Search in sources :

Example 1 with BoundBeanStore

use of org.jboss.weld.contexts.beanstore.BoundBeanStore in project core by weld.

the class HttpRequestContextImpl method associate.

public boolean associate(HttpServletRequest request) {
    // At this point the bean store should never be set - see also HttpContextLifecycle#nestedInvocationGuard
    BoundBeanStore beanStore = getBeanStore();
    if (beanStore != null) {
        ContextLogger.LOG.beanStoreLeakDuringAssociation(this.getClass().getName(), request);
        if (ContextLogger.LOG.isDebugEnabled()) {
            ContextLogger.LOG.beanStoreLeakAffectedBeanIdentifiers(this.getClass().getName(), Iterables.toMultiRowString(beanStore));
        }
    }
    // We always associate a new bean store to avoid possible leaks (security threats)
    beanStore = new RequestBeanStore(request, namingScheme);
    setBeanStore(beanStore);
    beanStore.attach();
    return true;
}
Also used : RequestBeanStore(org.jboss.weld.module.web.context.beanstore.http.RequestBeanStore) BoundBeanStore(org.jboss.weld.contexts.beanstore.BoundBeanStore)

Example 2 with BoundBeanStore

use of org.jboss.weld.contexts.beanstore.BoundBeanStore 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)

Example 3 with BoundBeanStore

use of org.jboss.weld.contexts.beanstore.BoundBeanStore in project core by weld.

the class AbstractConversationContext method destroy.

public boolean destroy(S session) {
    // the context may be active
    // if it is, we need to re-attach the bean store once the other conversations are destroyed
    final BoundBeanStore beanStore = getBeanStore();
    final boolean active = isActive();
    if (beanStore != null) {
        beanStore.detach();
    }
    try {
        Object conversationMap = getSessionAttributeFromSession(session, CONVERSATIONS_ATTRIBUTE_NAME);
        if (conversationMap instanceof Map) {
            Map<String, ManagedConversation> conversations = cast(conversationMap);
            synchronized (conversations) {
                if (!conversations.isEmpty()) {
                    // There are some conversations to destroy
                    setActive(true);
                    if (beanStore == null) {
                        // There is no request associated - destroy conversation contexts immediately
                        for (Entry<String, ManagedConversation> entry : conversations.entrySet()) {
                            destroyConversation(session, entry.getKey());
                        }
                    } else {
                        // All conversation contexts created during the current session should be destroyed after the servlet service() completes
                        // However, at that time the session will not be available - store all remaining contextual instances in the request
                        setDestructionQueue(conversations, session);
                    }
                }
            }
        }
        return true;
    } finally {
        setBeanStore(beanStore);
        setActive(active);
        if (beanStore != null) {
            beanStore.attach();
        } else if (!active) {
            removeState();
            cleanup();
        }
    }
}
Also used : ManagedConversation(org.jboss.weld.context.ManagedConversation) BoundBeanStore(org.jboss.weld.contexts.beanstore.BoundBeanStore) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

BoundBeanStore (org.jboss.weld.contexts.beanstore.BoundBeanStore)3 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ManagedConversation (org.jboss.weld.context.ManagedConversation)1 HttpConversationContext (org.jboss.weld.context.http.HttpConversationContext)1 AttributeBeanStore (org.jboss.weld.contexts.beanstore.AttributeBeanStore)1 EagerSessionBeanStore (org.jboss.weld.module.web.context.beanstore.http.EagerSessionBeanStore)1 RequestBeanStore (org.jboss.weld.module.web.context.beanstore.http.RequestBeanStore)1