use of io.helidon.webserver.WebServer in project helidon by oracle.
the class Server method main.
/**
* The main program entry point.
*
* @param args the program arguments
*/
public static void main(String[] args) {
// By default this will pick up application.yaml from the classpath
Config config = Config.create();
// load logging configuration
LogConfig.configureRuntime();
// Get gRPC server config from the "grpc" section of application.yaml
GrpcServerConfiguration serverConfig = GrpcServerConfiguration.builder(config.get("grpc")).build();
GrpcServer grpcServer = GrpcServer.create(serverConfig, createRouting(config));
// Try to start the server. If successful, print some info and arrange to
// print a message at shutdown. If unsuccessful, print the exception.
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("Startup failed: " + t.getMessage());
t.printStackTrace(System.err);
return null;
});
// add support for standard and gRPC health checks
HealthSupport health = HealthSupport.builder().addLiveness(HealthChecks.healthChecks()).addLiveness(grpcServer.healthChecks()).build();
// start web server with health endpoint
Routing routing = Routing.builder().register(health).build();
WebServer.create(routing, config.get("webserver")).start().thenAccept(s -> {
System.out.println("HTTP server is UP! http://localhost:" + s.port());
s.whenShutdown().thenRun(() -> System.out.println("HTTP server is DOWN. Good bye!"));
}).exceptionally(t -> {
System.err.println("Startup failed: " + t.getMessage());
t.printStackTrace(System.err);
return null;
});
}
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) {
WebServer server = WebServer.builder().routing(Routing.builder().register(GraphQlSupport.create(buildSchema())).build()).build();
server.start().thenApply(webServer -> {
String endpoint = "http://localhost:" + webServer.port();
System.out.println("GraphQL started on " + endpoint + "/graphql");
System.out.println("GraphQL schema available on " + endpoint + "/graphql/schema.graphql");
return null;
});
}
use of io.helidon.webserver.WebServer in project helidon by oracle.
the class Main method startServer.
/**
* Start the server.
* @return the created WebServer instance
*/
public static Single<WebServer> startServer() {
// load logging configuration
LogConfig.configureRuntime();
// By default this will pick up application.yaml from the classpath
Config config = Config.create();
Single<WebServer> server = WebServer.builder(createRouting(config)).config(config.get("server")).addMediaSupport(JsonpSupport.create()).addMediaSupport(JsonbSupport.create()).build().start();
server.thenAccept(ws -> {
System.out.println("WEB server is up! http://localhost:" + ws.port() + "/api/movies");
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.webserver.WebServer in project helidon by oracle.
the class OciAtpMain method main.
/**
* Application main entry point.
*
* @param args command line arguments.
*/
public static void main(String[] args) {
// load logging configuration
LogConfig.configureRuntime();
// By default this will pick up application.yaml from the classpath
Config config = Config.create();
Config ociConfig = config.get("oci");
// this requires OCI configuration in the usual place
// ~/.oci/config
OciAutonomousDbRx autonomousDbRx = OciAutonomousDbRx.create(ociConfig);
// Prepare routing for the server
WebServer server = WebServer.builder().config(config.get("server")).routing(Routing.builder().register("/atp", new AtpService(autonomousDbRx, config))).build();
// Start the server and print some info.
server.start().thenAccept(ws -> {
System.out.println("WEB server is up! http://localhost:" + ws.port() + "/");
});
// Server threads are not daemon. NO need to block. Just react.
server.whenShutdown().thenRun(() -> System.out.println("WEB server is DOWN. Good bye!"));
}
use of io.helidon.webserver.WebServer in project helidon by oracle.
the class BasicExampleBuilderMain method startServer.
static WebServer startServer() {
LogConfig.initClass();
Routing routing = Routing.builder().register(buildWebSecurity().securityDefaults(WebSecurity.authenticate())).any("/static[/{*}]", WebSecurity.rolesAllowed("user")).register("/static", StaticContentSupport.create("/WEB")).get("/noRoles", WebSecurity.enforce()).get("/user[/{*}]", WebSecurity.rolesAllowed("user")).get("/admin", WebSecurity.rolesAllowed("admin")).get("/deny", WebSecurity.rolesAllowed("deny").audit()).any("/noAuthn", WebSecurity.rolesAllowed("admin").authenticationOptional().audit()).get("/{*}", (req, res) -> {
Optional<SecurityContext> securityContext = req.context().get(SecurityContext.class);
res.headers().contentType(MediaType.TEXT_PLAIN.withCharset("UTF-8"));
res.send("Hello, you are: \n" + securityContext.map(ctx -> ctx.user().orElse(SecurityContext.ANONYMOUS).toString()).orElse("Security context is null"));
}).build();
return WebServer.builder().routing(routing).build().start().await(10, TimeUnit.SECONDS);
}
Aggregations