|
3 | 3 | import java.io.IOException; |
4 | 4 | import java.util.concurrent.CompletableFuture; |
5 | 5 |
|
| 6 | +import javax.net.ssl.SSLException; |
| 7 | + |
6 | 8 | import com.google.common.util.concurrent.FutureCallback; |
7 | 9 | import com.google.common.util.concurrent.Futures; |
8 | 10 | import com.google.common.util.concurrent.ListenableFuture; |
9 | 11 |
|
10 | 12 | import io.grpc.ManagedChannel; |
11 | | -import io.grpc.ManagedChannelBuilder; |
| 13 | +import io.grpc.netty.GrpcSslContexts; |
| 14 | +import io.grpc.netty.NettyChannelBuilder; |
12 | 15 | import io.grpc.stub.MetadataUtils; |
| 16 | +import io.netty.handler.ssl.SslContext; |
13 | 17 | import io.weaviate.client6.v1.internal.grpc.protocol.WeaviateGrpc; |
14 | 18 | import io.weaviate.client6.v1.internal.grpc.protocol.WeaviateGrpc.WeaviateBlockingStub; |
15 | 19 | import io.weaviate.client6.v1.internal.grpc.protocol.WeaviateGrpc.WeaviateFutureStub; |
@@ -80,15 +84,29 @@ public void onFailure(Throwable t) { |
80 | 84 | } |
81 | 85 |
|
82 | 86 | private static ManagedChannel buildChannel(GrpcChannelOptions transportOptions) { |
83 | | - var channel = ManagedChannelBuilder.forAddress(transportOptions.host(), transportOptions.port()); |
| 87 | + var channel = NettyChannelBuilder.forAddress(transportOptions.host(), transportOptions.port()); |
84 | 88 |
|
85 | 89 | if (transportOptions.isSecure()) { |
86 | 90 | channel.useTransportSecurity(); |
87 | 91 | } else { |
88 | 92 | channel.usePlaintext(); |
89 | 93 | } |
90 | 94 |
|
| 95 | + if (transportOptions.trustManagerFactory() != null) { |
| 96 | + SslContext sslCtx; |
| 97 | + try { |
| 98 | + sslCtx = GrpcSslContexts.forClient() |
| 99 | + .trustManager(transportOptions.trustManagerFactory()) |
| 100 | + .build(); |
| 101 | + } catch (SSLException e) { |
| 102 | + // todo: rethrow as WeaviateConnectionException |
| 103 | + throw new RuntimeException("create grpc transport", e); |
| 104 | + } |
| 105 | + channel.sslContext(sslCtx); |
| 106 | + } |
| 107 | + |
91 | 108 | channel.intercept(MetadataUtils.newAttachHeadersInterceptor(transportOptions.headers())); |
| 109 | + |
92 | 110 | return channel.build(); |
93 | 111 | } |
94 | 112 |
|
|
0 commit comments