Search in sources :

Example 16 with WebServer

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;
    });
}
Also used : StringService(io.helidon.grpc.examples.common.StringService) GrpcServerConfiguration(io.helidon.grpc.server.GrpcServerConfiguration) GreetServiceJava(io.helidon.grpc.examples.common.GreetServiceJava) Config(io.helidon.config.Config) WebServer(io.helidon.webserver.WebServer) GrpcServer(io.helidon.grpc.server.GrpcServer) GreetService(io.helidon.grpc.examples.common.GreetService) LogConfig(io.helidon.common.LogConfig) Routing(io.helidon.webserver.Routing) GrpcRouting(io.helidon.grpc.server.GrpcRouting) HealthSupport(io.helidon.health.HealthSupport) HealthChecks(io.helidon.health.checks.HealthChecks) GrpcServerConfiguration(io.helidon.grpc.server.GrpcServerConfiguration) Config(io.helidon.config.Config) LogConfig(io.helidon.common.LogConfig) HealthSupport(io.helidon.health.HealthSupport) Routing(io.helidon.webserver.Routing) GrpcRouting(io.helidon.grpc.server.GrpcRouting) GrpcServer(io.helidon.grpc.server.GrpcServer)

Example 17 with WebServer

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;
    });
}
Also used : WebServer(io.helidon.webserver.WebServer)

Example 18 with WebServer

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;
}
Also used : Driver(org.neo4j.driver.Driver) JsonbSupport(io.helidon.media.jsonb.JsonbSupport) Config(io.helidon.config.Config) LogManager(java.util.logging.LogManager) IOException(java.io.IOException) MovieRepository(io.helidon.examples.integrations.neo4j.se.domain.MovieRepository) HealthSupport(io.helidon.health.HealthSupport) Neo4j(io.helidon.integrations.neo4j.Neo4j) JsonpSupport(io.helidon.media.jsonp.JsonpSupport) Neo4jHealthCheck(io.helidon.integrations.neo4j.health.Neo4jHealthCheck) Neo4jMetricsSupport(io.helidon.integrations.neo4j.metrics.Neo4jMetricsSupport) WebServer(io.helidon.webserver.WebServer) Single(io.helidon.common.reactive.Single) MetricsSupport(io.helidon.metrics.MetricsSupport) LogConfig(io.helidon.common.LogConfig) Routing(io.helidon.webserver.Routing) InputStream(java.io.InputStream) HealthChecks(io.helidon.health.checks.HealthChecks) WebServer(io.helidon.webserver.WebServer) Config(io.helidon.config.Config) LogConfig(io.helidon.common.LogConfig)

Example 19 with WebServer

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!"));
}
Also used : WebServer(io.helidon.webserver.WebServer) Config(io.helidon.config.Config) LogConfig(io.helidon.common.LogConfig) OciAutonomousDbRx(io.helidon.integrations.oci.atp.OciAutonomousDbRx)

Example 20 with WebServer

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);
}
Also used : Arrays(java.util.Arrays) Security(io.helidon.security.Security) Set(java.util.Set) HashMap(java.util.HashMap) SecurityContext(io.helidon.security.SecurityContext) MediaType(io.helidon.common.http.MediaType) TimeUnit(java.util.concurrent.TimeUnit) StaticContentSupport(io.helidon.webserver.staticcontent.StaticContentSupport) Map(java.util.Map) WebServer(io.helidon.webserver.WebServer) Optional(java.util.Optional) WebSecurity(io.helidon.security.integration.webserver.WebSecurity) LogConfig(io.helidon.common.LogConfig) Routing(io.helidon.webserver.Routing) HttpBasicAuthProvider(io.helidon.security.providers.httpauth.HttpBasicAuthProvider) SecureUserStore(io.helidon.security.providers.httpauth.SecureUserStore) Optional(java.util.Optional) SecurityContext(io.helidon.security.SecurityContext) Routing(io.helidon.webserver.Routing)

Aggregations

WebServer (io.helidon.webserver.WebServer)88 Config (io.helidon.config.Config)49 Routing (io.helidon.webserver.Routing)48 LogConfig (io.helidon.common.LogConfig)34 Single (io.helidon.common.reactive.Single)17 JsonpSupport (io.helidon.media.jsonp.JsonpSupport)16 MetricsSupport (io.helidon.metrics.MetricsSupport)16 HealthSupport (io.helidon.health.HealthSupport)15 HealthChecks (io.helidon.health.checks.HealthChecks)13 ConfigSources (io.helidon.config.ConfigSources)10 TimeUnit (java.util.concurrent.TimeUnit)10 WebClient (io.helidon.webclient.WebClient)9 WebClientResponse (io.helidon.webclient.WebClientResponse)9 CountDownLatch (java.util.concurrent.CountDownLatch)9 Test (org.junit.jupiter.api.Test)9 Http (io.helidon.common.http.Http)8 MediaType (io.helidon.common.http.MediaType)8 IOException (java.io.IOException)8 SecurityContext (io.helidon.security.SecurityContext)7 StaticContentSupport (io.helidon.webserver.staticcontent.StaticContentSupport)7