Search in sources :

Example 1 with StringService

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);
}
Also used : GrpcServerConfiguration(io.helidon.grpc.server.GrpcServerConfiguration) Config(io.helidon.config.Config) LogConfig(io.helidon.common.LogConfig) EchoService(services.EchoService) Channel(io.grpc.Channel) StringService(services.StringService) GrpcRouting(io.helidon.grpc.server.GrpcRouting) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 2 with StringService

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);
}
Also used : GrpcServerConfiguration(io.helidon.grpc.server.GrpcServerConfiguration) ServiceDescriptor(io.helidon.grpc.server.ServiceDescriptor) LogConfig(io.helidon.common.LogConfig) Config(io.helidon.config.Config) EchoService(services.EchoService) Channel(io.grpc.Channel) StringService(services.StringService) Security(io.helidon.security.Security) GrpcRouting(io.helidon.grpc.server.GrpcRouting) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 3 with StringService

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)));
}
Also used : JsonNumber(jakarta.json.JsonNumber) JsonObject(jakarta.json.JsonObject) StringService(services.StringService) Test(org.junit.jupiter.api.Test)

Example 4 with StringService

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();
}
Also used : GrpcServerConfiguration(io.helidon.grpc.server.GrpcServerConfiguration) TreeMapService(services.TreeMapService) StringService(services.StringService) GrpcRouting(io.helidon.grpc.server.GrpcRouting) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 5 with StringService

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);
}
Also used : GrpcServerConfiguration(io.helidon.grpc.server.GrpcServerConfiguration) TreeMapService(services.TreeMapService) Channel(io.grpc.Channel) StringService(services.StringService) GrpcRouting(io.helidon.grpc.server.GrpcRouting) BeforeAll(org.junit.jupiter.api.BeforeAll)

Aggregations

StringService (services.StringService)7 GrpcRouting (io.helidon.grpc.server.GrpcRouting)4 GrpcServerConfiguration (io.helidon.grpc.server.GrpcServerConfiguration)4 BeforeAll (org.junit.jupiter.api.BeforeAll)4 Channel (io.grpc.Channel)3 JsonObject (jakarta.json.JsonObject)3 Test (org.junit.jupiter.api.Test)3 LogConfig (io.helidon.common.LogConfig)2 Config (io.helidon.config.Config)2 EchoService (services.EchoService)2 TreeMapService (services.TreeMapService)2 StringMessage (io.helidon.grpc.examples.common.Strings.StringMessage)1 ServiceDescriptor (io.helidon.grpc.server.ServiceDescriptor)1 Security (io.helidon.security.Security)1 JsonNumber (jakarta.json.JsonNumber)1