Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * JBoss, Home of Professional Open Source
   * Copyright 2013, Red Hat, Inc., and individual contributors
   * by the @authors tag. See the copyright.txt in the distribution for a
   * full listing of individual contributors.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
  * http://www.apache.org/licenses/LICENSE-2.0
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 package org.jboss.weld.servlet;
 
 import  javax.servlet.http.HttpServletRequest;
 import  javax.servlet.http.HttpSession;
 
This component takes care of activation/deactivation of the conversation context for a servlet request.

Author(s):
Jozef Hartinger
Marko Luksa
See also:
ConversationFilter
org.jboss.weld.servlet.WeldInitialListener
 
 public class ConversationContextActivator {
 
     private static final String NO_CID = "nocid";
     private static final String CONVERSATION_PROPAGATION = "conversationPropagation";
     private static final String CONVERSATION_PROPAGATION_NONE = "none";
 
     private static final String CONTEXT_ACTIVATED_IN_REQUEST = ConversationContextActivator.class.getName() + "CONTEXT_ACTIVATED_IN_REQUEST";
 
     private final BeanManagerImpl beanManager;
 
     private final FastEvent<HttpServletRequest> conversationInitializedEvent;
     private final FastEvent<HttpServletRequest> conversationDestroyedEvent;
 
     private final boolean lazy;
 
     protected ConversationContextActivator(BeanManagerImpl beanManagerboolean lazy) {
         this. = beanManager;
          = FastEvent.of(HttpServletRequest.classbeanManager.);
          = FastEvent.of(HttpServletRequest.classbeanManager.);
         this. = lazy;
     }
 
         if ( == null) {
         }
         return ;
     }
 
     public void startConversationContext(HttpServletRequest request) {
         associateConversationContext(request);
         activateConversationContext(request);
     }
 
     public void stopConversationContext(HttpServletRequest request) {
         deactivateConversationContext(request);
 
     }
 
     // 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(conversationContextrequest);
         } 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(conversationContextrequest);
        }
    }
    private void activate(HttpConversationContext conversationContext, HttpServletRequest request) {
        if () {
            conversationContext.activate();
        } else {
            String cid = determineConversationId(requestconversationContext.getParameterName());
            conversationContext.activate(cid);
            if (cid == null) { // transient conversation
                .fire(request);
            }
        }
    }
    protected void associateConversationContext(HttpServletRequest request) {
        httpConversationContext().associate(request);
    }
    private void setContextActivatedInRequest(HttpServletRequest request) {
        request.setAttribute(true);
    }
    private boolean isContextActivatedInRequest(HttpServletRequest request) {
        Object result = request.getAttribute();
        if (result == null) {
            return false;
        }
        return (Booleanresult;
    }
    protected void deactivateConversationContext(HttpServletRequest request) {
        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 = (LazyHttpConversationContextImplconversationContext;
                if (!lazyConversationContext.isInitialized()) {
                    // if this lazy conversation has not been touched yet, just deactivate it
                    lazyConversationContext.deactivate();
                    return;
                }
            }
            boolean isTransient = conversationContext.getCurrentConversation().isTransient();
            if (..isTraceEnabled()) {
                if (isTransient) {
                    ..cleaningUpTransientConversation();
                } else {
                    ..cleaningUpConversation(conversationContext.getCurrentConversation().getId());
                }
            }
            conversationContext.invalidate();
            conversationContext.deactivate();
            if (isTransient) {
                .fire(request);
            }
        }
    }
    protected void disassociateConversationContext(HttpServletRequest request) {
        try {
            httpConversationContext().dissociate(request);
        } catch (Exception e) {
            ..catchingDebug(e);
        }
    }
    public void sessionCreated(HttpSession session) {
        HttpConversationContext httpConversationContext = httpConversationContext();
        if (httpConversationContext instanceof AbstractConversationContext) {
            AbstractConversationContext<?, ?> abstractConversationContext = (AbstractConversationContext<?, ?>) httpConversationContext;
            abstractConversationContext.sessionCreated();
        }
    }
    public static String determineConversationId(HttpServletRequest requestString parameterName) {
        if (request == null) {
        }
        if (request.getParameter() != null) {
            return null// ignore cid; WELD-919
        }
        if (.equals(request.getParameter())) {
            return null// conversationPropagation=none (CDI-135)
        }
        String cidName = parameterName;
        String cid = request.getParameter(cidName);
        return cid;
    }
New to GrepCode? Check out our FAQ X