Search in sources :

Example 86 with WebServer

use of io.helidon.webserver.WebServer in project helidon by oracle.

the class MicrometerEndpointTests method runTest.

private static void runTest(String contextForRequest, Supplier<MicrometerSupport> micrometerSupportSupplier) throws ExecutionException, InterruptedException {
    WebServer webServer = null;
    try {
        webServer = WebServer.builder().host("localhost").port(-1).routing(prepareRouting(micrometerSupportSupplier)).build().start().await();
        WebClientResponse webClientResponse = WebClient.builder().baseUri(String.format("http://localhost:%d%s", webServer.port(), contextForRequest)).build().get().accept(MediaType.TEXT_PLAIN).request().get();
        MatcherAssert.assertThat(webClientResponse.status(), is(Http.Status.OK_200));
    } finally {
        if (webServer != null) {
            webServer.shutdown().await();
        }
    }
}
Also used : WebClientResponse(io.helidon.webclient.WebClientResponse) WebServer(io.helidon.webserver.WebServer)

Example 87 with WebServer

use of io.helidon.webserver.WebServer in project helidon by oracle.

the class MicrometerTestUtil method startServer.

public static WebServer startServer(int port, MicrometerSupport.Builder... builders) throws InterruptedException, ExecutionException, TimeoutException {
    WebServer result = WebServer.builder(Routing.builder().register(builders).build()).port(port).build().start().toCompletableFuture().get(10, TimeUnit.SECONDS);
    LOGGER.log(Level.INFO, "Started server at: https://localhost:{0}", result.port());
    return result;
}
Also used : WebServer(io.helidon.webserver.WebServer)

Example 88 with WebServer

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;
}
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)

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