use of io.helidon.common.reactive.Single in project helidon by oracle.
the class Main method startServer.
/**
* Start the server.
* @return the created {@link WebServer} instance
*/
static Single<WebServer> startServer() {
// load logging configuration
LogConfig.configureRuntime();
// By default this will pick up application.yaml from the classpath
Config config = Config.create();
WebServer server = WebServer.builder().tracer(TracerBuilder.create(config.get("tracing"))).routing(createRouting(config)).config(config.get("server")).addMediaSupport(JsonpSupport.create()).build();
Single<WebServer> webserver = server.start();
// Try to start the server. If successful, print some info and arrange to
// print a message at shutdown. If unsuccessful, print the exception.
webserver.thenAccept(ws -> {
System.out.println("WEB server is up! http://localhost:" + ws.port() + "/greet");
ws.whenShutdown().thenRun(() -> System.out.println("WEB server is DOWN. Good bye!"));
}).exceptionallyAccept(t -> {
System.err.println("Startup failed: " + t.getMessage());
t.printStackTrace(System.err);
});
return webserver;
}
use of io.helidon.common.reactive.Single in project helidon by oracle.
the class RestApiBase method responseSupplier.
/**
* Create a response supplier from the request.
* This method checks if there is a payload, and prepares the supplier based on this information.
*
* @param method HTTP method to invoke
* @param path path to invoke
* @param request request that may contain a JSON entity
* @param requestId request ID to use for this request
* @return supplier of response that is used with fault tolerance
*/
protected Supplier<Single<WebClientResponse>> responseSupplier(Http.RequestMethod method, String path, ApiRequest<?> request, String requestId) {
WebClientRequestBuilder requestBuilder = webClient.method(method).path(path);
addHeaders(requestBuilder, path, request, method, requestId);
addQueryParams(requestBuilder, path, request, method, requestId);
Optional<JsonObject> payload = request.toJson(jsonBuilderFactory);
Supplier<Single<WebClientResponse>> responseSupplier;
// now let's update the request
if (payload.isPresent()) {
responseSupplier = requestJsonPayload(path, request, method, requestId, requestBuilder, payload.get());
} else {
responseSupplier = requestPayload(path, request, method, requestId, requestBuilder);
}
return responseSupplier;
}
use of io.helidon.common.reactive.Single in project helidon by oracle.
the class Main method startServer.
/**
* Start the server.
* @return the created {@link WebServer} instance
* @throws IOException if there are problems reading logging properties
*/
static Single<WebServer> startServer() throws IOException {
// load logging configuration
LogConfig.configureRuntime();
// By default this will pick up application.yaml from the classpath
Config config = Config.create();
// Get webserver config from the "server" section of application.yaml
Single<WebServer> server = WebServer.builder(createRouting(config)).config(config.get("server")).addMediaSupport(JsonpSupport.create()).build().start();
server.thenAccept(ws -> {
System.out.println("WEB server is up! http://localhost:" + ws.port() + "/greet");
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 server;
}
use of io.helidon.common.reactive.Single in project helidon by oracle.
the class Main method startServer.
/**
* Start the server.
* @return the created {@link WebServer} instance
*/
static Single<WebServer> startServer() {
// load logging configuration
LogConfig.configureRuntime();
// By default this will pick up application.yaml from the classpath
Config config = Config.create();
// Get webserver config from the "server" section of application.yaml and JSON support registration
Single<WebServer> server = WebServer.builder(createRouting(config)).config(config.get("server")).addMediaSupport(JsonbSupport.create()).build().start();
server.thenAccept(ws -> {
System.out.println("WEB server is up!");
System.out.println("Web client at: http://localhost:" + ws.port() + "/public/index.html");
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 server;
}
Aggregations