【发布时间】:2016-05-12 12:52:14
【问题描述】:
在我使用 grpc 和 java 的项目中,我使用 OpenSSL 在客户端和服务器之间建立安全连接。
我能够成功启动 grpc 服务器。
文档here 提到安全通道的客户端代码是这样的
ManagedChannel channel = ManagedChannelBuilder.forAddress("myservice.example.com", 443)
.build();
GreeterGrpc.GreeterStub stub = GreeterGrpc.newStub(channel);
我在客户端使用如下代码,但抛出以下异常。
mChannel = ManagedChannelBuilder.forAddress(GrpcConstants.LOCAL_GRPC_CLIENT_IP, GrpcConstants.LOCAL_GRPC_CLIENT_PORT).build();
mEmployerServicesBlockingStub = EmployerServicesGrpc.newBlockingStub(mChannel);
mInviteContactsBlockingStub = InviteContactsGrpc.newBlockingStub(mChannel);
例外:
Network channel closed
at io.grpc.Status.asRuntimeException(Status.java:431)
at io.grpc.stub.ClientCalls.getUnchecked(ClientCalls.java:157)
at io.grpc.stub.ClientCalls.blockingUnaryCall(ClientCalls.java:106)
我也尝试了以下代码:
mChannel = NettyChannelBuilder.forAddress(GrpcConstants.LOCAL_GRPC_CLIENT_IP, GrpcConstants.LOCAL_GRPC_CLIENT_PORT).sslContext(GrpcSslContexts.forClient().trustManager(file).build()).build();
mEmployerServicesBlockingStub = EmployerServicesGrpc.newBlockingStub(mChannel);
mInviteContactsBlockingStub = InviteContactsGrpc.newBlockingStub(mChannel);
这也给出了与上述相同的异常。我只是在这里给出了一个空文件引用。
请告诉我应该使用哪种方法获取 GoDaddy 证书。
如果是第一种方法,我错过了什么。
如果是第二种方法,我应该将哪个文件用于“roots.pem”。
已更新。
【问题讨论】: