use of io.helidon.webserver.Routing in project helidon by oracle.
the class ServerCdiExtension method addApplication.
private void addApplication(JaxRsCdiExtension jaxRs, JaxRsApplication applicationMeta, InjectionManager injectionManager) {
LOGGER.info("Registering JAX-RS Application: " + applicationMeta.appName());
Optional<String> contextRoot = jaxRs.findContextRoot(config, applicationMeta);
Optional<String> namedRouting = jaxRs.findNamedRouting(config, applicationMeta);
boolean routingNameRequired = jaxRs.isNamedRoutingRequired(config, applicationMeta);
if (LOGGER.isLoggable(Level.FINEST)) {
LOGGER.finest("Application " + applicationMeta.appName() + ", class: " + applicationMeta.appClassName() + ", contextRoot: " + contextRoot + ", namedRouting: " + namedRouting + ", routingNameRequired: " + routingNameRequired);
}
Routing.Builder routing = routingBuilder(namedRouting, routingNameRequired, applicationMeta.appName());
JerseySupport jerseySupport = jaxRs.toJerseySupport(jaxRsExecutorService, applicationMeta, injectionManager);
if (contextRoot.isPresent()) {
String contextRootString = contextRoot.get();
LOGGER.fine(() -> "JAX-RS application " + applicationMeta.appName() + " registered on '" + contextRootString + "'");
routing.register(contextRootString, jerseySupport);
} else {
LOGGER.fine(() -> "JAX-RS application " + applicationMeta.appName() + " registered on '/'");
routing.register(jerseySupport);
}
jerseySupports.add(jerseySupport);
}
use of io.helidon.webserver.Routing in project helidon by oracle.
the class ReactiveVaultMain method main.
/**
* Main method.
* @param args ignored
*/
public static void main(String[] args) {
LogConfig.configureRuntime();
// as I cannot share my secret configuration, let's combine the configuration
// from my home directory with the one compiled into the jar
// when running this example, you can either update the application.yaml in resources directory
// or use the same approach
Config config = buildConfig();
// we have three configurations available
// 1. Token based authentication
Vault tokenVault = Vault.builder().config(config.get("vault.token")).updateWebClient(it -> it.connectTimeout(5, TimeUnit.SECONDS).readTimeout(5, TimeUnit.SECONDS)).build();
// 2. App role based authentication - must be created after we obtain the role id an token
// 3. Kubernetes (k8s) based authentication (requires to run on k8s) - must be created after we create
// the authentication method
// the tokenVault is using the root token and can be used to enable engines and
// other authentication mechanisms
CompletionAwaitable<Void> k8sFuture = new K8sExample(tokenVault, config.get("vault.k8s")).run().forSingle(System.out::println);
CompletionAwaitable<Void> appRoleFuture = new AppRoleExample(tokenVault, config.get("vault.approle")).run().forSingle(System.out::println);
/*
We do not need to block here for our examples, as the server started below will keep the process running
*/
SysRx sys = tokenVault.sys(SysRx.API);
// we use await for webserver, as we do not care if we block the main thread - it is not used
// for anything
WebServer webServer = WebServer.builder().config(config.get("server")).routing(Routing.builder().register("/cubbyhole", new CubbyholeService(sys, tokenVault.secrets(CubbyholeSecretsRx.ENGINE))).register("/kv1", new Kv1Service(sys, tokenVault.secrets(Kv1SecretsRx.ENGINE))).register("/kv2", new Kv2Service(sys, tokenVault.secrets(Kv2SecretsRx.ENGINE))).register("/transit", new TransitService(sys, tokenVault.secrets(TransitSecretsRx.ENGINE)))).build().start().await();
try {
appRoleFuture.await();
} catch (Exception e) {
System.err.println("AppRole example failed");
e.printStackTrace();
}
try {
k8sFuture.await();
} catch (Exception e) {
System.err.println("Kubernetes example failed");
e.printStackTrace();
}
String baseAddress = "http://localhost:" + webServer.port() + "/";
System.out.println("Server started on " + baseAddress);
System.out.println();
System.out.println("Key/Value Version 1 Secrets Engine");
System.out.println("\t" + baseAddress + "kv1/enable");
System.out.println("\t" + baseAddress + "kv1/create");
System.out.println("\t" + baseAddress + "kv1/secrets/first/secret");
System.out.println("\tcurl -i -X DELETE " + baseAddress + "kv1/secrets/first/secret");
System.out.println("\t" + baseAddress + "kv1/disable");
System.out.println();
System.out.println("Key/Value Version 2 Secrets Engine");
System.out.println("\t" + baseAddress + "kv2/create");
System.out.println("\t" + baseAddress + "kv2/secrets/first/secret");
System.out.println("\tcurl -i -X DELETE " + baseAddress + "kv2/secrets/first/secret");
System.out.println();
System.out.println("Transit Secrets Engine");
System.out.println("\t" + baseAddress + "transit/enable");
System.out.println("\t" + baseAddress + "transit/keys");
System.out.println("\t" + baseAddress + "transit/encrypt/secret_text");
System.out.println("\t" + baseAddress + "transit/decrypt/cipher_text");
System.out.println("\t" + baseAddress + "transit/sign");
System.out.println("\t" + baseAddress + "transit/verify/sign/signature_text");
System.out.println("\t" + baseAddress + "transit/hmac");
System.out.println("\t" + baseAddress + "transit/verify/hmac/hmac_text");
System.out.println("\tcurl -i -X DELETE " + baseAddress + "transit/keys");
System.out.println("\t" + baseAddress + "transit/disable");
}
use of io.helidon.webserver.Routing in project helidon by oracle.
the class Main method startServer.
/**
* Start the server.
* @return the created {@link WebServer} instance
*/
static Single<WebServer> startServer() {
// load logging configuration
LogConfig.configureRuntime();
// By default this will pick up application.yaml from the classpath
Config config = Config.create();
WebServer server = WebServer.builder().tracer(TracerBuilder.create(config.get("tracing"))).routing(createRouting(config)).config(config.get("server")).addMediaSupport(JsonpSupport.create()).build();
Single<WebServer> webserver = server.start();
// Try to start the server. If successful, print some info and arrange to
// print a message at shutdown. If unsuccessful, print the exception.
webserver.thenAccept(ws -> {
System.out.println("WEB server is up! http://localhost:" + ws.port() + "/greet");
ws.whenShutdown().thenRun(() -> System.out.println("WEB server is DOWN. Good bye!"));
}).exceptionallyAccept(t -> {
System.err.println("Startup failed: " + t.getMessage());
t.printStackTrace(System.err);
});
return webserver;
}
use of io.helidon.webserver.Routing in project helidon by oracle.
the class Se1Main method startServer.
/**
* Start the server.
* @return the created {@link io.helidon.webserver.WebServer} instance
*/
static WebServer startServer() {
// load logging configuration
LogConfig.configureRuntime();
// 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().routing(createRouting(config)).config(config.get("server")).tracer(TracerBuilder.create(config.get("tracing")).build()).addMediaSupport(JsonpSupport.create()).addMediaSupport(JsonbSupport.create()).printFeatureDetails(true).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() + "/greet");
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;
});
return server;
}
use of io.helidon.webserver.Routing in project helidon by oracle.
the class Server method main.
/**
* The main program entry point.
*
* @param args the program arguments
*
* @throws Exception if an error occurs
*/
public static void main(String[] args) throws Exception {
// By default this will pick up application.yaml from the classpath
Config config = Config.create();
// load logging configuration
LogConfig.configureRuntime();
// Get gRPC server config from the "grpc" section of application.yaml
GrpcServerConfiguration serverConfig = GrpcServerConfiguration.builder(config.get("grpc")).build();
GrpcRouting grpcRouting = GrpcRouting.builder().intercept(// global metrics - all service methods counted
GrpcMetrics.counted()).register(// GreetService uses global metrics so all methods are counted
new GreetService(config)).register(new StringService(), rules -> {
// service level metrics - StringService overrides global so that its methods are timed
rules.intercept(GrpcMetrics.timed()).intercept("Upper", GrpcMetrics.histogram());
}).build();
GrpcServer grpcServer = GrpcServer.create(serverConfig, grpcRouting);
// Try to start the server. If successful, print some info and arrange to
// print a message at shutdown. If unsuccessful, print the exception.
grpcServer.start().thenAccept(s -> {
System.out.println("gRPC server is UP! http://localhost:" + s.port());
s.whenShutdown().thenRun(() -> System.out.println("gRPC server is DOWN. Good bye!"));
}).exceptionally(t -> {
System.err.println("Startup failed: " + t.getMessage());
t.printStackTrace(System.err);
return null;
});
// start web server with the metrics endpoints
Routing routing = Routing.builder().register(MetricsSupport.create()).build();
WebServer.create(routing, config.get("webserver")).start().thenAccept(s -> {
System.out.println("HTTP server is UP! http://localhost:" + s.port());
s.whenShutdown().thenRun(() -> System.out.println("HTTP server is DOWN. Good bye!"));
}).exceptionally(t -> {
System.err.println("Startup failed: " + t.getMessage());
t.printStackTrace(System.err);
return null;
});
}
Aggregations