use of org.apache.webbeans.spi.ContextsService in project tomee by apache.
the class EnsureRequestScopeThreadLocalIsCleanUpTest method ensureRequestContextCanBeRestarted.
@Test
public void ensureRequestContextCanBeRestarted() throws Exception {
final ApplicationComposers composers = new ApplicationComposers(EnsureRequestScopeThreadLocalIsCleanUpTest.class);
composers.before(this);
final CdiAppContextsService contextsService = CdiAppContextsService.class.cast(WebBeansContext.currentInstance().getService(ContextsService.class));
final Context req1 = contextsService.getCurrentContext(RequestScoped.class);
assertNotNull(req1);
final Context session1 = contextsService.getCurrentContext(SessionScoped.class);
assertNotNull(session1);
contextsService.endContext(RequestScoped.class, null);
contextsService.startContext(RequestScoped.class, null);
final Context req2 = contextsService.getCurrentContext(RequestScoped.class);
assertNotSame(req1, req2);
final Context session2 = contextsService.getCurrentContext(SessionScoped.class);
assertSame(session1, session2);
composers.after();
assertNull(contextsService.getCurrentContext(RequestScoped.class));
assertNull(contextsService.getCurrentContext(SessionScoped.class));
}
use of org.apache.webbeans.spi.ContextsService in project tomee by apache.
the class JMS2AMQTest method cdi.
@Test
public void cdi() throws InterruptedException {
final String text = TEXT + "3";
final AtomicReference<Throwable> error = new AtomicReference<>();
final CountDownLatch ready = new CountDownLatch(1);
final CountDownLatch over = new CountDownLatch(1);
new Thread() {
{
setName(JMS2AMQTest.class.getName() + ".cdi#receiver");
}
@Override
public void run() {
final ContextsService contextsService = WebBeansContext.currentInstance().getContextsService();
// spec defines it for request scope an transaction scope
contextsService.startContext(RequestScoped.class, null);
try {
ready.countDown();
assertEquals(text, context.createConsumer(destination3).receiveBody(String.class, TimeUnit.MINUTES.toMillis(1)));
// ensure we dont do a NPE if there is nothing to read
assertNull(context.createConsumer(destination3).receiveBody(String.class, 100));
} catch (final Throwable t) {
error.set(t);
} finally {
contextsService.endContext(RequestScoped.class, null);
over.countDown();
}
}
}.start();
ready.await(1, TimeUnit.MINUTES);
// just to ensure we called receive already
sleep(150);
// now send the message
try (final JMSContext context = cf.createContext()) {
context.createProducer().send(destination3, text);
} catch (final JMSRuntimeException ex) {
fail(ex.getMessage());
}
over.await(1, TimeUnit.MINUTES);
// ensure we got the message and no exception
final Throwable exception = error.get();
if (exception != null) {
exception.printStackTrace();
}
assertNull(exception == null ? "ok" : exception.getMessage(), exception);
}
use of org.apache.webbeans.spi.ContextsService in project tomee by apache.
the class RequestScopedThreadContextListener method contextEntered.
@Override
public void contextEntered(final ThreadContext oldContext, final ThreadContext newContext) {
final BeanContext beanContext = newContext.getBeanContext();
final WebBeansContext webBeansContext = beanContext.getModuleContext().getAppContext().getWebBeansContext();
if (webBeansContext == null) {
return;
}
final ContextsService contextsService = webBeansContext.getContextsService();
final Context requestContext = CdiAppContextsService.class.cast(contextsService).getRequestContext(false);
if (requestContext == null) {
contextsService.startContext(RequestScoped.class, CdiAppContextsService.EJB_REQUEST_EVENT);
newContext.set(DestroyContext.class, new DestroyContext(contextsService, newContext));
}
}
use of org.apache.webbeans.spi.ContextsService in project deltaspike by apache.
the class OpenWebBeansContextControl method startConversationScope.
private void startConversationScope() {
ContextsService contextsService = getContextsService();
contextsService.startContext(ConversationScoped.class, null);
}
use of org.apache.webbeans.spi.ContextsService in project deltaspike by apache.
the class OpenWebBeansContextControl method startContexts.
@Override
public void startContexts() {
ContextsService contextsService = getContextsService();
startSingletonScope();
startApplicationScope();
startSessionScope();
startRequestScope();
startConversationScope();
}
Aggregations