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