in plugin-tester-java/src/main/java/example/myapp/CombinedServer.java [45:81]
public static void main(String[] args) {
// important to enable HTTP/2 in ActorSystem's config
Config conf = ConfigFactory.parseString("pekko.http.server.preview.enable-http2 = on")
.withFallback(ConfigFactory.defaultApplication());
ActorSystem sys = ActorSystem.create("HelloWorld", conf);
Materializer mat = SystemMaterializer.get(sys).materializer();
//#concatOrNotFound
Function<HttpRequest, CompletionStage<HttpResponse>> greeterService =
GreeterServiceHandlerFactory.create(new GreeterServiceImpl(mat), sys);
Function<HttpRequest, CompletionStage<HttpResponse>> echoService =
EchoServiceHandlerFactory.create(new EchoServiceImpl(), sys);
@SuppressWarnings("unchecked")
Function<HttpRequest, CompletionStage<HttpResponse>> serviceHandlers =
ServiceHandler.concatOrNotFound(greeterService, echoService);
Http.get(sys)
.newServerAt("127.0.0.1", 8090)
.bind(serviceHandlers)
//#concatOrNotFound
.thenAccept(binding -> {
System.out.println("gRPC server bound to: " + binding.localAddress());
});
//#grpc-web
Function<HttpRequest, CompletionStage<HttpResponse>> grpcWebServiceHandlers =
WebHandler.grpcWebHandler(Arrays.asList(greeterService, echoService), sys, mat);
Http.get(sys)
.newServerAt("127.0.0.1", 8090)
.bind(grpcWebServiceHandlers)
//#grpc-web
.thenAccept(binding -> {
System.out.println("gRPC-Web server bound to: " + binding.localAddress());
});
}