use of io.helidon.webserver.WebServer in project metro-jax-ws by eclipse-ee4j.
the class Main method startServer.
static WebServer startServer() {
setupLogging();
// By default this will pick up application.yaml from the classpath
Config config = buildConfig();
// Get webserver config from the "server" section of application.yaml
WebServer server = WebServer.builder().config(config.get("server")).routing(buildRouting(config)).build();
// Try to start the server. If successful, print some info and arrange to
// print a message at shutdown. If unsuccessful, print the exception.
server.start().thenAccept(ws -> {
System.out.println("WEB server is up! http://localhost:" + ws.port());
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;
});
// Server threads are not daemon. No need to block. Just react.
return server;
}
use of io.helidon.webserver.WebServer in project helidon by oracle.
the class Main method main.
/**
* Start the example. Prints endpoints to standard output.
*
* @param args not used
*/
public static void main(String[] args) {
serverStartTime = System.currentTimeMillis();
HealthSupport health = HealthSupport.builder().addLiveness(HealthChecks.healthChecks()).addReadiness(() -> HealthCheckResponse.named("exampleHealthCheck").up().withData("time", System.currentTimeMillis()).build()).addStartup(() -> HealthCheckResponse.named("exampleStartCheck").status(isStarted()).withData("time", System.currentTimeMillis()).build()).build();
Routing routing = Routing.builder().register(health).get("/hello", (req, res) -> res.send("Hello World!")).build();
WebServer ws = WebServer.create(routing);
ws.start().thenApply(webServer -> {
String endpoint = "http://localhost:" + webServer.port();
System.out.println("Hello World started on " + endpoint + "/hello");
System.out.println("Health checks available on " + endpoint + "/health");
return null;
});
}
use of io.helidon.webserver.WebServer 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().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.webserver.WebServer in project helidon by oracle.
the class Main method startServer.
/**
* Start the server.
*
* @return the created {@link WebServer} instance
*/
static WebServer startServer() {
// load logging configuration
LogConfig.configureRuntime();
// By default this will pick up application.yaml from the classpath
Config config = Config.create();
SendingService sendingService = new SendingService(config);
WebServer server = WebServer.builder(createRouting(sendingService)).config(config.get("server")).build();
server.start().thenAccept(ws -> {
System.out.println("WEB server is up! http://localhost:" + ws.port());
ws.whenShutdown().thenRun(() -> {
// Stop messaging properly
sendingService.shutdown();
System.out.println("WEB server is DOWN. Good bye!");
});
}).exceptionally(t -> {
System.err.println("Startup failed: " + t.getMessage());
t.printStackTrace(System.err);
return null;
});
// Server threads are not daemon. No need to block. Just react.
return server;
}
use of io.helidon.webserver.WebServer in project helidon by oracle.
the class Main method startFrontendServer.
/**
* Start the server.
* @return the created {@link WebServer} instance
*/
public static Single<WebServer> startFrontendServer() {
// configure logging in order to not have the standard JVM defaults
LogConfig.configureRuntime();
Config config = Config.builder().sources(ConfigSources.environmentVariables()).build();
WebServer webServer = WebServer.builder(Routing.builder().register(new TranslatorFrontendService(config.get("backend.host").asString().orElse("localhost"), 9080))).port(8080).tracer(TracerBuilder.create(config.get("tracing")).serviceName("helidon-webserver-translator-frontend").registerGlobal(false).build()).build();
return webServer.start().peek(ws -> {
System.out.println("WEB server is up! http://localhost:" + ws.port());
ws.whenShutdown().thenRun(() -> System.out.println("WEB server is DOWN. Good bye!"));
}).onError(t -> {
System.err.println("Startup failed: " + t.getMessage());
t.printStackTrace(System.err);
});
}
Aggregations