use of io.helidon.config.ConfigValue 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.ConfigValue in project helidon by oracle.
the class WithSourcesExample method main.
/**
* Executes the example.
*
* @param args arguments
*/
public static void main(String... args) {
/*
Creates a config source composed of following sources:
- conf/dev.yaml - developer specific configuration, should not be placed in VCS;
- conf/config.yaml - deployment dependent configuration, for example prod, stage, etc;
- default.yaml - application default values, loaded form classpath;
with a filter which convert values with keys ending with "level" to upper case
*/
Config config = Config.builder(file("conf/dev.yaml").optional(), file("conf/config.yaml").optional(), classpath("default.yaml")).addFilter((key, stringValue) -> key.name().equals("level") ? stringValue.toUpperCase() : stringValue).build();
// Environment type, from dev.yaml:
ConfigValue<String> env = config.get("meta.env").asString();
env.ifPresent(e -> System.out.println("Environment: " + e));
assert env.get().equals("DEV");
// Default value (default.yaml): Config Sources Example
String appName = config.get("app.name").asString().get();
System.out.println("Name: " + appName);
assert appName.equals("Config Sources Example");
// Page size, from config.yaml: 10
int pageSize = config.get("app.page-size").asInt().get();
System.out.println("Page size: " + pageSize);
assert pageSize == 10;
// Applied filter (uppercase logging level), from dev.yaml: finest -> FINEST
String level = config.get("component.audit.logging.level").asString().get();
System.out.println("Level: " + level);
assert level.equals("FINE");
}
use of io.helidon.config.ConfigValue in project helidon by oracle.
the class WebSecurity method registerRouting.
private void registerRouting(Routing.Rules routing) {
Config wsConfig = config.get("web-server");
SecurityHandler defaults = SecurityHandler.create(wsConfig.get("defaults"), defaultHandler);
wsConfig.get("paths").asNodeList().ifPresent(configs -> {
for (Config pathConfig : configs) {
List<Http.RequestMethod> methods = pathConfig.get("methods").asNodeList().orElse(List.of()).stream().map(Config::asString).map(ConfigValue::get).map(Http.RequestMethod::create).collect(Collectors.toList());
String path = pathConfig.get("path").asString().orElseThrow(() -> new SecurityException(pathConfig.key() + " must contain path key with a path to " + "register to web server"));
if (methods.isEmpty()) {
routing.any(path, SecurityHandler.create(pathConfig, defaults));
} else {
routing.anyOf(methods, path, SecurityHandler.create(pathConfig, defaults));
}
}
});
}
use of io.helidon.config.ConfigValue in project helidon by oracle.
the class LoadSourcesExample method main.
/**
* Executes the example.
*
* @param args arguments
*/
public static void main(String... args) {
/*
Creates a configuration from list of config sources loaded from meta sources:
- conf/meta-config.yaml - - deployment dependent meta-config file, loaded from file on filesystem;
- meta-config.yaml - application default meta-config file, loaded form classpath;
with a filter which convert values with keys ending with "level" to upper case
*/
Config metaConfig = Config.create(file("conf/meta-config.yaml").optional(), classpath("meta-config.yaml"));
Config config = Config.builder().config(metaConfig).addFilter((key, stringValue) -> key.name().equals("level") ? stringValue.toUpperCase() : stringValue).build();
// Optional environment type, from dev.yaml:
ConfigValue<String> env = config.get("meta.env").asString();
env.ifPresent(e -> System.out.println("Environment: " + e));
assert env.get().equals("DEV");
// Default value (default.yaml): Config Sources Example
String appName = config.get("app.name").asString().get();
System.out.println("Name: " + appName);
assert appName.equals("Config Sources Example");
// Page size, from config.yaml: 10
int pageSize = config.get("app.page-size").asInt().get();
System.out.println("Page size: " + pageSize);
assert pageSize == 10;
// Applied filter (uppercase logging level), from dev.yaml: finest -> FINEST
String level = config.get("component.audit.logging.level").asString().get();
System.out.println("Level: " + level);
assert level.equals("FINE");
}
Aggregations