1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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 */
51 public class FilterDispatcherCompatWeblogic61 extends FilterDispatcher {
52
53 private static Logger LOG = LoggerFactory.getLogger(FilterDispatcherCompatWeblogic61.class);
54
55 /***
56 * dummy setter for {@link #filterConfig}; this method
57 * sets up the {@link org.apache.struts2.config.ServletContextSingleton} with
58 * the servlet context from the filter configuration.
59 * <p/>
60 * This is needed by Weblogic Server 6.1 because it
61 * uses a slightly obsolete Servlet 2.3-minus spec
62 * whose {@link Filter} interface requires this method.
63 * <p/>
64 *
65 * @param filterConfig the filter configuration.
66 */
67 public void setFilterConfig(FilterConfig filterConfig) {
68 try {
69 init(filterConfig);
70 } catch (ServletException se) {
71 LOG.error("Couldn't set the filter configuration in this filter", se);
72 }
73
74 ServletContextSingleton singleton = ServletContextSingleton.getInstance();
75 singleton.setServletContext(filterConfig.getServletContext());
76 }
77
78 /***
79 * answers the servlet context.
80 * <p/>
81 * Servlet 2.3 specifies that this can be retrieved from
82 * the session. Unfortunately, weblogic.jar can only retrieve
83 * the servlet context from the filter config. Hence, this
84 * returns the servlet context from the singleton that was
85 * setup by {@link #setFilterConfig(FilterConfig)}.
86 *
87 * @param session the HTTP session. Not used
88 * @return the servlet context.
89 */
90 protected ServletContext getServletContext(HttpSession session) {
91 ServletContextSingleton singleton =
92 ServletContextSingleton.getInstance();
93 return singleton.getServletContext();
94 }
95
96 /***
97 * This method is required by Weblogic 6.1 SP4 because
98 * they defined this as a required method just before
99 * the Servlet 2.3 specification was finalized.
100 *
101 * @return the filter's filter configuration
102 */
103 public FilterConfig getFilterConfig() {
104 return super.getFilterConfig();
105 }
106 }