View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.apache.myfaces.orchestra.frameworkAdapter.basic;
21  
22  import org.apache.commons.logging.Log;
23  import org.apache.commons.logging.LogFactory;
24  
25  import javax.servlet.Filter;
26  import javax.servlet.FilterChain;
27  import javax.servlet.FilterConfig;
28  import javax.servlet.ServletException;
29  import javax.servlet.ServletRequest;
30  import javax.servlet.ServletResponse;
31  import java.io.IOException;
32  
33  /**
34   * Configures the BasicFrameworkAdapter.
35   * <p>
36   * Orchestra accesses information about the request, response, session, etc via a
37   * FrameworkAdapter so that it can be used with multiple web tier frameworks. This
38   * class selects and configures the simplest version of this adapter, which only
39   * depends on the <i>basic</i> Servlet APIs.
40   * <p>
41   * If filter config parameter "conversationMessagerClass" is set, then this is 
42   * passed to the BasicFrameworkAdapter, meaning that this can be either a 
43   * beanname defined in the dependency-injection framework, or an absolute
44   * classname of a type implementing ConversationMessager.
45   */
46  public class BasicFrameworkAdapterFilter implements Filter
47  {
48      private final static String INIT_CONVERSATION_MESSAGER = "conversationMessagerClass";
49  
50      private final Log log = LogFactory.getLog(BasicFrameworkAdapterFilter.class);
51      private BasicFrameworkAdapter adapter;
52  
53      public void init(FilterConfig filterConfig) throws ServletException
54      {
55          String conversationMessager = filterConfig.getInitParameter(INIT_CONVERSATION_MESSAGER);
56  
57           adapter = new BasicFrameworkAdapter(filterConfig.getServletContext(), conversationMessager);
58      }
59  
60      public void doFilter(ServletRequest req, ServletResponse rsp, FilterChain filterChain) throws IOException, ServletException
61      {
62          log.debug("doFilter");
63          try
64          {
65              adapter.beginRequest(req, rsp);
66              filterChain.doFilter(req, rsp);
67          }
68          finally
69          {
70              adapter.endRequest();
71          }
72      }
73  
74      public void destroy()
75      {
76      }
77  }