Search in sources :

Example 1 with ServerCdiExtension

use of io.helidon.microprofile.server.ServerCdiExtension in project helidon by oracle.

the class GraphQlCdiExtension method registerWithWebServer.

void registerWithWebServer(@Observes @Priority(LIBRARY_BEFORE + 9) @Initialized(ApplicationScoped.class) Object event, BeanManager bm) {
    Config config = ConfigProvider.getConfig();
    // this works for Helidon MP config
    io.helidon.config.Config graphQlConfig = ((io.helidon.config.Config) config).get("graphql");
    InvocationHandler.Builder handlerBuilder = InvocationHandler.builder().config(graphQlConfig).schema(createSchema());
    config.getOptionalValue(ConfigKey.DEFAULT_ERROR_MESSAGE, String.class).ifPresent(handlerBuilder::defaultErrorMessage);
    config.getOptionalValue(ConfigKey.EXCEPTION_WHITE_LIST, String[].class).ifPresent(handlerBuilder::exceptionWhitelist);
    config.getOptionalValue(ConfigKey.EXCEPTION_BLACK_LIST, String[].class).ifPresent(handlerBuilder::exceptionBlacklist);
    GraphQlSupport graphQlSupport = GraphQlSupport.builder().config(graphQlConfig).invocationHandler(handlerBuilder).build();
    try {
        ServerCdiExtension server = bm.getExtension(ServerCdiExtension.class);
        Optional<String> routingNameConfig = config.getOptionalValue("graphql.routing", String.class);
        Routing.Builder routing = routingNameConfig.stream().filter(Predicate.not("@default"::equals)).map(server::serverNamedRoutingBuilder).findFirst().orElseGet(server::serverRoutingBuilder);
        graphQlSupport.update(routing);
    } catch (Throwable e) {
        LOGGER.log(Level.WARNING, "Failed to set up routing with web server, maybe server extension missing?", e);
    }
}
Also used : Config(org.eclipse.microprofile.config.Config) GraphQlSupport(io.helidon.graphql.server.GraphQlSupport) Routing(io.helidon.webserver.Routing) InvocationHandler(io.helidon.graphql.server.InvocationHandler) ServerCdiExtension(io.helidon.microprofile.server.ServerCdiExtension)

Example 2 with ServerCdiExtension

use of io.helidon.microprofile.server.ServerCdiExtension in project helidon by oracle.

the class MessagingHealthTest method setUp.

@BeforeEach
void setUp() {
    ServerCdiExtension server = CDI.current().select(ServerCdiExtension.class).get();
    client = WebClient.builder().baseUri("http://localhost:" + server.port()).addReader(JsonpSupport.reader()).build();
}
Also used : ServerCdiExtension(io.helidon.microprofile.server.ServerCdiExtension) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with ServerCdiExtension

use of io.helidon.microprofile.server.ServerCdiExtension in project helidon by oracle.

the class CoordinatorDeployer method beforeUndeploy.

public void beforeUndeploy(@Observes BeforeUnDeploy event, Container container) {
    startedFuture = new CompletableFuture<>();
    // Gracefully stop the container so coordinator gets the chance to persist lra registry
    try {
        CDI<Object> current = CDI.current();
        // Remember the ports for redeploy in TckRecoveryTests
        ServerCdiExtension serverCdiExtension = current.getBeanManager().getExtension(ServerCdiExtension.class);
        coordinatorPort.set(serverCdiExtension.port(COORDINATOR_ROUTING_NAME));
        clientPort.set(serverCdiExtension.port());
        ((SeContainer) current).close();
    } catch (Throwable t) {
        t.printStackTrace();
    }
}
Also used : SeContainer(jakarta.enterprise.inject.se.SeContainer) ServerCdiExtension(io.helidon.microprofile.server.ServerCdiExtension)

Example 4 with ServerCdiExtension

use of io.helidon.microprofile.server.ServerCdiExtension in project helidon by oracle.

the class CoordinatorDeployer method afterDeploy.

public void afterDeploy(@Observes AfterDeploy event, Container container) throws Exception {
    ServerCdiExtension serverCdiExtension = CDI.current().getBeanManager().getExtension(ServerCdiExtension.class);
    for (int i = 0; i < 50 && !serverCdiExtension.started(); i++) {
        try {
            TimeUnit.MILLISECONDS.sleep(10);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    startedFuture.complete(null);
}
Also used : ServerCdiExtension(io.helidon.microprofile.server.ServerCdiExtension)

Example 5 with ServerCdiExtension

use of io.helidon.microprofile.server.ServerCdiExtension in project helidon by oracle.

the class AbstractCDITest method stopCdiContainer.

protected static void stopCdiContainer() {
    try {
        ServerCdiExtension server = CDI.current().getBeanManager().getExtension(ServerCdiExtension.class);
        if (server.started()) {
            SeContainer container = (SeContainer) CDI.current();
            container.close();
        }
    } catch (IllegalStateException e) {
    // noop container is not running
    }
}
Also used : SeContainer(jakarta.enterprise.inject.se.SeContainer) ServerCdiExtension(io.helidon.microprofile.server.ServerCdiExtension)

Aggregations

ServerCdiExtension (io.helidon.microprofile.server.ServerCdiExtension)9 Config (io.helidon.config.Config)2 JaxRsCdiExtension (io.helidon.microprofile.server.JaxRsCdiExtension)2 SeContainer (jakarta.enterprise.inject.se.SeContainer)2 GraphQlSupport (io.helidon.graphql.server.GraphQlSupport)1 InvocationHandler (io.helidon.graphql.server.InvocationHandler)1 JaxRsApplication (io.helidon.microprofile.server.JaxRsApplication)1 Security (io.helidon.security.Security)1 SecurityFeature (io.helidon.security.integration.jersey.SecurityFeature)1 WebSecurity (io.helidon.security.integration.webserver.WebSecurity)1 Routing (io.helidon.webserver.Routing)1 WebTracingConfig (io.helidon.webserver.WebTracingConfig)1 Tracer (io.opentracing.Tracer)1 Config (org.eclipse.microprofile.config.Config)1 LoggingFeature (org.glassfish.jersey.logging.LoggingFeature)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1