use of org.apache.meecrowave.Meecrowave in project meecrowave by apache.
the class OWBAutoSetup method onStartup.
@Override
public void onStartup(final Set<Class<?>> c, final ServletContext ctx) {
final Configuration builder = Configuration.class.cast(ctx.getAttribute("meecrowave.configuration"));
final Meecrowave instance = Meecrowave.class.cast(ctx.getAttribute("meecrowave.instance"));
if (builder.isCdiConversation()) {
try {
final Class<? extends Filter> clazz = (Class<? extends Filter>) OWBAutoSetup.class.getClassLoader().loadClass("org.apache.webbeans.web.context.WebConversationFilter");
final FilterRegistration.Dynamic filter = ctx.addFilter("owb-conversation", clazz);
filter.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), false, "/*");
} catch (final Exception e) {
// no-op
}
}
// eager boot to let injections work in listeners
final EagerBootListener bootListener = new EagerBootListener(instance);
bootListener.doContextInitialized(new ServletContextEvent(ctx));
ctx.addListener(bootListener);
}
use of org.apache.meecrowave.Meecrowave in project meecrowave by apache.
the class MeecrowaveClientLifecycleListenerTest method autoClose.
@Test
public void autoClose() throws NoSuchFieldException, IllegalAccessException {
try (final Meecrowave meecrowave = new Meecrowave(new Meecrowave.Builder().randomHttpPort().includePackages(MeecrowaveClientLifecycleListenerTest.class.getName())).bake()) {
final Field jsonbs = JohnzonCdiExtension.class.getDeclaredField("jsonbs");
jsonbs.setAccessible(true);
final BeanManager beanManager = CDI.current().getBeanManager();
final JohnzonCdiExtension extensionInstance = JohnzonCdiExtension.class.cast(beanManager.getContext(ApplicationScoped.class).get(beanManager.resolve(beanManager.getBeans(JohnzonCdiExtension.class))));
final Collection<?> o = Collection.class.cast(jsonbs.get(extensionInstance));
{
// ensure server is init whatever test suite we run in
final Client client = ClientBuilder.newClient();
get(meecrowave, client);
client.close();
}
final int origin = o.size();
final Client client = ClientBuilder.newClient();
final JsonbJaxrsProvider<?> provider = new JsonbJaxrsProvider<>();
client.register(provider);
get(meecrowave, client);
assertEquals(origin + 1, o.size());
client.close();
assertEquals(origin, o.size());
}
}
use of org.apache.meecrowave.Meecrowave in project meecrowave by apache.
the class ListeningTest method events.
@Test
public void events() {
final Listener listener;
final String base;
int count = 0;
try (final Meecrowave meecrowave = new Meecrowave(new Meecrowave.Builder().randomHttpPort().includePackages(ListeningTest.class.getName())).bake()) {
count++;
listener = CDI.current().select(Listener.class).get();
assertEquals(count, listener.getEvents().size());
base = "http://localhost:" + meecrowave.getConfiguration().getHttpPort();
assertEquals(base, listener.getEvents().iterator().next().getFirstBase());
}
count++;
assertEquals(count, listener.getEvents().size());
assertEquals(base, listener.getEvents().get(count - 1).getFirstBase());
}
use of org.apache.meecrowave.Meecrowave in project component-runtime by Talend.
the class WebServer method run.
@Override
public void run() {
final String originalCompSystProp = setSystemProperty("talend.component.server.component.coordinates", componentGav);
final String skipClasspathSystProp = setSystemProperty("component.manager.classpath.skip", "true");
final String skipCallersSystProp = setSystemProperty("component.manager.callers.skip", "true");
final AtomicReference<Meecrowave> ref = new AtomicReference<>();
try {
final CountDownLatch latch = new CountDownLatch(1);
final Cli cli = new Cli(buildArgs()) {
@Override
protected void doWait(final Meecrowave meecrowave, final CommandLine line) {
ref.set(meecrowave);
latch.countDown();
super.doWait(meecrowave, line);
}
};
new Thread(() -> {
try {
cli.run();
} catch (final RuntimeException re) {
latch.countDown();
log.error(re.getMessage());
throw re;
}
}, getClass().getName() + '_' + findPort()).start();
try {
latch.await(2, MINUTES);
} catch (final InterruptedException e) {
Thread.interrupted();
return;
}
final Scanner scanner = new Scanner(System.in);
do {
log.info("Enter 'exit' to quit");
} while (!shouldQuit(scanner.nextLine()));
} finally {
reset("talend.component.server.component.coordinates", originalCompSystProp);
reset("component.manager.classpath.skip", skipClasspathSystProp);
reset("component.manager.callers.skip", skipCallersSystProp);
ofNullable(ref.get()).ifPresent(mw -> StandardServer.class.cast(mw.getTomcat().getServer()).stopAwait());
}
}
Aggregations