use of javax.enterprise.context.spi.Context 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 javax.enterprise.context.spi.Context in project tomee by apache.
the class ApplicationScopedTest method test.
@Test
public void test() throws Exception {
final Context appContext = beanManager.getContext(ApplicationScoped.class);
final Green green = createAndMutate(appContext, Green.class);
final Blue blue = createAndMutate(appContext, Blue.class);
assertEquals(green.getMessage(), blue.getGreen().getMessage());
final BrownLocal brownLocal = createAndMutate(appContext, BrownLocal.class);
final Green green2 = brownLocal.getGreen();
green2.getMessage();
final Orange orange = createAndMutate(appContext, Orange.class);
assertNotNull(orange);
assertNotNull(orange.getBlue());
assertNotNull(orange.getBlue().getGreen());
assertNotNull(orange.getGreen());
final Green greenA = orange.getBlue().getGreen();
final Green greenB = orange.getGreen();
assertSame(greenA, greenB);
}
use of javax.enterprise.context.spi.Context 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 javax.enterprise.context.spi.Context in project tomee by apache.
the class WebBeansListenerHelper method ensureRequestScope.
public static void ensureRequestScope(final ContextsService cs, final ServletRequestListener listener) {
final Context reqCtx = cs.getCurrentContext(RequestScoped.class);
if (reqCtx == null || !cs.getCurrentContext(RequestScoped.class).isActive()) {
listener.requestInitialized(null);
FAKE_REQUEST.set(true);
}
}
use of javax.enterprise.context.spi.Context in project cxf by apache.
the class CustomScopeExtension method afterBeanDiscovery.
public void afterBeanDiscovery(@Observes AfterBeanDiscovery event, BeanManager manager) {
final Context context = new CustomContext(manager);
event.addContext(context);
}
Aggregations