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() + "'");
}
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)));
}
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);
}
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)));
}
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);
}
Aggregations