KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensymphony > webwork > dispatcher > FilterDispatcherCompatWeblogic61


1 package com.opensymphony.webwork.dispatcher;
2
3 import com.opensymphony.webwork.config.ServletContextSingleton;
4 import org.apache.commons.logging.Log;
5 import org.apache.commons.logging.LogFactory;
6
7 import javax.servlet.Filter JavaDoc;
8 import javax.servlet.FilterConfig JavaDoc;
9 import javax.servlet.ServletContext JavaDoc;
10 import javax.servlet.ServletException JavaDoc;
11 import javax.servlet.http.HttpSession JavaDoc;
12
13
14 /**
15  * When running Weblogic Server 6.1, this class should be
16  * specified in web.xml instead of {@link FilterDispatcher}.
17  * <p/>
18  * This class properly handles the weblogic.jar handling
19  * of servlet filters. There is one serious incompatibility, and
20  * that is that while {@link FilterConfig#init(FilterConfig)}
21  * throws a {@link ServletException}, this class's method
22  * {@link #setFilterConfig(FilterConfig)} does not throw
23  * the exception. Since {@link #setFilterConfig(FilterConfig)}
24  * invokes {@link FilterConfig#init(FilterConfig)}, the setter
25  * must "swallow" the exception. This it does by logging the
26  * exception as an error.
27  *
28  * @author Scott N. Smith scottnelsonsmith@yahoo.com
29  * @version $Id: FilterDispatcherCompatWeblogic61.java,v 1.2 2005/06/25 16:15:16 plightbo Exp $
30  */

31 public class FilterDispatcherCompatWeblogic61
32         extends FilterDispatcher
33         implements Filter JavaDoc {
34     /**
35      * the standard logger
36      */

37     private static Log log =
38             LogFactory.getLog(FilterDispatcherCompatWeblogic61.class);
39
40     /**
41      * dummy setter for {@link #filterConfig}; this method
42      * sets up the {@link com.opensymphony.webwork.config.ServletContextSingleton} with
43      * the servlet context from the filter configuration.
44      * <p/>
45      * This is needed by Weblogic Server 6.1 because it
46      * uses a slightly obsolete Servlet 2.3-minus spec
47      * whose {@link Filter} interface requires this method.
48      * <p/>
49      *
50      * @param filterConfig the filter configuration.
51      */

52     public void setFilterConfig(FilterConfig JavaDoc filterConfig) {
53         try {
54             init(filterConfig);
55         } catch (ServletException JavaDoc se) {
56             log.error("Couldn't set the filter configuration in this filter", se);
57         }
58
59         ServletContextSingleton singleton = ServletContextSingleton.getInstance();
60         singleton.setServletContext(filterConfig.getServletContext());
61     }
62
63     /**
64      * answers the servlet context.
65      * <p/>
66      * Servlet 2.3 specifies that this can be retrieved from
67      * the session. Unfortunately, weblogic.jar can only retrieve
68      * the servlet context from the filter config. Hence, this
69      * returns the servlet context from the singleton that was
70      * setup by {@link #setFilterConfig(FilterConfig)}.
71      *
72      * @param session the HTTP session. Not used
73      * @return the servlet context.
74      */

75     protected ServletContext JavaDoc getServletContext(HttpSession JavaDoc session) {
76         ServletContextSingleton singleton =
77                 ServletContextSingleton.getInstance();
78         return singleton.getServletContext();
79     }
80
81     /**
82      * This method is required by Weblogic 6.1 SP4 because
83      * they defined this as a required method just before
84      * the Servlet 2.3 specification was finalized.
85      *
86      * @return the filter's filter configuration
87      */

88     public FilterConfig JavaDoc getFilterConfig() {
89         return super.getFilterConfig();
90     }
91 }
92
Popular Tags