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.springBasic;
21  
22  import org.apache.commons.logging.Log;
23  import org.apache.commons.logging.LogFactory;
24  import org.apache.myfaces.orchestra.frameworkAdapter.basic.BasicFrameworkAdapter;
25  import org.apache.myfaces.orchestra.frameworkAdapter.basic.BasicFrameworkAdapterFilter;
26  
27  import javax.servlet.Filter;
28  import javax.servlet.FilterChain;
29  import javax.servlet.FilterConfig;
30  import javax.servlet.ServletException;
31  import javax.servlet.ServletRequest;
32  import javax.servlet.ServletResponse;
33  import java.io.IOException;
34  
35  /**
36   * Configures the SpringBasicFrameworkAdapter.
37   * <p>
38   * Orchestra accesses information about the request, response, session, etc via a
39   * FrameworkAdapter so that it can be used with multiple web tier frameworks. This
40   * class selects and configures a version of this adapter which looks up variables
41   * via Spring.
42   * <p>
43   * If filter config parameter "conversationMessagerClass" is set, then this is
44   * passed to the SpringBasicFrameworkAdapter, meaning that this can be either a
45   * beanname defined in the dependency-injection framework, or an absolute
46   * classname of a type implementing ConversationMessager.
47   * <p>
48   * This filter access the Spring framework to lookup the bean in its
49   *  {@link org.apache.myfaces.orchestra.frameworkAdapter.FrameworkAdapter#getBean} method
50   */
51  public class SpringBasicFrameworkAdapterFilter implements Filter
52  {
53      private final static String INIT_CONVERSATION_MESSAGER = "conversationMessagerClass";
54  
55      private final Log log = LogFactory.getLog(BasicFrameworkAdapterFilter.class);
56      private BasicFrameworkAdapter adapter;
57  
58      public void init(FilterConfig filterConfig) throws ServletException
59      {
60          String conversationMessager = filterConfig.getInitParameter(INIT_CONVERSATION_MESSAGER);
61  
62           adapter = new SpringBasicFrameworkAdapter(filterConfig.getServletContext(), conversationMessager);
63      }
64  
65      public void doFilter(ServletRequest req, ServletResponse rsp, FilterChain filterChain)
66      throws IOException, ServletException
67      {
68          log.debug("doFilter");
69          try
70          {
71              adapter.beginRequest(req, rsp);
72              filterChain.doFilter(req, rsp);
73          }
74          finally
75          {
76              adapter.endRequest();
77          }
78      }
79  
80      public void destroy()
81      {
82      }
83  }