use of io.helidon.grpc.server.test.Echo in project helidon by oracle.
the class SecuredOutboundEchoService method echo.
/**
* Make a web request passing this method's message parameter and send
* the web response back to the caller .
*
* @param request the echo request containing the message to echo
* @param observer the call response
*/
public void echo(Echo.EchoRequest request, StreamObserver<Echo.EchoResponse> observer) {
try {
SecurityContext securityContext = GrpcSecurity.SECURITY_CONTEXT.get();
String message = request.getMessage();
Response webResponse = client.target(url).path("/test").queryParam("message", message).request().property(ClientSecurity.PROPERTY_CONTEXT, securityContext).get();
if (webResponse.getStatus() == 200) {
String value = webResponse.readEntity(String.class);
Echo.EchoResponse echoResponse = Echo.EchoResponse.newBuilder().setMessage(value).build();
complete(observer, echoResponse);
} else if (webResponse.getStatus() == Response.Status.FORBIDDEN.getStatusCode() || webResponse.getStatus() == Response.Status.UNAUTHORIZED.getStatusCode()) {
observer.onError(Status.PERMISSION_DENIED.asException());
} else {
observer.onError(Status.UNKNOWN.withDescription("Received http response " + webResponse).asException());
}
} catch (Throwable thrown) {
observer.onError(Status.UNKNOWN.withCause(thrown).asException());
}
}
use of io.helidon.grpc.server.test.Echo in project helidon by oracle.
the class SslIT method shouldConnectWithClientCertsFor2WayUseConfig.
@Test
public void shouldConnectWithClientCertsFor2WayUseConfig() throws Exception {
Resource tlsCaCert = Resource.create(CA_CERT);
Resource tlsClientCert = Resource.create(CLIENT_CERT);
Resource tlsClientKey = Resource.create(CLIENT_KEY);
SslContext sslContext = clientSslContext(tlsCaCert, tlsClientCert, tlsClientKey);
Channel channel = NettyChannelBuilder.forAddress("localhost", grpcServer_2WaySSLConfig.port()).negotiationType(NegotiationType.TLS).sslContext(sslContext).build();
// call the gRPC Echo service
Echo.EchoResponse response = EchoServiceGrpc.newBlockingStub(channel).echo(Echo.EchoRequest.newBuilder().setMessage("foo").build());
assertThat(response.getMessage(), is("foo"));
((ManagedChannel) channel).shutdown().awaitTermination(5, TimeUnit.SECONDS);
}
Aggregations