Search in sources :

Example 91 with Config

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

the class Server method main.

/**
 * The main program entry point.
 *
 * @param args  the program arguments
 */
public static void main(String[] args) {
    // 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();
    GrpcServer grpcServer = GrpcServer.create(serverConfig, createRouting(config));
    // 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;
    });
    // add support for standard and gRPC health checks
    HealthSupport health = HealthSupport.builder().addLiveness(HealthChecks.healthChecks()).addLiveness(grpcServer.healthChecks()).build();
    // start web server with health endpoint
    Routing routing = Routing.builder().register(health).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;
    });
}
Also used : StringService(io.helidon.grpc.examples.common.StringService) GrpcServerConfiguration(io.helidon.grpc.server.GrpcServerConfiguration) GreetServiceJava(io.helidon.grpc.examples.common.GreetServiceJava) Config(io.helidon.config.Config) WebServer(io.helidon.webserver.WebServer) GrpcServer(io.helidon.grpc.server.GrpcServer) GreetService(io.helidon.grpc.examples.common.GreetService) LogConfig(io.helidon.common.LogConfig) Routing(io.helidon.webserver.Routing) GrpcRouting(io.helidon.grpc.server.GrpcRouting) HealthSupport(io.helidon.health.HealthSupport) HealthChecks(io.helidon.health.checks.HealthChecks) GrpcServerConfiguration(io.helidon.grpc.server.GrpcServerConfiguration) Config(io.helidon.config.Config) LogConfig(io.helidon.common.LogConfig) HealthSupport(io.helidon.health.HealthSupport) Routing(io.helidon.webserver.Routing) GrpcRouting(io.helidon.grpc.server.GrpcRouting) GrpcServer(io.helidon.grpc.server.GrpcServer)

Example 92 with Config

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

the class PokemonMain method createRouting.

/**
 * Creates new {@link io.helidon.webserver.Routing}.
 *
 * @param config configuration of this server
 * @return routing configured with JSON support, a health check, and a service
 */
private static Routing createRouting(Config config) {
    Config dbConfig = config.get("db");
    // Client services are added through a service loader - see mongoDB example for explicit services
    DbClient dbClient = DbClient.builder(dbConfig).build();
    // Some relational databases do not support DML statement as ping so using query which works for all of them
    HealthSupport health = HealthSupport.builder().addLiveness(DbClientHealthCheck.create(dbClient, dbConfig.get("health-check"))).build();
    // Initialize database schema
    InitializeDb.init(dbClient);
    return Routing.builder().register(// Health at "/health"
    health).register(// Metrics at "/metrics"
    MetricsSupport.create()).register("/db", new PokemonService(dbClient)).build();
}
Also used : DbClient(io.helidon.dbclient.DbClient) Config(io.helidon.config.Config) LogConfig(io.helidon.common.LogConfig) HealthSupport(io.helidon.health.HealthSupport)

Example 93 with Config

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

the class OciObjectStorageMain method main.

/**
 * Main method.
 *
 * @param args ignored
 */
public static void main(String[] args) {
    LogConfig.configureRuntime();
    // as I cannot share my configuration of OCI, 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();
    Config ociConfig = config.get("oci");
    // this requires OCI configuration in the usual place
    // ~/.oci/config
    OciObjectStorageRx ociObjectStorage = OciObjectStorageRx.create(ociConfig);
    // the following parameters are required
    String bucketName = ociConfig.get("objectstorage").get("bucket").asString().get();
    String namespace = ociConfig.get("objectstorage").get("namespace").asString().get();
    // setup ObjectStorage health check
    HealthSupport health = HealthSupport.builder().addLiveness(OciObjectStorageHealthCheck.builder().ociObjectStorage(ociObjectStorage).addBucket(bucketName).namespace(namespace).build()).build();
    WebServer.builder().config(config.get("server")).routing(Routing.builder().register(health).register("/files", new ObjectStorageService(ociObjectStorage, bucketName))).build().start().await();
}
Also used : Config(io.helidon.config.Config) LogConfig(io.helidon.common.LogConfig) HealthSupport(io.helidon.health.HealthSupport) OciObjectStorageRx(io.helidon.integrations.oci.objectstorage.OciObjectStorageRx)

Example 94 with Config

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

the class Main method startServer.

/**
 * Start the server.
 * @return the created WebServer instance
 */
public static Single<WebServer> startServer() {
    // load logging configuration
    LogConfig.configureRuntime();
    // By default this will pick up application.yaml from the classpath
    Config config = Config.create();
    Single<WebServer> server = WebServer.builder(createRouting(config)).config(config.get("server")).addMediaSupport(JsonpSupport.create()).addMediaSupport(JsonbSupport.create()).build().start();
    server.thenAccept(ws -> {
        System.out.println("WEB server is up! http://localhost:" + ws.port() + "/api/movies");
        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;
}
Also used : Driver(org.neo4j.driver.Driver) JsonbSupport(io.helidon.media.jsonb.JsonbSupport) Config(io.helidon.config.Config) LogManager(java.util.logging.LogManager) IOException(java.io.IOException) MovieRepository(io.helidon.examples.integrations.neo4j.se.domain.MovieRepository) HealthSupport(io.helidon.health.HealthSupport) Neo4j(io.helidon.integrations.neo4j.Neo4j) JsonpSupport(io.helidon.media.jsonp.JsonpSupport) Neo4jHealthCheck(io.helidon.integrations.neo4j.health.Neo4jHealthCheck) Neo4jMetricsSupport(io.helidon.integrations.neo4j.metrics.Neo4jMetricsSupport) WebServer(io.helidon.webserver.WebServer) Single(io.helidon.common.reactive.Single) MetricsSupport(io.helidon.metrics.MetricsSupport) LogConfig(io.helidon.common.LogConfig) Routing(io.helidon.webserver.Routing) InputStream(java.io.InputStream) HealthChecks(io.helidon.health.checks.HealthChecks) WebServer(io.helidon.webserver.WebServer) Config(io.helidon.config.Config) LogConfig(io.helidon.common.LogConfig)

Example 95 with Config

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

the class OciAtpMain method main.

/**
 * Application main entry point.
 *
 * @param args command line arguments.
 */
public static void main(String[] args) {
    // load logging configuration
    LogConfig.configureRuntime();
    // By default this will pick up application.yaml from the classpath
    Config config = Config.create();
    Config ociConfig = config.get("oci");
    // this requires OCI configuration in the usual place
    // ~/.oci/config
    OciAutonomousDbRx autonomousDbRx = OciAutonomousDbRx.create(ociConfig);
    // Prepare routing for the server
    WebServer server = WebServer.builder().config(config.get("server")).routing(Routing.builder().register("/atp", new AtpService(autonomousDbRx, config))).build();
    // Start the server and print some info.
    server.start().thenAccept(ws -> {
        System.out.println("WEB server is up! http://localhost:" + ws.port() + "/");
    });
    // Server threads are not daemon. NO need to block. Just react.
    server.whenShutdown().thenRun(() -> System.out.println("WEB server is DOWN. Good bye!"));
}
Also used : WebServer(io.helidon.webserver.WebServer) Config(io.helidon.config.Config) LogConfig(io.helidon.common.LogConfig) OciAutonomousDbRx(io.helidon.integrations.oci.atp.OciAutonomousDbRx)

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