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