Search in sources :

Example 6 with GrpcTlsDescriptor

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;
}
Also used : StatusRuntimeException(io.grpc.StatusRuntimeException) LogConfig(io.helidon.common.LogConfig) Config(io.helidon.config.Config) EchoService(services.EchoService) Resource(io.helidon.common.configurable.Resource) GrpcTlsDescriptor(io.helidon.grpc.core.GrpcTlsDescriptor)

Aggregations

GrpcTlsDescriptor (io.helidon.grpc.core.GrpcTlsDescriptor)6 Resource (io.helidon.common.configurable.Resource)5 Test (org.junit.jupiter.api.Test)3 HandlerRegistry (io.grpc.HandlerRegistry)1 StatusRuntimeException (io.grpc.StatusRuntimeException)1 NettyServerBuilder (io.grpc.netty.NettyServerBuilder)1 MutableHandlerRegistry (io.grpc.util.MutableHandlerRegistry)1 LogConfig (io.helidon.common.LogConfig)1 Config (io.helidon.config.Config)1 GrpcRouting (io.helidon.grpc.server.GrpcRouting)1 GrpcServerConfiguration (io.helidon.grpc.server.GrpcServerConfiguration)1 JdkSslContext (io.netty.handler.ssl.JdkSslContext)1 SslContext (io.netty.handler.ssl.SslContext)1 SSLContext (javax.net.ssl.SSLContext)1 EchoService (services.EchoService)1 TreeMapService (services.TreeMapService)1