use of io.helidon.common.http.Http in project helidon by oracle.
the class SecureServer method createWebServer.
/**
* Create the web server.
*/
private static WebServer createWebServer(Config config, Security security) {
Routing routing = Routing.builder().register(WebSecurity.create(security).securityDefaults(WebSecurity.authenticate())).register(new RestService()).build();
WebServer webServer = WebServer.create(routing, config);
webServer.start().thenAccept(s -> {
System.out.println("Web server is UP! http://localhost:" + s.port());
s.whenShutdown().thenRun(() -> System.out.println("gRPC server is DOWN. Good bye!"));
}).exceptionally(t -> {
System.err.println("Web server startup failed: " + t.getMessage());
t.printStackTrace(System.err);
return null;
});
return webServer;
}
use of io.helidon.common.http.Http in project helidon by oracle.
the class SecureServer method createGrpcServer.
/**
* Create the gRPC server.
*/
private static GrpcServer createGrpcServer(Config config, Security security) {
GrpcRouting grpcRouting = GrpcRouting.builder().intercept(GrpcSecurity.create(security).securityDefaults(GrpcSecurity.authenticate())).register(new StringService(), GrpcSecurity.rolesAllowed("admin")).register(new GreetService()).build();
GrpcServer grpcServer = GrpcServer.create(GrpcServerConfiguration.create(config), grpcRouting);
grpcServer.start().thenAccept(s -> {
System.out.println("gRPC server is UP! http://localhost:" + s.port());
s.whenShutdown().thenRun(() -> System.out.println("gRPC server is DOWN. Good bye!"));
}).exceptionally(t -> {
System.err.println("gRPC server startup failed: " + t.getMessage());
t.printStackTrace(System.err);
return null;
});
return grpcServer;
}
use of io.helidon.common.http.Http in project helidon by oracle.
the class ClientMainTest method testMetricsExample.
@Test
public void testMetricsExample() {
String counterName = "example.metric.GET.localhost";
Counter counter = METRIC_REGISTRY.counter(counterName);
assertThat("Counter " + counterName + " has not been 0", counter.getCount(), is(0L));
ClientMain.clientMetricsExample("http://localhost:" + ServerMain.getServerPort() + "/greet", Config.create()).thenAccept(it -> assertThat("Counter " + counterName + " " + "has not been 1", counter.getCount(), is(1L))).await();
}
use of io.helidon.common.http.Http in project helidon by oracle.
the class Main method firstRouting.
// ---------------- EXAMPLES
/**
* True heart of WebServer API is {@link Routing}. It provides fluent way how to assign custom {@link Handler} to the routing
* rule. The rule consists from two main factors - <i>HTTP method</i> and <i>path pattern</i>.
* <p>
* The (route) {@link Handler} is a functional interface which process HTTP {@link io.helidon.webserver.ServerRequest request} and
* writes to the {@link io.helidon.webserver.ServerResponse response}.
*/
public void firstRouting() {
Routing routing = Routing.builder().post("/post-endpoint", (req, res) -> res.status(Http.Status.CREATED_201).send()).get("/get-endpoint", (req, res) -> res.status(Http.Status.NO_CONTENT_204).send("Hello World!")).build();
startServer(routing);
}
use of io.helidon.common.http.Http in project helidon by oracle.
the class ServerBuilderMain method startServer.
static Single<WebServer> startServer(int unsecured, int secured) {
SocketConfiguration socketConf = SocketConfiguration.builder().name("secured").port(secured).tls(tlsConfig()).build();
Single<WebServer> webServer = WebServer.builder().port(unsecured).routing(createPlainRouting()).addSocket(socketConf, createMtlsRouting()).build().start();
webServer.thenAccept(ws -> {
System.out.println("WebServer is up!");
System.out.println("Unsecured: http://localhost:" + ws.port() + "/");
System.out.println("Secured: https://localhost:" + ws.port("secured") + "/");
ws.whenShutdown().thenRun(() -> System.out.println("WEB server is DOWN. Good bye!"));
}).exceptionally(t -> {
System.err.println("Startup failed: " + t.getMessage());
t.printStackTrace(System.err);
return null;
});
return webServer;
}
Aggregations