Search in sources :

Example 1 with ClientServiceDescriptor

use of io.helidon.grpc.client.ClientServiceDescriptor in project helidon by oracle.

the class SecureStringClient method main.

/**
 * Program entry point.
 *
 * @param args  the program arguments - {@code arg[0]} is the user name
 *              and {@code arg[1] is the password}
 */
public static void main(String[] args) {
    Channel channel = ManagedChannelBuilder.forAddress("localhost", 1408).usePlaintext().build();
    // Obtain the user name and password from the program arguments
    String user = args.length >= 2 ? args[0] : "Ted";
    String password = args.length >= 2 ? args[1] : "secret";
    Config config = Config.create();
    // configure Helidon security and add the basic auth provider
    Security security = Security.builder().addProvider(HttpBasicAuthProvider.create(config.get("http-basic-auth"))).build();
    // create the gRPC client security call credentials
    // setting the properties used by the basic auth provider for user name and password
    GrpcClientSecurity clientSecurity = GrpcClientSecurity.builder(security.createContext("test.client")).property(HttpBasicAuthProvider.EP_PROPERTY_OUTBOUND_USER, user).property(HttpBasicAuthProvider.EP_PROPERTY_OUTBOUND_PASSWORD, password).build();
    // Create the client service descriptor and add the call credentials
    ClientServiceDescriptor descriptor = ClientServiceDescriptor.builder(StringServiceGrpc.getServiceDescriptor()).callCredentials(clientSecurity).build();
    // create the client for the service
    GrpcServiceClient client = GrpcServiceClient.create(channel, descriptor);
    Strings.StringMessage request = Strings.StringMessage.newBuilder().setText("ABCDE").build();
    Strings.StringMessage response = client.blockingUnary("Lower", request);
    System.out.println("Response from Lower method call is '" + response.getText() + "'");
}
Also used : GrpcClientSecurity(io.helidon.security.integration.grpc.GrpcClientSecurity) Config(io.helidon.config.Config) Channel(io.grpc.Channel) ClientServiceDescriptor(io.helidon.grpc.client.ClientServiceDescriptor) GrpcServiceClient(io.helidon.grpc.client.GrpcServiceClient) Security(io.helidon.security.Security) GrpcClientSecurity(io.helidon.security.integration.grpc.GrpcClientSecurity) Strings(io.helidon.grpc.examples.common.Strings)

Example 2 with ClientServiceDescriptor

use of io.helidon.grpc.client.ClientServiceDescriptor in project helidon by oracle.

the class GrpcClientBuilderTest method assertServiceOne.

public void assertServiceOne(GrpcClientBuilder builder) {
    ClientServiceDescriptor.Builder descriptorBuilder = builder.build();
    ClientServiceDescriptor descriptor = descriptorBuilder.build();
    assertThat(descriptor.name(), is("ServiceOne/foo"));
    assertThat(descriptor.methods().size(), is(4));
    ClientMethodDescriptor ClientMethodDescriptor;
    io.grpc.MethodDescriptor grpcDescriptor;
    ClientMethodDescriptor = descriptor.method("unary");
    assertThat(ClientMethodDescriptor, is(notNullValue()));
    assertThat(ClientMethodDescriptor.name(), is("unary"));
    grpcDescriptor = ClientMethodDescriptor.descriptor();
    assertThat(grpcDescriptor, is(notNullValue()));
    assertThat(grpcDescriptor.getFullMethodName(), is("ServiceOne/foo/unary"));
    assertThat(grpcDescriptor.getType(), is(io.grpc.MethodDescriptor.MethodType.UNARY));
    assertThat(grpcDescriptor.getRequestMarshaller(), is(instanceOf(JavaMarshaller.class)));
    assertThat(grpcDescriptor.getResponseMarshaller(), is(instanceOf(JavaMarshaller.class)));
    ClientMethodDescriptor = descriptor.method("clientStreaming");
    assertThat(ClientMethodDescriptor, is(notNullValue()));
    assertThat(ClientMethodDescriptor.name(), is("clientStreaming"));
    grpcDescriptor = ClientMethodDescriptor.descriptor();
    assertThat(grpcDescriptor, is(notNullValue()));
    assertThat(grpcDescriptor.getFullMethodName(), is("ServiceOne/foo/clientStreaming"));
    assertThat(grpcDescriptor.getType(), is(io.grpc.MethodDescriptor.MethodType.CLIENT_STREAMING));
    assertThat(grpcDescriptor.getRequestMarshaller(), is(instanceOf(JavaMarshaller.class)));
    assertThat(grpcDescriptor.getResponseMarshaller(), is(instanceOf(JavaMarshaller.class)));
    ClientMethodDescriptor = descriptor.method("serverStreaming");
    assertThat(ClientMethodDescriptor, is(notNullValue()));
    assertThat(ClientMethodDescriptor.name(), is("serverStreaming"));
    grpcDescriptor = ClientMethodDescriptor.descriptor();
    assertThat(grpcDescriptor, is(notNullValue()));
    assertThat(grpcDescriptor.getFullMethodName(), is("ServiceOne/foo/serverStreaming"));
    assertThat(grpcDescriptor.getType(), is(io.grpc.MethodDescriptor.MethodType.SERVER_STREAMING));
    assertThat(grpcDescriptor.getRequestMarshaller(), is(instanceOf(JavaMarshaller.class)));
    assertThat(grpcDescriptor.getResponseMarshaller(), is(instanceOf(JavaMarshaller.class)));
    ClientMethodDescriptor = descriptor.method("bidiStreaming");
    assertThat(ClientMethodDescriptor, is(notNullValue()));
    assertThat(ClientMethodDescriptor.name(), is("bidiStreaming"));
    grpcDescriptor = ClientMethodDescriptor.descriptor();
    assertThat(grpcDescriptor, is(notNullValue()));
    assertThat(grpcDescriptor.getFullMethodName(), is("ServiceOne/foo/bidiStreaming"));
    assertThat(grpcDescriptor.getType(), is(io.grpc.MethodDescriptor.MethodType.BIDI_STREAMING));
    assertThat(grpcDescriptor.getRequestMarshaller(), is(instanceOf(JavaMarshaller.class)));
    assertThat(grpcDescriptor.getResponseMarshaller(), is(instanceOf(JavaMarshaller.class)));
}
Also used : ClientServiceDescriptor(io.helidon.grpc.client.ClientServiceDescriptor) ClientMethodDescriptor(io.helidon.grpc.client.ClientMethodDescriptor)

