Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   * JBoss, Home of Professional Open Source
   * Copyright 2008, 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
  * 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.faces.context.FacesContext;
 import  javax.servlet.Filter;
 import  javax.servlet.FilterChain;
 import  javax.servlet.FilterConfig;
 import  javax.servlet.ServletException;
 import  javax.servlet.ServletRequest;
 import  javax.servlet.ServletResponse;
 import  javax.servlet.http.HttpServletRequest;
 import  javax.servlet.http.HttpServletResponse;
 import  javax.servlet.http.HttpServletResponseWrapper;

A Filter for handling conversation propagation over redirects.

This filter intercepts the call to HttpServletResponse.sendRedirect(String) and appends the conversation id request parameter to the URL if the conversation is long-running, but only if the request parameter is not already present.

See also WELD-1262 and JBPAPP6-1664
Nicklas Karlsson
 public class ConversationPropagationFilter implements Filter {
     private String contextId;
     public void init(FilterConfig configthrows ServletException {
          = (Stringconfig.getServletContext().getAttribute(.);
         if ( == null) {
     public void doFilter(ServletRequest request, ServletResponse response, FilterChain chainthrows IOException, ServletException {
         if (request instanceof HttpServletRequest && response instanceof HttpServletResponse) {
             response = wrapResponse((HttpServletResponse) response, ((HttpServletRequest) request).getContextPath());
     public void destroy() {
     private ServletResponse wrapResponse(HttpServletResponse responsefinal String requestPath) {
         return new HttpServletResponseWrapper(response) {
             public void sendRedirect(String paththrows IOException {
                 FacesContext context = FacesContext.getCurrentInstance();
                 if (context != null) { // this is a JSF request
                     ConversationContext conversationContext = instance().select(HttpConversationContext.class).get();
                     if (conversationContext.isActive()) {
                         Conversation conversation = conversationContext.getCurrentConversation();
                         if (!conversation.isTransient()) {
                             path = new FacesUrlTransformer(pathcontext)
                                 .appendConversationIdIfNecessary(conversationContext.getParameterName(), conversation.getId())
    private static Instance<Contextinstance(String id) {
        return Container.instance(id).deploymentManager().instance().select(Context.class);
New to GrepCode? Check out our FAQ X