use of io.grpc.okhttp.OkHttpChannelBuilder in project grpc-java by grpc.
the class Utils method newOkhttpClientChannel.
private static OkHttpChannelBuilder newOkhttpClientChannel(SocketAddress address, boolean tls, boolean testca, @Nullable String authorityOverride) {
InetSocketAddress addr = (InetSocketAddress) address;
OkHttpChannelBuilder builder = OkHttpChannelBuilder.forAddress(addr.getHostName(), addr.getPort());
if (tls) {
builder.negotiationType(io.grpc.okhttp.NegotiationType.TLS);
SSLSocketFactory factory;
if (testca) {
builder.overrideAuthority(GrpcUtil.authorityFromHostAndPort(authorityOverride, addr.getPort()));
try {
factory = TestUtils.newSslSocketFactoryForCa(Platform.get().getProvider(), TestUtils.loadCert("ca.pem"));
} catch (Exception e) {
throw new RuntimeException(e);
}
} else {
factory = (SSLSocketFactory) SSLSocketFactory.getDefault();
}
builder.sslSocketFactory(factory);
} else {
builder.negotiationType(io.grpc.okhttp.NegotiationType.PLAINTEXT);
}
return builder;
}
use of io.grpc.okhttp.OkHttpChannelBuilder in project grpc-java by grpc.
the class TesterOkHttpChannelBuilder method build.
public static ManagedChannel build(String host, int port, @Nullable String serverHostOverride, boolean useTls, @Nullable InputStream testCa) {
ChannelCredentials credentials;
if (useTls) {
if (testCa == null) {
credentials = TlsChannelCredentials.create();
} else {
try {
credentials = TlsChannelCredentials.newBuilder().trustManager(testCa).build();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
} else {
credentials = InsecureChannelCredentials.create();
}
ManagedChannelBuilder<?> channelBuilder = Grpc.newChannelBuilderForAddress(host, port, credentials).maxInboundMessageSize(16 * 1024 * 1024);
if (!(channelBuilder instanceof OkHttpChannelBuilder)) {
throw new RuntimeException("Did not receive an OkHttpChannelBuilder");
}
if (serverHostOverride != null) {
// Force the hostname to match the cert the server uses.
channelBuilder.overrideAuthority(serverHostOverride);
}
return channelBuilder.build();
}
use of io.grpc.okhttp.OkHttpChannelBuilder in project grpc-java by grpc.
the class Http2OkHttpTest method createChannelBuilderPreCredentialsApi.
private OkHttpChannelBuilder createChannelBuilderPreCredentialsApi() {
int port = ((InetSocketAddress) getListenAddress()).getPort();
OkHttpChannelBuilder builder = OkHttpChannelBuilder.forAddress("localhost", port).maxInboundMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE).connectionSpec(new ConnectionSpec.Builder(ConnectionSpec.MODERN_TLS).build()).overrideAuthority(GrpcUtil.authorityFromHostAndPort(TestUtils.TEST_SERVER_HOST, port));
try {
builder.sslSocketFactory(TestUtils.newSslSocketFactoryForCa(Platform.get().getProvider(), TestUtils.loadCert("ca.pem")));
} catch (Exception e) {
throw new RuntimeException(e);
}
// Disable the default census stats interceptor, use testing interceptor instead.
InternalOkHttpChannelBuilder.setStatsEnabled(builder, false);
return builder.intercept(createCensusStatsClientInterceptor());
}
use of io.grpc.okhttp.OkHttpChannelBuilder in project grpc-java by grpc.
the class Http2OkHttpTest method createChannel.
@Override
protected ManagedChannel createChannel() {
OkHttpChannelBuilder builder = OkHttpChannelBuilder.forAddress("127.0.0.1", getPort()).maxInboundMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE).connectionSpec(new ConnectionSpec.Builder(OkHttpChannelBuilder.DEFAULT_CONNECTION_SPEC).cipherSuites(TestUtils.preferredTestCiphers().toArray(new String[0])).tlsVersions(ConnectionSpec.MODERN_TLS.tlsVersions().toArray(new TlsVersion[0])).build()).overrideAuthority(GrpcUtil.authorityFromHostAndPort(TestUtils.TEST_SERVER_HOST, getPort()));
io.grpc.internal.TestingAccessor.setStatsContextFactory(builder, getClientStatsFactory());
try {
builder.sslSocketFactory(TestUtils.newSslSocketFactoryForCa(Platform.get().getProvider(), TestUtils.loadCert("ca.pem")));
} catch (Exception e) {
throw new RuntimeException(e);
}
return builder.build();
}
use of io.grpc.okhttp.OkHttpChannelBuilder in project grpc-java by grpc.
the class Http2OkHttpTest method createChannelBuilder.
@Override
protected OkHttpChannelBuilder createChannelBuilder() {
int port = ((InetSocketAddress) getListenAddress()).getPort();
ChannelCredentials channelCreds;
try {
channelCreds = TlsChannelCredentials.newBuilder().trustManager(TestUtils.loadCert("ca.pem")).build();
} catch (IOException ex) {
throw new RuntimeException(ex);
}
OkHttpChannelBuilder builder = OkHttpChannelBuilder.forAddress("localhost", port, channelCreds).maxInboundMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE).overrideAuthority(GrpcUtil.authorityFromHostAndPort(TestUtils.TEST_SERVER_HOST, port));
// Disable the default census stats interceptor, use testing interceptor instead.
InternalOkHttpChannelBuilder.setStatsEnabled(builder, false);
return builder.intercept(createCensusStatsClientInterceptor());
}
Aggregations