Search in sources :

Example 11 with Context

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));
    }
}
Also used : WebBeansContext(org.apache.webbeans.config.WebBeansContext) BeanContext(org.apache.openejb.BeanContext) Context(javax.enterprise.context.spi.Context) ThreadContext(org.apache.openejb.core.ThreadContext) BeanContext(org.apache.openejb.BeanContext) ContextsService(org.apache.webbeans.spi.ContextsService) WebBeansContext(org.apache.webbeans.config.WebBeansContext)

Example 12 with Context

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);
}
Also used : Context(javax.enterprise.context.spi.Context) CreationalContext(javax.enterprise.context.spi.CreationalContext) Test(org.junit.Test)

Example 13 with Context

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));
}
Also used : WebBeansContext(org.apache.webbeans.config.WebBeansContext) Context(javax.enterprise.context.spi.Context) SessionScoped(javax.enterprise.context.SessionScoped) ContextsService(org.apache.webbeans.spi.ContextsService) RequestScoped(javax.enterprise.context.RequestScoped) ApplicationComposers(org.apache.openejb.testing.ApplicationComposers) Test(org.junit.Test)

Example 14 with Context

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);
    }
}
Also used : Context(javax.enterprise.context.spi.Context) RequestScoped(javax.enterprise.context.RequestScoped)

Example 15 with Context

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);
}
Also used : Context(javax.enterprise.context.spi.Context)

Aggregations

Context (javax.enterprise.context.spi.Context)20 CreationalContext (javax.enterprise.context.spi.CreationalContext)8 WebBeansContext (org.apache.webbeans.config.WebBeansContext)4 Test (org.junit.Test)4 Annotation (java.lang.annotation.Annotation)3 ContextNotActiveException (javax.enterprise.context.ContextNotActiveException)3 WeldCreationalContext (org.jboss.weld.contexts.WeldCreationalContext)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Dependent (javax.enterprise.context.Dependent)2 RequestScoped (javax.enterprise.context.RequestScoped)2 AlterableContext (javax.enterprise.context.spi.AlterableContext)2 InvocationContext (javax.interceptor.InvocationContext)2 BeanContext (org.apache.openejb.BeanContext)2 ContextsService (org.apache.webbeans.spi.ContextsService)2 ProxyObject (org.jboss.weld.bean.proxy.ProxyObject)2 JoynrJeeMessageScoped (io.joynr.jeeintegration.api.JoynrJeeMessageScoped)1 JoynrJeeMessageContext (io.joynr.jeeintegration.context.JoynrJeeMessageContext)1 IOException (java.io.IOException)1 InvocationHandler (java.lang.reflect.InvocationHandler)1