1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.struts2.dispatcher;
22
23 import javax.servlet.Filter;
24 import javax.servlet.FilterConfig;
25 import javax.servlet.ServletContext;
26 import javax.servlet.ServletException;
27 import javax.servlet.http.HttpSession;
28
29 import org.apache.commons.logging.Log;
30 import org.apache.commons.logging.LogFactory;
31 import org.apache.struts2.config.ServletContextSingleton;
32
33
34 /***
35 * When running Weblogic Server 6.1, this class should be
36 * specified in web.xml instead of {@link FilterDispatcher}.
37 * <p/>
38 * This class properly handles the weblogic.jar handling
39 * of servlet filters. There is one serious incompatibility, and
40 * that is that while {@link FilterDispatcher#init(FilterConfig)}
41 * throws a {@link ServletException}, this class's method
42 * {@link #setFilterConfig(FilterConfig)} does not throw
43 * the exception. Since {@link #setFilterConfig(FilterConfig)}
44 * invokes {@link FilterDispatcher#init(FilterConfig)}, the setter
45 * must "swallow" the exception. This it does by logging the
46 * exception as an error.
47 *
48 */
49 public class FilterDispatcherCompatWeblogic61 extends FilterDispatcher {
50
51 private static Log log =
52 LogFactory.getLog(FilterDispatcherCompatWeblogic61.class);
53
54 /***
55 * dummy setter for {@link #filterConfig}; this method
56 * sets up the {@link org.apache.struts2.config.ServletContextSingleton} with
57 * the servlet context from the filter configuration.
58 * <p/>
59 * This is needed by Weblogic Server 6.1 because it
60 * uses a slightly obsolete Servlet 2.3-minus spec
61 * whose {@link Filter} interface requires this method.
62 * <p/>
63 *
64 * @param filterConfig the filter configuration.
65 */
66 public void setFilterConfig(FilterConfig filterConfig) {
67 try {
68 init(filterConfig);
69 } catch (ServletException se) {
70 log.error("Couldn't set the filter configuration in this filter", se);
71 }
72
73 ServletContextSingleton singleton = ServletContextSingleton.getInstance();
74 singleton.setServletContext(filterConfig.getServletContext());
75 }
76
77 /***
78 * answers the servlet context.
79 * <p/>
80 * Servlet 2.3 specifies that this can be retrieved from
81 * the session. Unfortunately, weblogic.jar can only retrieve
82 * the servlet context from the filter config. Hence, this
83 * returns the servlet context from the singleton that was
84 * setup by {@link #setFilterConfig(FilterConfig)}.
85 *
86 * @param session the HTTP session. Not used
87 * @return the servlet context.
88 */
89 protected ServletContext getServletContext(HttpSession session) {
90 ServletContextSingleton singleton =
91 ServletContextSingleton.getInstance();
92 return singleton.getServletContext();
93 }
94
95 /***
96 * This method is required by Weblogic 6.1 SP4 because
97 * they defined this as a required method just before
98 * the Servlet 2.3 specification was finalized.
99 *
100 * @return the filter's filter configuration
101 */
102 public FilterConfig getFilterConfig() {
103 return super.getFilterConfig();
104 }
105 }