use of services.StringService 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.StringService 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.StringService in project helidon by oracle.
the class MetricsTest method shouldHaveMeterMetric.
/**
* Verify that the StringService lower method has the meter metric.
*/
@Test
public void shouldHaveMeterMetric() {
JsonObject json = getMetrics();
JsonObject meter = json.getJsonObject(StringService.class.getName() + ".lower");
assertThat(meter, is(notNullValue()));
int count = meter.getInt("count");
JsonNumber meanRate = meter.getJsonNumber("meanRate");
assertThat(count, is(0));
assertThat(meanRate, is(notNullValue()));
assertThat(meanRate.doubleValue(), is(0.0));
stringStub.lower(StringMessage.newBuilder().setText("FOO").build());
json = getMetrics();
meter = json.getJsonObject(StringService.class.getName() + ".lower");
assertThat(meter, is(notNullValue()));
count = meter.getInt("count");
meanRate = meter.getJsonNumber("meanRate");
assertThat(count, is(1));
assertThat(meanRate, is(notNullValue()));
assertThat(meanRate.doubleValue(), is(not(0.0)));
}
use of services.StringService in project helidon by oracle.
the class PojoServiceClientIT method startServer.
@BeforeAll
public static void startServer() throws Exception {
LogConfig.configureRuntime();
GrpcRouting routing = GrpcRouting.builder().register(new TreeMapService()).register(new StringService()).build();
GrpcServerConfiguration serverConfig = GrpcServerConfiguration.builder().port(0).build();
grpcServer = GrpcServer.create(serverConfig, routing).start().toCompletableFuture().get(10, TimeUnit.SECONDS);
channel = ManagedChannelBuilder.forAddress("localhost", grpcServer.port()).usePlaintext().build();
}
use of services.StringService in project helidon by oracle.
the class ProtoGrpcServiceClientIT method startServer.
@BeforeAll
public static void startServer() throws Exception {
LogConfig.configureRuntime();
GrpcRouting routing = GrpcRouting.builder().intercept(headerCheckingInterceptor).register(new TreeMapService()).register(new StringService()).build();
GrpcServerConfiguration serverConfig = GrpcServerConfiguration.builder().port(0).build();
grpcServer = GrpcServer.create(serverConfig, routing).start().toCompletableFuture().get(10, TimeUnit.SECONDS);
ClientServiceDescriptor descriptor = ClientServiceDescriptor.builder(StringServiceGrpc.getServiceDescriptor()).intercept(mediumPriorityInterceptor).intercept("Upper", highPriorityInterceptor).intercept("Lower", lowPriorityInterceptor).callCredentials(serviceCred).callCredentials("Lower", lowerMethodCred).callCredentials("Join", joinMethodCred).build();
Channel channel = ManagedChannelBuilder.forAddress("localhost", grpcServer.port()).usePlaintext().build();
grpcClient = GrpcServiceClient.create(channel, descriptor);
}
Aggregations