Home » apache-openwebbeans-1.0.0-incubating-M3-sources » org.apache.webbeans.jsf » [javadoc | source]

    1   /*
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements. See the NOTICE file distributed with this
    4    * work for additional information regarding copyright ownership. The ASF
    5    * licenses this file to You under the Apache License, Version 2.0 (the
    6    * "License"); you may not use this file except in compliance with the License.
    7    * You may obtain a copy of the License at
    8    * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
    9    * or agreed to in writing, software distributed under the License is
   10    * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
   11    * KIND, either express or implied. See the License for the specific language
   12    * governing permissions and limitations under the License.
   13    */
   14   package org.apache.webbeans.jsf;
   15   
   16   import java.io.IOException;
   17   
   18   import javax.enterprise.context.Conversation;
   19   import javax.enterprise.inject.spi.Bean;
   20   import javax.servlet.Filter;
   21   import javax.servlet.FilterChain;
   22   import javax.servlet.FilterConfig;
   23   import javax.servlet.ServletException;
   24   import javax.servlet.ServletRequest;
   25   import javax.servlet.ServletResponse;
   26   import javax.servlet.http.HttpServletResponse;
   27   import javax.servlet.http.HttpServletResponseWrapper;
   28   
   29   import org.apache.webbeans.annotation.CurrentLiteral;
   30   import org.apache.webbeans.container.BeanManagerImpl;
   31   import org.apache.webbeans.util.JSFUtil;
   32   
   33   public class WebBeansJSFFilter implements Filter
   34   {
   35   
   36       public void destroy()
   37       {
   38   
   39       }
   40   
   41       public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException
   42       {
   43           HttpServletResponse servletResponse = (HttpServletResponse) response;
   44           HttpServletResponseWrapper responseWrapper = new HttpServletResponseWrapper(servletResponse)
   45           {
   46   
   47               /*
   48                * (non-Javadoc)
   49                * @see
   50                * javax.servlet.http.HttpServletResponseWrapper#sendRedirect(java
   51                * .lang.String)
   52                */
   53               @Override
   54               public void sendRedirect(String location) throws IOException
   55               {
   56                   Bean<?> bean = BeanManagerImpl.getManager().resolveByType(Conversation.class, new CurrentLiteral()).iterator().next();
   57                   Conversation conversation = (Conversation)BeanManagerImpl.getManager().getInstance(bean);
   58   
   59                   String path = location;
   60   
   61                   if (conversation != null)
   62                   {
   63   
   64                       if (conversation.isLongRunning())
   65                       {
   66                           // Find JSFish view od of the redirection
   67                           path = JSFUtil.getRedirectViewId(location);
   68                           path = JSFUtil.getViewHandler().getActionURL(JSFUtil.getCurrentFacesContext(), path);
   69                           path = JSFUtil.getExternalContext().encodeActionURL(path + "?cid=" + conversation.getId());
   70                       }
   71                   }
   72   
   73                   super.sendRedirect(path);
   74   
   75               }
   76   
   77           };
   78   
   79           chain.doFilter(request, responseWrapper);
   80       }
   81   
   82       public void init(FilterConfig config) throws ServletException
   83       {
   84   
   85       }
   86   
   87   }

Home » apache-openwebbeans-1.0.0-incubating-M3-sources » org.apache.webbeans.jsf » [javadoc | source]