use of io.helidon.grpc.core.GrpcTlsDescriptor in project helidon by oracle.
the class SslIT method startGrpcServer.
/**
* Start the gRPC Server listening on the specified nPort.
*
* @throws Exception in case of an error
*/
private static GrpcServer startGrpcServer(int nPort, boolean mutual, boolean useConfig) throws Exception {
Resource tlsCert = Resource.create(SERVER_CERT);
Resource tlsKey = Resource.create(SERVER_KEY);
Resource tlsCaCert = Resource.create(CA_CERT);
GrpcTlsDescriptor sslConfig;
String name = "grpc.server";
if (useConfig) {
name = name + 1;
Config config = Config.builder().sources(ConfigSources.classpath("config-ssl.conf")).build();
sslConfig = config.get("grpcserver.ssl").as(GrpcTlsDescriptor::create).get();
} else if (mutual) {
name = name + 2;
sslConfig = GrpcTlsDescriptor.builder().jdkSSL(false).tlsCert(tlsCert).tlsKey(tlsKey).tlsCaCert(tlsCaCert).build();
} else {
name = name + 3;
sslConfig = GrpcTlsDescriptor.builder().jdkSSL(false).tlsCert(tlsCert).tlsKey(tlsKey).build();
}
// Add the EchoService
GrpcRouting routing = GrpcRouting.builder().register(new EchoService()).build();
GrpcServerConfiguration serverConfig = GrpcServerConfiguration.builder().name(name).port(nPort).tlsConfig(sslConfig).build();
GrpcServer grpcServer;
try {
grpcServer = GrpcServer.create(serverConfig, routing).start().toCompletableFuture().get(10, TimeUnit.SECONDS);
} catch (Throwable t) {
throw new RuntimeException(t);
}
LOGGER.info("Started gRPC server at: localhost:" + grpcServer.port());
return grpcServer;
}
Aggregations