Search in sources :

Example 1 with BoundRequestContext

use of org.jboss.weld.context.bound.BoundRequestContext in project wildfly by wildfly.

the class WeldContextSetup method setup.

@SuppressWarnings("unchecked")
public void setup(Map<String, Object> properties) {
    try {
        final BeanManager manager = (BeanManager) new InitialContext().lookup(STANDARD_BEAN_MANAGER_JNDI_NAME);
        if (manager != null && Container.available()) {
            final Bean<BoundSessionContext> sessionContextBean = (Bean<BoundSessionContext>) manager.resolve(manager.getBeans(BoundSessionContext.class, BoundLiteral.INSTANCE));
            CreationalContext<?> ctx = manager.createCreationalContext(sessionContextBean);
            final BoundSessionContext sessionContext = (BoundSessionContext) manager.getReference(sessionContextBean, BoundSessionContext.class, ctx);
            sessionContext.associate(sessionContexts.get());
            sessionContext.activate();
            final Bean<BoundRequestContext> requestContextBean = (Bean<BoundRequestContext>) manager.resolve(manager.getBeans(BoundRequestContext.class, BoundLiteral.INSTANCE));
            ctx = manager.createCreationalContext(requestContextBean);
            final BoundRequestContext requestContext = (BoundRequestContext) manager.getReference(requestContextBean, BoundRequestContext.class, ctx);
            requestContext.associate(requestContexts.get());
            requestContext.activate();
            final Bean<BoundConversationContext> conversationContextBean = (Bean<BoundConversationContext>) manager.resolve(manager.getBeans(BoundConversationContext.class, BoundLiteral.INSTANCE));
            ctx = manager.createCreationalContext(conversationContextBean);
            final BoundConversationContext conversationContext = (BoundConversationContext) manager.getReference(conversationContextBean, BoundConversationContext.class, ctx);
            BoundRequest request = new MutableBoundRequest(requestContexts.get(), sessionContexts.get());
            boundRequests.set(request);
            conversationContext.associate(request);
            conversationContext.activate();
        }
    } catch (NamingException e) {
        WeldLogger.ROOT_LOGGER.failedToSetupWeldContexts(e);
    }
}
Also used : MutableBoundRequest(org.jboss.weld.context.bound.MutableBoundRequest) BoundSessionContext(org.jboss.weld.context.bound.BoundSessionContext) BoundConversationContext(org.jboss.weld.context.bound.BoundConversationContext) InitialContext(javax.naming.InitialContext) Bean(javax.enterprise.inject.spi.Bean) BoundRequestContext(org.jboss.weld.context.bound.BoundRequestContext) BoundRequest(org.jboss.weld.context.bound.BoundRequest) MutableBoundRequest(org.jboss.weld.context.bound.MutableBoundRequest) NamingException(javax.naming.NamingException) BeanManager(javax.enterprise.inject.spi.BeanManager)

Example 2 with BoundRequestContext

use of org.jboss.weld.context.bound.BoundRequestContext in project indy by Commonjava.

the class RequestScopeListener method requestInitialized.

@Override
public void requestInitialized(final ServletRequestEvent evt) {
    final BoundRequestContext ctx = CDI.current().select(BoundRequestContext.class).get();
    final Map<String, Object> instanceMap = new HashMap<>();
    final ServletRequest req = evt.getServletRequest();
    req.setAttribute(CDI_CONTEXT, ctx);
    req.setAttribute(CDI_INSTANCE_MAP, instanceMap);
    ctx.associate(instanceMap);
    ctx.activate();
}
Also used : BoundRequestContext(org.jboss.weld.context.bound.BoundRequestContext) ServletRequest(javax.servlet.ServletRequest) HashMap(java.util.HashMap)

Example 3 with BoundRequestContext

use of org.jboss.weld.context.bound.BoundRequestContext in project indy by Commonjava.

the class RequestScopeListener method requestDestroyed.

@Override
public void requestDestroyed(final ServletRequestEvent evt) {
    final ServletRequest req = evt.getServletRequest();
    @SuppressWarnings("unchecked") final Map<String, Object> instanceMap = (Map<String, Object>) req.getAttribute(CDI_INSTANCE_MAP);
    final BoundRequestContext ctx = (BoundRequestContext) req.getAttribute(CDI_CONTEXT);
    ctx.invalidate();
    ctx.deactivate();
    ctx.dissociate(instanceMap);
    req.removeAttribute(CDI_CONTEXT);
    req.removeAttribute(CDI_INSTANCE_MAP);
}
Also used : ServletRequest(javax.servlet.ServletRequest) BoundRequestContext(org.jboss.weld.context.bound.BoundRequestContext) Map(java.util.Map) HashMap(java.util.HashMap)

