use of services.EchoService in project helidon by oracle.
the class MetricsIT method startGrpcServer.
// ----- helper methods -------------------------------------------------
/**
* Start the gRPC Server listening on an ephemeral port.
*
* @throws Exception in case of an error
*/
private static void startGrpcServer() throws Exception {
// Add the EchoService and enable GrpcMetrics
GrpcRouting routing = GrpcRouting.builder().intercept(GrpcMetrics.timed()).register(new EchoService(), rules -> rules.intercept(GrpcMetrics.metered()).intercept("Echo", GrpcMetrics.counted())).build();
// Run the server on port 0 so that it picks a free ephemeral port
GrpcServerConfiguration serverConfig = GrpcServerConfiguration.builder().port(0).build();
grpcServer = GrpcServer.create(serverConfig, routing).start().toCompletableFuture().get(10, TimeUnit.SECONDS);
LOGGER.info("Started gRPC server at: localhost:" + grpcServer.port());
}
use of services.EchoService in project helidon by oracle.
the class SecurityFromConfigIT method startServer.
@BeforeAll
public static void startServer() throws Exception {
LogConfig.configureRuntime();
// load the config containing the gRPC service security settings
Config config = Config.builder().sources(ConfigSources.classpath("secure-services.conf")).build();
// Create the gRPC routing configuring the GrpcSecurity interceptor from config
GrpcRouting routing = GrpcRouting.builder().intercept(GrpcSecurity.create(config.get("security"))).register(new EchoService()).register(new StringService()).build();
// Run the server on port 0 so that it picks a free ephemeral port
GrpcServerConfiguration serverConfig = GrpcServerConfiguration.builder().port(0).build();
grpcServer = GrpcServer.create(serverConfig, routing).start().toCompletableFuture().get(10, TimeUnit.SECONDS);
Channel channel = InProcessChannelBuilder.forName(grpcServer.configuration().name()).build();
adminEchoStub = EchoServiceGrpc.newBlockingStub(channel).withCallCredentials(adminCreds);
userEchoStub = EchoServiceGrpc.newBlockingStub(channel).withCallCredentials(userCreds);
adminStringStub = StringServiceGrpc.newBlockingStub(channel).withCallCredentials(adminCreds);
userStringStub = StringServiceGrpc.newBlockingStub(channel).withCallCredentials(userCreds);
noCredsEchoStub = StringServiceGrpc.newBlockingStub(channel);
}
use of services.EchoService in project helidon by oracle.
the class ServiceAndMethodLevelSecurityIT method startServer.
@BeforeAll
public static void startServer() throws Exception {
LogConfig.configureRuntime();
Config config = Config.create();
Security security = Security.builder().addProvider(HttpBasicAuthProvider.create(config.get("http-basic-auth"))).build();
ServiceDescriptor echoService = ServiceDescriptor.builder(new EchoService()).intercept(GrpcSecurity.rolesAllowed("admin")).build();
ServiceDescriptor stringService = ServiceDescriptor.builder(new StringService()).intercept("Upper", GrpcSecurity.rolesAllowed("admin")).intercept("Split", GrpcSecurity.rolesAllowed("admin")).build();
// Add the EchoService
GrpcRouting routing = GrpcRouting.builder().intercept(GrpcSecurity.create(security).securityDefaults(GrpcSecurity.authenticate())).register(echoService).register(stringService).build();
// Run the server on port 0 so that it picks a free ephemeral port
GrpcServerConfiguration serverConfig = GrpcServerConfiguration.builder().port(0).build();
grpcServer = GrpcServer.create(serverConfig, routing).start().toCompletableFuture().get(10, TimeUnit.SECONDS);
Channel channel = InProcessChannelBuilder.forName(grpcServer.configuration().name()).build();
adminEchoStub = EchoServiceGrpc.newBlockingStub(channel).withCallCredentials(adminCreds);
userEchoStub = EchoServiceGrpc.newBlockingStub(channel).withCallCredentials(userCreds);
adminStringStub = StringServiceGrpc.newBlockingStub(channel).withCallCredentials(adminCreds);
userStringStub = StringServiceGrpc.newBlockingStub(channel).withCallCredentials(userCreds);
noCredsEchoStub = StringServiceGrpc.newBlockingStub(channel);
}
use of services.EchoService 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;
}
use of services.EchoService in project helidon by oracle.
the class TracingIT method startGrpcServer.
// ----- helper methods -------------------------------------------------
/**
* Start the gRPC Server listening on an ephemeral port.
*
* @throws Exception in case of an error
*/
private static void startGrpcServer() throws Exception {
// Add the EchoService
GrpcRouting routing = GrpcRouting.builder().register(new EchoService()).intercept(interceptor).build();
// Enable tracing
Tracer tracer = TracerBuilder.create("Server").collectorUri(URI.create(zipkin.httpUrl() + "/api/v2/spans")).build();
GrpcTracingConfig tracingConfig = GrpcTracingConfig.builder().withStreaming().withVerbosity().withTracedAttributes(ServerRequestAttribute.CALL_ATTRIBUTES, ServerRequestAttribute.HEADERS, ServerRequestAttribute.METHOD_NAME).build();
// Run the server on port 0 so that it picks a free ephemeral port
GrpcServerConfiguration serverConfig = GrpcServerConfiguration.builder().port(0).tracer(tracer).tracingConfig(tracingConfig).build();
grpcServer = GrpcServer.create(serverConfig, routing).start().toCompletableFuture().get(10, TimeUnit.SECONDS);
LOGGER.info("Started gRPC server at: localhost:" + grpcServer.port());
}
Aggregations