View Javadoc

1   /*
2    * $Id: FilterDispatcherCompatWeblogic61.java 672473 2008-06-28 07:25:05Z mrdon $
3    *
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  package org.apache.struts2.dispatcher;
23  
24  import javax.servlet.Filter;
25  import javax.servlet.FilterConfig;
26  import javax.servlet.ServletContext;
27  import javax.servlet.ServletException;
28  import javax.servlet.http.HttpSession;
29  
30  import org.apache.struts2.config.ServletContextSingleton;
31  
32  import com.opensymphony.xwork2.util.logging.Logger;
33  import com.opensymphony.xwork2.util.logging.LoggerFactory;
34  
35  
36  /***
37   * When running Weblogic Server 6.1, this class should be
38   * specified in web.xml instead of {@link FilterDispatcher}.
39   * <p/>
40   * This class properly handles the weblogic.jar handling
41   * of servlet filters.  There is one serious incompatibility, and
42   * that is that while {@link FilterDispatcher#init(FilterConfig)}
43   * throws a {@link ServletException}, this class's method
44   * {@link #setFilterConfig(FilterConfig)} does not throw
45   * the exception.  Since {@link #setFilterConfig(FilterConfig)}
46   * invokes {@link FilterDispatcher#init(FilterConfig)}, the setter
47   * must "swallow" the exception.  This it does by logging the
48   * exception as an error.
49   *
50   * @deprecated Since Struts 2.1.3 as it probably isn't used anymore
51   *
52   */
53  public class FilterDispatcherCompatWeblogic61 extends FilterDispatcher {
54  
55      private static Logger LOG = LoggerFactory.getLogger(FilterDispatcherCompatWeblogic61.class);
56  
57      /***
58       * dummy setter for {@link #filterConfig}; this method
59       * sets up the {@link org.apache.struts2.config.ServletContextSingleton} with
60       * the servlet context from the filter configuration.
61       * <p/>
62       * This is needed by Weblogic Server 6.1 because it
63       * uses a slightly obsolete Servlet 2.3-minus spec
64       * whose {@link Filter} interface requires this method.
65       * <p/>
66       *
67       * @param filterConfig the filter configuration.
68       */
69      public void setFilterConfig(FilterConfig filterConfig) {
70          try {
71              init(filterConfig);
72          } catch (ServletException se) {
73              LOG.error("Couldn't set the filter configuration in this filter", se);
74          }
75  
76          ServletContextSingleton singleton = ServletContextSingleton.getInstance();
77          singleton.setServletContext(filterConfig.getServletContext());
78      }
79  
80      /***
81       * answers the servlet context.
82       * <p/>
83       * Servlet 2.3 specifies that this can be retrieved from
84       * the session.  Unfortunately, weblogic.jar can only retrieve
85       * the servlet context from the filter config.  Hence, this
86       * returns the servlet context from the singleton that was
87       * setup by {@link #setFilterConfig(FilterConfig)}.
88       *
89       * @param session the HTTP session.  Not used
90       * @return the servlet context.
91       */
92      protected ServletContext getServletContext(HttpSession session) {
93          ServletContextSingleton singleton =
94                  ServletContextSingleton.getInstance();
95          return singleton.getServletContext();
96      }
97  
98      /***
99       * This method is required by Weblogic 6.1 SP4 because
100      * they defined this as a required method just before
101      * the Servlet 2.3 specification was finalized.
102      *
103      * @return the filter's filter configuration
104      */
105     public FilterConfig getFilterConfig() {
106         return super.getFilterConfig();
107     }
108 }