use of jakarta.enterprise.inject.se.SeContainer in project helidon by oracle.
the class HelidonDeployableContainer method startServer.
void startServer(RunContext context, Path[] classPath) throws ReflectiveOperationException {
try {
Optional.of((SeContainer) CDI.current()).ifPresent(SeContainer::close);
stopAll();
} catch (IllegalStateException ignored) {
// there is no server running
}
URLClassLoader urlClassloader;
ClassLoader parent;
if (containerConfig.getUserParentClassloader()) {
urlClassloader = new URLClassLoader(toUrls(classPath));
parent = urlClassloader;
} else {
urlClassloader = new URLClassLoader(toUrls(classPath), null);
parent = Thread.currentThread().getContextClassLoader();
}
context.classLoader = new HelidonContainerClassloader(parent, urlClassloader, excludedLibrariesPattern, containerConfig.getUserParentClassloader());
context.oldClassLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(context.classLoader);
context.runnerClass = context.classLoader.loadClass("io.helidon.microprofile.arquillian.ServerRunner");
context.runner = context.runnerClass.getDeclaredConstructor().newInstance();
STOP_RUNNABLES.add(() -> {
try {
context.runnerClass.getDeclaredMethod("stop").invoke(context.runner);
} catch (ReflectiveOperationException e) {
LOGGER.log(Level.WARNING, "Can't stop embedded Helidon", e);
}
});
// Configuration needs to be explicit, as some TCK libraries contain an unfortunate
// META-INF/microprofile-config.properties (such as JWT-Auth)
ConfigBuilder builder = ConfigProviderResolver.instance().getBuilder();
// we must use the default configuration to support profiles (and test them correctly in config TCK)
// we may need to have a custom configuration for TCKs that do require workarounds
/*
Config config =
containerConfig.useBuilder(builder.withSources(findMpConfigSources(classPath)))
.addDiscoveredConverters()
// will read application.yaml
.addDiscoveredSources()
.build();
if (config.getOptionalValue("mp.config.profile", Boolean.class).orElse(false)) {
// there is a configuration profile, we must add correct sources
}
*/
Config config;
if (containerConfig.hasCustomConfig()) {
config = containerConfig.useBuilder(builder).build();
} else {
config = ConfigProvider.getConfig();
}
context.runnerClass.getDeclaredMethod("start", Config.class, Integer.TYPE).invoke(context.runner, config, containerConfig.getPort());
}
use of jakarta.enterprise.inject.se.SeContainer in project helidon by oracle.
the class HelidonContainerInitializerTest method testRestart.
@Test
void testRestart() {
// this is a reproducer for bug 1554
Config config = ConfigProviderResolver.instance().getBuilder().withSources(MpConfigSources.create(Map.of(HelidonContainerInitializer.CONFIG_ALLOW_INITIALIZER, "true"))).build();
configResolver.registerConfig((org.eclipse.microprofile.config.Config) config, cl);
// now we can start using SeContainerInitializer
SeContainer container = SeContainerInitializer.newInstance().disableDiscovery().addBeanClasses(TestBean.class).initialize();
container.close();
try {
Main.main(new String[0]);
} finally {
Main.shutdown();
}
}
use of jakarta.enterprise.inject.se.SeContainer in project helidon by oracle.
the class InvalidStateTest method assertDeploymentException.
@SuppressWarnings("unchecked")
void assertDeploymentException(Class<? extends Throwable> expected, Map<String, String> configMap, Class<?>... beans) {
Config config = ConfigProviderResolver.instance().getBuilder().withSources(MpConfigSources.create(configMap), MpConfigSources.create(Map.of("mp.initializer.allow", "true"))).build();
ConfigProviderResolver.instance().registerConfig(config, Thread.currentThread().getContextClassLoader());
SeContainerInitializer initializer = SeContainerInitializer.newInstance();
initializer.addExtensions(SchedulingCdiExtension.class);
initializer.addBeanClasses(beans);
try (SeContainer c = initializer.initialize()) {
fail("Expected " + expected.getName());
} catch (AssertionFailedError e) {
throw e;
} catch (Throwable e) {
assertEquals(expected, e.getClass());
}
}
use of jakarta.enterprise.inject.se.SeContainer in project helidon by oracle.
the class AsyncClient method main.
/**
* Program entry point.
*
* @param args the program arguments
*
* @throws Exception if an error occurs
*/
public static void main(String[] args) throws Exception {
SeContainerInitializer initializer = SeContainerInitializer.newInstance();
SeContainer container = initializer.initialize();
AsyncClient client = container.select(AsyncClient.class).get();
client.asyncUnary();
}
use of jakarta.enterprise.inject.se.SeContainer in project helidon by oracle.
the class Client method main.
/**
* Program entry point.
*
* @param args the program arguments
*
* @throws Exception if an error occurs
*/
public static void main(String[] args) throws Exception {
SeContainerInitializer initializer = SeContainerInitializer.newInstance();
SeContainer container = initializer.initialize();
Client client = container.select(Client.class).get();
client.unary();
client.serverStreaming();
client.clientStreaming();
client.bidirectional();
}
Aggregations