Example 4 with BoundRequestContext

use of org.jboss.weld.context.bound.BoundRequestContext in project Payara by payara.

the class JavaEEContextUtilImpl method pushRequestContext.

/**
 * pushes invocation context onto the stack
 * Also creates Request scope
 *
 * @return new context that was created
 */
@Override
public Context pushRequestContext() {
    Context rootCtx = pushContext();
    BoundRequestContext brc = CDI.current().select(BoundRequestContext.class).get();
    ContextImpl.RequestContext context = new ContextImpl.RequestContext(rootCtx, brc.isActive() ? null : brc, new HashMap<String, Object>());
    if (context.ctx != null) {
        context.ctx.associate(context.storage);
        context.ctx.activate();
    }
    return context;
}
Also used : BoundRequestContext(org.jboss.weld.context.bound.BoundRequestContext) ServerContext(org.glassfish.internal.api.ServerContext) BoundRequestContext(org.jboss.weld.context.bound.BoundRequestContext) BoundRequestContext(org.jboss.weld.context.bound.BoundRequestContext)

Example 5 with BoundRequestContext

use of org.jboss.weld.context.bound.BoundRequestContext in project wildfly by wildfly.

the class WeldContextSetup method teardown.

@SuppressWarnings("unchecked")
public void teardown(Map<String, Object> properties) {
    try {
        final BeanManager manager = (BeanManager) new InitialContext().lookup("java:comp/BeanManager");
        if (manager != null && Container.available()) {
            final Bean<BoundSessionContext> sessionContextBean = (Bean<BoundSessionContext>) manager.resolve(manager.getBeans(BoundSessionContext.class, BoundLiteral.INSTANCE));
            CreationalContext<?> ctx = manager.createCreationalContext(sessionContextBean);
            final BoundSessionContext sessionContext = (BoundSessionContext) manager.getReference(sessionContextBean, BoundSessionContext.class, ctx);
            sessionContext.invalidate();
            sessionContext.deactivate();
            sessionContext.dissociate(sessionContexts.get());
            final Bean<BoundRequestContext> requestContextBean = (Bean<BoundRequestContext>) manager.resolve(manager.getBeans(BoundRequestContext.class, BoundLiteral.INSTANCE));
            ctx = manager.createCreationalContext(requestContextBean);
            final BoundRequestContext requestContext = (BoundRequestContext) manager.getReference(requestContextBean, BoundRequestContext.class, ctx);
            requestContext.invalidate();
            requestContext.deactivate();
            requestContext.dissociate(requestContexts.get());
            final Bean<BoundConversationContext> conversationContextBean = (Bean<BoundConversationContext>) manager.resolve(manager.getBeans(BoundConversationContext.class, BoundLiteral.INSTANCE));
            ctx = manager.createCreationalContext(conversationContextBean);
            final BoundConversationContext conversationContext = (BoundConversationContext) manager.getReference(conversationContextBean, BoundConversationContext.class, ctx);
            conversationContext.invalidate();
            conversationContext.deactivate();
            conversationContext.dissociate(boundRequests.get());
        }
    } catch (NamingException e) {
        WeldLogger.ROOT_LOGGER.failedToTearDownWeldContexts(e);
    } finally {
        sessionContexts.remove();
        requestContexts.remove();
        boundRequests.remove();
    }
}
Also used : BoundRequestContext(org.jboss.weld.context.bound.BoundRequestContext) BoundSessionContext(org.jboss.weld.context.bound.BoundSessionContext) BoundConversationContext(org.jboss.weld.context.bound.BoundConversationContext) NamingException(javax.naming.NamingException) BeanManager(javax.enterprise.inject.spi.BeanManager) InitialContext(javax.naming.InitialContext) Bean(javax.enterprise.inject.spi.Bean)

Aggregations

BoundRequestContext (org.jboss.weld.context.bound.BoundRequestContext)5 HashMap (java.util.HashMap)2 Bean (javax.enterprise.inject.spi.Bean)2 BeanManager (javax.enterprise.inject.spi.BeanManager)2 InitialContext (javax.naming.InitialContext)2 NamingException (javax.naming.NamingException)2 ServletRequest (javax.servlet.ServletRequest)2 BoundConversationContext (org.jboss.weld.context.bound.BoundConversationContext)2 BoundSessionContext (org.jboss.weld.context.bound.BoundSessionContext)2 Map (java.util.Map)1 ServerContext (org.glassfish.internal.api.ServerContext)1 BoundRequest (org.jboss.weld.context.bound.BoundRequest)1 MutableBoundRequest (org.jboss.weld.context.bound.MutableBoundRequest)1