Search in sources :

Example 1 with Routing

use of io.helidon.webserver.Routing in project visuale by Cantara.

the class Main method startServer.

public WebServer startServer(int port, String contextPath) {
    Routing routing = Routing.builder().register(contextPath, healthResource).register(contextPath, statusResource).register(contextPath + "/favicon.ico", StaticContentSupport.builder("/nuxt-spa/dist/favicon.ico").build()).register(contextPath + "/nuxt-spa", StaticContentSupport.builder("/nuxt-spa").build()).register(contextPath + "/_nuxt", StaticContentSupport.builder("/nuxt-spa/dist/_nuxt").build()).register(contextPath + "/", StaticContentSupport.builder("/nuxt-spa/dist").welcomeFileName("index.html").build()).build();
    WebServer ws = WebServer.builder().port(port).addMediaSupport(JacksonSupport.create()).routing(routing).build();
    // start the server
    // Server server = startServer();
    ws.start().thenApply(webServer -> {
        if (accessToken == null || accessToken.length() < 1) {
            String endpoint = "http://localhost:" + webServer.port() + contextPath;
            System.out.println("- Visit Dashboard at: " + endpoint + "/?ui_extension=groupByTag&servicetype=true");
            System.out.println(" - Health checks available on: " + endpoint + "/health");
            System.out.println(" - Environment status available on:  " + endpoint + "/status/");
        } else {
            String endpoint = "http://localhost:" + webServer.port() + contextPath;
            System.out.println(" Visit Dashboard at: " + endpoint + "/?accessToken=" + accessToken + "&ui_extension=groupByTag&servicetype=true");
            System.out.println(" - Health checks available on: " + endpoint + "/health");
            System.out.println(" - Environment status available on:  " + endpoint + "/status/?accessToken=" + accessToken);
        }
        return null;
    });
    return ws;
}
Also used : WebServer(io.helidon.webserver.WebServer) Routing(io.helidon.webserver.Routing)

Example 2 with Routing

use of io.helidon.webserver.Routing 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;
}
Also used : Config(io.helidon.config.Config) LogManager(java.util.logging.LogManager) WebServer(io.helidon.webserver.WebServer) MetroSupport(org.eclipse.metro.helidon.MetroSupport) IOException(java.io.IOException) ConfigSources(io.helidon.config.ConfigSources) Routing(io.helidon.webserver.Routing) InputStream(java.io.InputStream) WebServer(io.helidon.webserver.WebServer) Config(io.helidon.config.Config)

Example 3 with Routing

use of io.helidon.webserver.Routing 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;
}
Also used : Config(io.helidon.config.Config) LogManager(java.util.logging.LogManager) WebServer(io.helidon.webserver.WebServer) MetroSupport(org.eclipse.metro.helidon.MetroSupport) IOException(java.io.IOException) ConfigSources(io.helidon.config.ConfigSources) Routing(io.helidon.webserver.Routing) InputStream(java.io.InputStream) WebServer(io.helidon.webserver.WebServer) Config(io.helidon.config.Config)

Example 4 with Routing

use of io.helidon.webserver.Routing 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;
}
Also used : Config(io.helidon.config.Config) LogManager(java.util.logging.LogManager) WebServer(io.helidon.webserver.WebServer) MetroSupport(org.eclipse.metro.helidon.MetroSupport) IOException(java.io.IOException) ConfigSources(io.helidon.config.ConfigSources) Routing(io.helidon.webserver.Routing) InputStream(java.io.InputStream) WebServer(io.helidon.webserver.WebServer) Config(io.helidon.config.Config)

Example 5 with Routing

use of io.helidon.webserver.Routing 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;
}
Also used : Config(io.helidon.config.Config) LogManager(java.util.logging.LogManager) WebServer(io.helidon.webserver.WebServer) MetroSupport(org.eclipse.metro.helidon.MetroSupport) IOException(java.io.IOException) ConfigSources(io.helidon.config.ConfigSources) Routing(io.helidon.webserver.Routing) RestService(org.eclipse.metro.helidon.example.client.RestService) InputStream(java.io.InputStream) WebServer(io.helidon.webserver.WebServer) Config(io.helidon.config.Config)

Aggregations

Routing (io.helidon.webserver.Routing)86 WebServer (io.helidon.webserver.WebServer)38 Config (io.helidon.config.Config)33 Test (org.junit.jupiter.api.Test)32 Http (io.helidon.common.http.Http)23 TimeUnit (java.util.concurrent.TimeUnit)21 LogConfig (io.helidon.common.LogConfig)19 MediaType (io.helidon.common.http.MediaType)19 CoreMatchers.is (org.hamcrest.CoreMatchers.is)17 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)17 SecurityContext (io.helidon.security.SecurityContext)16 HttpException (io.helidon.webserver.HttpException)15 Optional (java.util.Optional)15 CountDownLatch (java.util.concurrent.CountDownLatch)15 WebSecurity (io.helidon.security.integration.webserver.WebSecurity)13 SERVICE_UNAVAILABLE_503 (io.helidon.common.http.Http.Status.SERVICE_UNAVAILABLE_503)11 JsonpSupport (io.helidon.media.jsonp.JsonpSupport)11 Security (io.helidon.security.Security)11 StaticContentSupport (io.helidon.webserver.staticcontent.StaticContentSupport)10 TestResponse (io.helidon.webserver.testsupport.TestResponse)10