Search in sources :

Example 1 with HttpConversationContext

use of org.jboss.weld.context.http.HttpConversationContext in project core by weld.

the class WeldWebModule method postContextRegistration.

@Override
public void postContextRegistration(PostContextRegistrationContext ctx) {
    final BeanIdentifierIndex index = ctx.getServices().get(BeanIdentifierIndex.class);
    final String contextId = ctx.getContextId();
    if (Reflections.isClassLoadable(ServletApiAbstraction.SERVLET_CONTEXT_CLASS_NAME, WeldClassLoaderResourceLoader.INSTANCE)) {
        // Register the Http contexts if not in
        Set<Annotation> httpQualifiers = ImmutableSet.<Annotation>builder().addAll(Bindings.DEFAULT_QUALIFIERS).add(HttpLiteral.INSTANCE).build();
        ctx.addContext(new ContextHolder<HttpSessionContext>(new HttpSessionContextImpl(contextId, index), HttpSessionContext.class, httpQualifiers));
        ctx.addContext(new ContextHolder<HttpSessionDestructionContext>(new HttpSessionDestructionContext(contextId, index), HttpSessionDestructionContext.class, httpQualifiers));
        ctx.addContext(new ContextHolder<HttpConversationContext>(new LazyHttpConversationContextImpl(contextId, ctx.getServices()), HttpConversationContext.class, httpQualifiers));
        ctx.addContext(new ContextHolder<HttpRequestContext>(new HttpRequestContextImpl(contextId), HttpRequestContext.class, httpQualifiers));
    }
}
Also used : HttpSessionDestructionContext(org.jboss.weld.module.web.context.http.HttpSessionDestructionContext) LazyHttpConversationContextImpl(org.jboss.weld.module.web.context.http.LazyHttpConversationContextImpl) Annotation(java.lang.annotation.Annotation) BeanIdentifierIndex(org.jboss.weld.serialization.BeanIdentifierIndex) HttpSessionContextImpl(org.jboss.weld.module.web.context.http.HttpSessionContextImpl) HttpSessionContext(org.jboss.weld.context.http.HttpSessionContext) HttpRequestContext(org.jboss.weld.context.http.HttpRequestContext) HttpRequestContextImpl(org.jboss.weld.module.web.context.http.HttpRequestContextImpl) HttpConversationContext(org.jboss.weld.context.http.HttpConversationContext)

Example 2 with HttpConversationContext

use of org.jboss.weld.context.http.HttpConversationContext in project core by weld.

the class ConversationContextActivator method deactivateConversationContext.

protected void deactivateConversationContext(HttpServletRequest request) {
    try {
        ConversationContext conversationContext = httpConversationContext();
        if (conversationContext.isActive()) {
            // Only deactivate the context if one is already active, otherwise we get Exceptions
            if (conversationContext instanceof LazyHttpConversationContextImpl) {
                LazyHttpConversationContextImpl lazyConversationContext = (LazyHttpConversationContextImpl) conversationContext;
                if (!lazyConversationContext.isInitialized()) {
                    // if this lazy conversation has not been touched yet, just deactivate it
                    lazyConversationContext.deactivate();
                    processDestructionQueue(request);
                    return;
                }
            }
            boolean isTransient = conversationContext.getCurrentConversation().isTransient();
            if (ConversationLogger.LOG.isTraceEnabled()) {
                if (isTransient) {
                    ConversationLogger.LOG.cleaningUpTransientConversation();
                } else {
                    ConversationLogger.LOG.cleaningUpConversation(conversationContext.getCurrentConversation().getId());
                }
            }
            if (isTransient) {
                conversationBeforeDestroyedEvent.fire(request);
            }
            conversationContext.invalidate();
            conversationContext.deactivate();
            if (isTransient) {
                conversationDestroyedEvent.fire(request);
            }
            processDestructionQueue(request);
        }
    } catch (Exception e) {
        ServletLogger.LOG.unableToDeactivateContext(httpConversationContext(), request);
        ServletLogger.LOG.catchingDebug(e);
    }
}
Also used : LazyHttpConversationContextImpl(org.jboss.weld.module.web.context.http.LazyHttpConversationContextImpl) HttpConversationContext(org.jboss.weld.context.http.HttpConversationContext) ConversationContext(org.jboss.weld.context.ConversationContext) AbstractConversationContext(org.jboss.weld.contexts.AbstractConversationContext)