Example 3 with ClientServiceDescriptor

use of io.helidon.grpc.client.ClientServiceDescriptor in project helidon by oracle.

the class SecureGreetClient method main.

/**
 * Main entry point.
 *
 * @param args  the program arguments - {@code arg[0]} is the user name
 *              and {@code arg[1] is the password}
 */
public static void main(String[] args) {
    Channel channel = ManagedChannelBuilder.forAddress("localhost", 1408).usePlaintext().build();
    // Obtain the user name and password from the program arguments
    String user = args.length >= 2 ? args[0] : "Ted";
    String password = args.length >= 2 ? args[1] : "secret";
    Config config = Config.create();
    // configure Helidon security and add the basic auth provider
    Security security = Security.builder().addProvider(HttpBasicAuthProvider.create(config.get("http-basic-auth"))).build();
    // create the gRPC client security call credentials
    // setting the properties used by the basic auth provider for user name and password
    GrpcClientSecurity clientSecurity = GrpcClientSecurity.builder(security.createContext("test.client")).property(HttpBasicAuthProvider.EP_PROPERTY_OUTBOUND_USER, user).property(HttpBasicAuthProvider.EP_PROPERTY_OUTBOUND_PASSWORD, password).build();
    // Create the client service descriptor and add the call credentials
    ClientServiceDescriptor descriptor = ClientServiceDescriptor.builder(GreetServiceGrpc.getServiceDescriptor()).callCredentials(clientSecurity).build();
    // create the client for the service
    GrpcServiceClient client = GrpcServiceClient.create(channel, descriptor);
    greet(client);
    setGreeting(client);
    greet(client);
}
Also used : GrpcClientSecurity(io.helidon.security.integration.grpc.GrpcClientSecurity) Config(io.helidon.config.Config) Channel(io.grpc.Channel) ClientServiceDescriptor(io.helidon.grpc.client.ClientServiceDescriptor) GrpcServiceClient(io.helidon.grpc.client.GrpcServiceClient) Security(io.helidon.security.Security) GrpcClientSecurity(io.helidon.security.integration.grpc.GrpcClientSecurity)

Example 4 with ClientServiceDescriptor

use of io.helidon.grpc.client.ClientServiceDescriptor in project helidon by oracle.

the class GrpcClientBuilderTest method shouldCreateServiceWithMethodNamesFromAnnotation.

