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 * @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 }