Search in sources :

Example 51 with Config

use of io.helidon.config.Config in project helidon by oracle.

the class FrontendTest method startFrontendServer.

private static void startFrontendServer() {
    Properties prop = new Properties();
    prop.put("services.backend.endpoint", "http://127.0.0.1:" + serverBackend.port());
    Config config = Config.builder().sources(List.of(classpath("frontend-application.yaml"), ConfigSources.create(prop))).build();
    Client client = ClientBuilder.newClient();
    BackendServiceClient bsc = new BackendServiceClient(client, config);
    serverFrontend = WebServer.builder(createRouting(Security.create(config.get("security")), config, bsc)).config(config.get("webserver")).addMediaSupport(JsonpSupport.create()).build();
    serverFrontend.start();
}
Also used : Config(io.helidon.config.Config) Properties(java.util.Properties) WebClient(io.helidon.webclient.WebClient) Client(jakarta.ws.rs.client.Client)

Example 52 with Config

use of io.helidon.config.Config 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);
    });
}
Also used : TracerBuilder(io.helidon.tracing.TracerBuilder) Config(io.helidon.config.Config) WebServer(io.helidon.webserver.WebServer) Single(io.helidon.common.reactive.Single) LogConfig(io.helidon.common.LogConfig) ConfigSources(io.helidon.config.ConfigSources) Routing(io.helidon.webserver.Routing) WebServer(io.helidon.webserver.WebServer) Config(io.helidon.config.Config) LogConfig(io.helidon.common.LogConfig)

Example 53 with Config

use of io.helidon.config.Config in project helidon by oracle.

the class ClientMain method main.

/**
 * Executes WebClient examples.
 *
 * If no argument provided it will take server port from configuration server.port.
 *
 * User can override port from configuration by main method parameter with the specific port.
 *
 * @param args main method
 */
public static void main(String[] args) {
    Config config = Config.create();
    String url;
    if (args.length == 0) {
        ConfigValue<Integer> port = config.get("server.port").asInt();
        if (!port.isPresent() || port.get() == -1) {
            throw new IllegalStateException("Unknown port! Please specify port as a main method parameter " + "or directly to config server.port");
        }
        url = "http://localhost:" + port.get() + "/greet";
    } else {
        url = "http://localhost:" + Integer.parseInt(args[0]) + "/greet";
    }
    WebClient webClient = WebClient.builder().baseUri(url).config(config.get("client")).addMediaSupport(JsonpSupport.create()).build();
    performPutMethod(webClient).flatMapSingle(it -> performGetMethod(webClient)).flatMapSingle(it -> followRedirects(webClient)).flatMapSingle(it -> getResponseAsAnJsonObject(webClient)).flatMapSingle(it -> saveResponseToFile(webClient)).flatMapSingle(it -> clientMetricsExample(url, config)).await();
}
Also used : Arrays(java.util.Arrays) WebClient(io.helidon.webclient.WebClient) WebClientService(io.helidon.webclient.spi.WebClientService) Files(java.nio.file.Files) IoMulti(io.helidon.common.reactive.IoMulti) Config(io.helidon.config.Config) WebClientResponse(io.helidon.webclient.WebClientResponse) DataChunk(io.helidon.common.http.DataChunk) JsonBuilderFactory(jakarta.json.JsonBuilderFactory) IOException(java.io.IOException) ConfigValue(io.helidon.config.ConfigValue) Json(jakarta.json.Json) JsonpSupport(io.helidon.media.jsonp.JsonpSupport) Counter(org.eclipse.microprofile.metrics.Counter) Paths(java.nio.file.Paths) JsonObject(jakarta.json.JsonObject) Single(io.helidon.common.reactive.Single) MetricRegistry(org.eclipse.microprofile.metrics.MetricRegistry) Http(io.helidon.common.http.Http) Path(java.nio.file.Path) Collections(java.util.Collections) RegistryFactory(io.helidon.metrics.RegistryFactory) WebClientMetrics(io.helidon.webclient.metrics.WebClientMetrics) Config(io.helidon.config.Config) WebClient(io.helidon.webclient.WebClient)

Example 54 with Config

use of io.helidon.config.Config in project helidon by oracle.

the class ServerMain method startServer.

/**
 * Start the server.
 *
 * @return the created {@link WebServer} instance
 */
static Single<WebServer> startServer() {
    // By default this will pick up application.yaml from the classpath
    Config config = Config.create();
    WebServer server = WebServer.builder(createRouting(config)).config(config.get("server")).addMediaSupport(JsonpSupport.create()).build();
    // Server threads are not daemon. No need to block. Just react.
    return server.start().peek(ws -> {
        serverPort = ws.port();
        System.out.println("WEB server is up! http://localhost:" + ws.port() + "/greet");
        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);
    });
}
Also used : JsonpSupport(io.helidon.media.jsonp.JsonpSupport) Config(io.helidon.config.Config) WebServer(io.helidon.webserver.WebServer) Single(io.helidon.common.reactive.Single) MetricsSupport(io.helidon.metrics.MetricsSupport) Routing(io.helidon.webserver.Routing) WebServer(io.helidon.webserver.WebServer) Config(io.helidon.config.Config)

Example 55 with Config

use of io.helidon.config.Config in project helidon by oracle.

the class ClientMainTest method createWebClient.

private void createWebClient(int port, WebClientService... services) {
    Config config = Config.create();
    WebClient.Builder builder = WebClient.builder().baseUri("http://localhost:" + port + "/greet").config(config.get("client")).addMediaSupport(JsonpSupport.create());
    for (WebClientService service : services) {
        builder.addService(service);
    }
    webClient = builder.build();
}
Also used : Config(io.helidon.config.Config) WebClientService(io.helidon.webclient.spi.WebClientService) WebClient(io.helidon.webclient.WebClient)

Aggregations

Config (io.helidon.config.Config)329 Test (org.junit.jupiter.api.Test)169 LogConfig (io.helidon.common.LogConfig)56 WebServer (io.helidon.webserver.WebServer)54 Routing (io.helidon.webserver.Routing)51 BeforeAll (org.junit.jupiter.api.BeforeAll)24 Security (io.helidon.security.Security)20 HealthSupport (io.helidon.health.HealthSupport)18 Single (io.helidon.common.reactive.Single)17 MetricsSupport (io.helidon.metrics.MetricsSupport)16 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)16 ConfigSources (io.helidon.config.ConfigSources)15 JsonpSupport (io.helidon.media.jsonp.JsonpSupport)15 SecurityContext (io.helidon.security.SecurityContext)15 Optional (java.util.Optional)15 TimeUnit (java.util.concurrent.TimeUnit)15 WebSecurity (io.helidon.security.integration.webserver.WebSecurity)13 HealthChecks (io.helidon.health.checks.HealthChecks)12 WebClient (io.helidon.webclient.WebClient)12 GrpcRouting (io.helidon.grpc.server.GrpcRouting)11