Example 3 with HttpConversationContext

use of org.jboss.weld.context.http.HttpConversationContext in project core by weld.

the class ConversationContextActivator method sessionCreated.

public void sessionCreated(HttpSession session) {
    HttpConversationContext httpConversationContext = httpConversationContext();
    if (httpConversationContext instanceof AbstractConversationContext) {
        AbstractConversationContext<?, ?> abstractConversationContext = (AbstractConversationContext<?, ?>) httpConversationContext;
        abstractConversationContext.sessionCreated();
    }
}
Also used : AbstractConversationContext(org.jboss.weld.contexts.AbstractConversationContext) HttpConversationContext(org.jboss.weld.context.http.HttpConversationContext)

Example 4 with HttpConversationContext

use of org.jboss.weld.context.http.HttpConversationContext in project core by weld.

the class ConversationContextActivator method activateConversationContext.

// Conversation handling
protected void activateConversationContext(HttpServletRequest request) {
    HttpConversationContext conversationContext = httpConversationContext();
    /*
         * Don't try to reactivate the ConversationContext if we have already activated it for this request WELD-877
         */
    if (!isContextActivatedInRequest(request)) {
        setContextActivatedInRequest(request);
        activate(conversationContext, request);
    } else {
        /*
             * We may have previously been associated with a ConversationContext, but the reference to that context may have been lost during a Servlet forward
             * WELD-877
             */
        conversationContext.dissociate(request);
        conversationContext.associate(request);
        activate(conversationContext, request);
    }
}
Also used : HttpConversationContext(org.jboss.weld.context.http.HttpConversationContext)

Example 5 with HttpConversationContext

use of org.jboss.weld.context.http.HttpConversationContext in project core by weld.

the class HttpSessionContextImpl method destroy.

public boolean destroy(HttpSession session) {
    final BoundBeanStore beanStore = getBeanStore();
    if (beanStore == null) {
        try {
            HttpConversationContext conversationContext = getConversationContext();
            setBeanStore(new EagerSessionBeanStore(namingScheme, session));
            activate();
            invalidate();
            conversationContext.destroy(session);
            deactivate();
            setBeanStore(null);
            return true;
        } finally {
            cleanup();
        }
    } else {
        // We are in a request, invalidate it
        invalidate();
        if (beanStore instanceof AttributeBeanStore) {
            AttributeBeanStore attributeBeanStore = ((AttributeBeanStore) beanStore);
            if (attributeBeanStore.isAttributeLazyFetchingEnabled()) {
                // At this moment we have to sync the local bean store and the backing store
                attributeBeanStore.fetchUninitializedAttributes();
            }
        }
        getConversationContext().destroy(session);
        return false;
    }
}
Also used : AttributeBeanStore(org.jboss.weld.contexts.beanstore.AttributeBeanStore) BoundBeanStore(org.jboss.weld.contexts.beanstore.BoundBeanStore) HttpConversationContext(org.jboss.weld.context.http.HttpConversationContext) EagerSessionBeanStore(org.jboss.weld.module.web.context.beanstore.http.EagerSessionBeanStore)

Aggregations

HttpConversationContext (org.jboss.weld.context.http.HttpConversationContext)5 AbstractConversationContext (org.jboss.weld.contexts.AbstractConversationContext)2 LazyHttpConversationContextImpl (org.jboss.weld.module.web.context.http.LazyHttpConversationContextImpl)2 Annotation (java.lang.annotation.Annotation)1 ConversationContext (org.jboss.weld.context.ConversationContext)1 HttpRequestContext (org.jboss.weld.context.http.HttpRequestContext)1 HttpSessionContext (org.jboss.weld.context.http.HttpSessionContext)1 AttributeBeanStore (org.jboss.weld.contexts.beanstore.AttributeBeanStore)1 BoundBeanStore (org.jboss.weld.contexts.beanstore.BoundBeanStore)1 EagerSessionBeanStore (org.jboss.weld.module.web.context.beanstore.http.EagerSessionBeanStore)1 HttpRequestContextImpl (org.jboss.weld.module.web.context.http.HttpRequestContextImpl)1 HttpSessionContextImpl (org.jboss.weld.module.web.context.http.HttpSessionContextImpl)1 HttpSessionDestructionContext (org.jboss.weld.module.web.context.http.HttpSessionDestructionContext)1 BeanIdentifierIndex (org.jboss.weld.serialization.BeanIdentifierIndex)1