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