3 * Copyright 2018 gRPC authors.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
19 #include <grpcpp/grpcpp.h>
22 #include "src/core/lib/security/security_connector/ssl_utils.h"
23 #include "test/cpp/interop/interop_client.h"
25 extern "C" JNIEXPORT void JNICALL
26 Java_io_grpc_interop_cpp_InteropActivity_configureSslRoots(JNIEnv* env,
29 const char* path = env->GetStringUTFChars(path_raw, (jboolean*)0);
31 GPR_GLOBAL_CONFIG_SET(grpc_default_ssl_roots_file_path, path);
34 std::shared_ptr<grpc::testing::InteropClient> GetClient(const char* host,
37 const int host_port_buf_size = 1024;
38 char host_port[host_port_buf_size];
39 snprintf(host_port, host_port_buf_size, "%s:%d", host, port);
41 std::shared_ptr<grpc::ChannelCredentials> credentials;
43 credentials = grpc::SslCredentials(grpc::SslCredentialsOptions());
45 credentials = grpc::InsecureChannelCredentials();
48 grpc::testing::ChannelCreationFunc channel_creation_func =
49 std::bind(grpc::CreateChannel, host_port, credentials);
50 return std::shared_ptr<grpc::testing::InteropClient>(
51 new grpc::testing::InteropClient(channel_creation_func, true, false));
54 extern "C" JNIEXPORT jboolean JNICALL
55 Java_io_grpc_interop_cpp_InteropActivity_doEmpty(JNIEnv* env, jobject obj_this,
58 jboolean use_tls_raw) {
59 const char* host = env->GetStringUTFChars(host_raw, (jboolean*)0);
60 int port = static_cast<int>(port_raw);
61 bool use_tls = static_cast<bool>(use_tls_raw);
63 return GetClient(host, port, use_tls)->DoEmpty();
66 extern "C" JNIEXPORT jboolean JNICALL
67 Java_io_grpc_interop_cpp_InteropActivity_doLargeUnary(JNIEnv* env,
71 jboolean use_tls_raw) {
72 const char* host = env->GetStringUTFChars(host_raw, (jboolean*)0);
73 int port = static_cast<int>(port_raw);
74 bool use_tls = static_cast<bool>(use_tls_raw);
76 return GetClient(host, port, use_tls)->DoLargeUnary();
79 extern "C" JNIEXPORT jboolean JNICALL
80 Java_io_grpc_interop_cpp_InteropActivity_doEmptyStream(JNIEnv* env,
84 jboolean use_tls_raw) {
85 const char* host = env->GetStringUTFChars(host_raw, (jboolean*)0);
86 int port = static_cast<int>(port_raw);
87 bool use_tls = static_cast<bool>(use_tls_raw);
89 return GetClient(host, port, use_tls)->DoEmptyStream();
92 extern "C" JNIEXPORT jboolean JNICALL
93 Java_io_grpc_interop_cpp_InteropActivity_doRequestStreaming(
94 JNIEnv* env, jobject obj_this, jstring host_raw, jint port_raw,
95 jboolean use_tls_raw) {
96 const char* host = env->GetStringUTFChars(host_raw, (jboolean*)0);
97 int port = static_cast<int>(port_raw);
98 bool use_tls = static_cast<bool>(use_tls_raw);
100 return GetClient(host, port, use_tls)->DoRequestStreaming();
103 extern "C" JNIEXPORT jboolean JNICALL
104 Java_io_grpc_interop_cpp_InteropActivity_doResponseStreaming(
105 JNIEnv* env, jobject obj_this, jstring host_raw, jint port_raw,
106 jboolean use_tls_raw) {
107 const char* host = env->GetStringUTFChars(host_raw, (jboolean*)0);
108 int port = static_cast<int>(port_raw);
109 bool use_tls = static_cast<bool>(use_tls_raw);
111 return GetClient(host, port, use_tls)->DoResponseStreaming();
114 extern "C" JNIEXPORT jboolean JNICALL
115 Java_io_grpc_interop_cpp_InteropActivity_doPingPong(JNIEnv* env,
119 jboolean use_tls_raw) {
120 const char* host = env->GetStringUTFChars(host_raw, (jboolean*)0);
121 int port = static_cast<int>(port_raw);
122 bool use_tls = static_cast<bool>(use_tls_raw);
124 return GetClient(host, port, use_tls)->DoPingPong();