@Test
public void shouldCreateServiceWithMethodNamesFromAnnotation() {
    ServiceTwo service = new ServiceTwo();
    GrpcClientBuilder builder = GrpcClientBuilder.create(service);
    ClientServiceDescriptor.Builder descriptorBuilder = builder.build();
    ClientServiceDescriptor descriptor = descriptorBuilder.build();
    assertThat(descriptor.name(), is("ServiceTwo"));
    assertThat(descriptor.methods().size(), is(4));
    ClientMethodDescriptor ClientMethodDescriptor;
    io.grpc.MethodDescriptor grpcDescriptor;
    ClientMethodDescriptor = descriptor.method("One");
    assertThat(ClientMethodDescriptor, is(notNullValue()));
    assertThat(ClientMethodDescriptor.name(), is("One"));
    grpcDescriptor = ClientMethodDescriptor.descriptor();
    assertThat(grpcDescriptor, is(notNullValue()));
    assertThat(grpcDescriptor.getFullMethodName(), is("ServiceTwo/One"));
    assertThat(grpcDescriptor.getType(), is(io.grpc.MethodDescriptor.MethodType.UNARY));
    assertThat(grpcDescriptor.getRequestMarshaller(), is(instanceOf(JavaMarshaller.class)));
    assertThat(grpcDescriptor.getResponseMarshaller(), is(instanceOf(JavaMarshaller.class)));
    ClientMethodDescriptor = descriptor.method("Two");
    assertThat(ClientMethodDescriptor, is(notNullValue()));
    assertThat(ClientMethodDescriptor.name(), is("Two"));
    grpcDescriptor = ClientMethodDescriptor.descriptor();
    assertThat(grpcDescriptor, is(notNullValue()));
    assertThat(grpcDescriptor.getFullMethodName(), is("ServiceTwo/Two"));
    assertThat(grpcDescriptor.getType(), is(io.grpc.MethodDescriptor.MethodType.CLIENT_STREAMING));
    assertThat(grpcDescriptor.getRequestMarshaller(), is(instanceOf(JavaMarshaller.class)));
    assertThat(grpcDescriptor.getResponseMarshaller(), is(instanceOf(JavaMarshaller.class)));
    ClientMethodDescriptor = descriptor.method("Three");
    assertThat(ClientMethodDescriptor, is(notNullValue()));
    assertThat(ClientMethodDescriptor.name(), is("Three"));
    grpcDescriptor = ClientMethodDescriptor.descriptor();
    assertThat(grpcDescriptor, is(notNullValue()));
    assertThat(grpcDescriptor.getFullMethodName(), is("ServiceTwo/Three"));
    assertThat(grpcDescriptor.getType(), is(io.grpc.MethodDescriptor.MethodType.SERVER_STREAMING));
    assertThat(grpcDescriptor.getRequestMarshaller(), is(instanceOf(JavaMarshaller.class)));
    assertThat(grpcDescriptor.getResponseMarshaller(), is(instanceOf(JavaMarshaller.class)));
    ClientMethodDescriptor = descriptor.method("Four");
    assertThat(ClientMethodDescriptor, is(notNullValue()));
    assertThat(ClientMethodDescriptor.name(), is("Four"));
    grpcDescriptor = ClientMethodDescriptor.descriptor();
    assertThat(grpcDescriptor, is(notNullValue()));
    assertThat(grpcDescriptor.getFullMethodName(), is("ServiceTwo/Four"));
    assertThat(grpcDescriptor.getType(), is(io.grpc.MethodDescriptor.MethodType.BIDI_STREAMING));
    assertThat(grpcDescriptor.getRequestMarshaller(), is(instanceOf(JavaMarshaller.class)));
    assertThat(grpcDescriptor.getResponseMarshaller(), is(instanceOf(JavaMarshaller.class)));
}
Also used : ClientServiceDescriptor(io.helidon.grpc.client.ClientServiceDescriptor) ClientMethodDescriptor(io.helidon.grpc.client.ClientMethodDescriptor) Test(org.junit.jupiter.api.Test)

Example 5 with ClientServiceDescriptor

use of io.helidon.grpc.client.ClientServiceDescriptor in project helidon by oracle.

the class StringClient method main.

/**
 * Program entry point.
 *
 * @param args  the program arguments
 *
 * @throws Exception if an error occurs
 */
public static void main(String[] args) throws Exception {
    ClientServiceDescriptor descriptor = ClientServiceDescriptor.builder(StringServiceGrpc.getServiceDescriptor()).build();
    Channel channel = ManagedChannelBuilder.forAddress("localhost", 1408).usePlaintext().build();
    GrpcServiceClient client = GrpcServiceClient.create(channel, descriptor);
    unary(client);
    asyncUnary(client);
    blockingUnary(client);
    clientStreaming(client);
    clientStreamingOfIterable(client);
    serverStreamingBlocking(client);
    serverStreaming(client);
    bidirectional(client);
}
Also used : ClientServiceDescriptor(io.helidon.grpc.client.ClientServiceDescriptor) Channel(io.grpc.Channel) GrpcServiceClient(io.helidon.grpc.client.GrpcServiceClient)

Aggregations

ClientServiceDescriptor (io.helidon.grpc.client.ClientServiceDescriptor)7 Channel (io.grpc.Channel)5 GrpcServiceClient (io.helidon.grpc.client.GrpcServiceClient)5 Config (io.helidon.config.Config)2 ClientMethodDescriptor (io.helidon.grpc.client.ClientMethodDescriptor)2 Security (io.helidon.security.Security)2 GrpcClientSecurity (io.helidon.security.integration.grpc.GrpcClientSecurity)2 StatusRuntimeException (io.grpc.StatusRuntimeException)1 HealthCheckResponse (io.grpc.health.v1.HealthCheckResponse)1 ClientTracingInterceptor (io.helidon.grpc.client.ClientTracingInterceptor)1 GreetRequest (io.helidon.grpc.examples.common.Greet.GreetRequest)1 GreetResponse (io.helidon.grpc.examples.common.Greet.GreetResponse)1 SetGreetingRequest (io.helidon.grpc.examples.common.Greet.SetGreetingRequest)1 SetGreetingResponse (io.helidon.grpc.examples.common.Greet.SetGreetingResponse)1 Strings (io.helidon.grpc.examples.common.Strings)1 Tracer (io.opentracing.Tracer)1 Test (org.junit.jupiter.api.Test)1