001: /*
002: * $Id: FilterDispatcherCompatWeblogic61.java 476075 2006-11-17 08:28:30Z mrdon $
003: *
004: * Licensed to the Apache Software Foundation (ASF) under one
005: * or more contributor license agreements. See the NOTICE file
006: * distributed with this work for additional information
007: * regarding copyright ownership. The ASF licenses this file
008: * to you under the Apache License, Version 2.0 (the
009: * "License"); you may not use this file except in compliance
010: * with the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing,
015: * software distributed under the License is distributed on an
016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017: * KIND, either express or implied. See the License for the
018: * specific language governing permissions and limitations
019: * under the License.
020: */
021: package org.apache.struts2.dispatcher;
022:
023: import javax.servlet.Filter;
024: import javax.servlet.FilterConfig;
025: import javax.servlet.ServletContext;
026: import javax.servlet.ServletException;
027: import javax.servlet.http.HttpSession;
028:
029: import org.apache.commons.logging.Log;
030: import org.apache.commons.logging.LogFactory;
031: import org.apache.struts2.config.ServletContextSingleton;
032:
033: /**
034: * When running Weblogic Server 6.1, this class should be
035: * specified in web.xml instead of {@link FilterDispatcher}.
036: * <p/>
037: * This class properly handles the weblogic.jar handling
038: * of servlet filters. There is one serious incompatibility, and
039: * that is that while {@link FilterDispatcher#init(FilterConfig)}
040: * throws a {@link ServletException}, this class's method
041: * {@link #setFilterConfig(FilterConfig)} does not throw
042: * the exception. Since {@link #setFilterConfig(FilterConfig)}
043: * invokes {@link FilterDispatcher#init(FilterConfig)}, the setter
044: * must "swallow" the exception. This it does by logging the
045: * exception as an error.
046: *
047: */
048: public class FilterDispatcherCompatWeblogic61 extends FilterDispatcher {
049:
050: private static Log log = LogFactory
051: .getLog(FilterDispatcherCompatWeblogic61.class);
052:
053: /**
054: * dummy setter for {@link #filterConfig}; this method
055: * sets up the {@link org.apache.struts2.config.ServletContextSingleton} with
056: * the servlet context from the filter configuration.
057: * <p/>
058: * This is needed by Weblogic Server 6.1 because it
059: * uses a slightly obsolete Servlet 2.3-minus spec
060: * whose {@link Filter} interface requires this method.
061: * <p/>
062: *
063: * @param filterConfig the filter configuration.
064: */
065: public void setFilterConfig(FilterConfig filterConfig) {
066: try {
067: init(filterConfig);
068: } catch (ServletException se) {
069: log
070: .error(
071: "Couldn't set the filter configuration in this filter",
072: se);
073: }
074:
075: ServletContextSingleton singleton = ServletContextSingleton
076: .getInstance();
077: singleton.setServletContext(filterConfig.getServletContext());
078: }
079:
080: /**
081: * answers the servlet context.
082: * <p/>
083: * Servlet 2.3 specifies that this can be retrieved from
084: * the session. Unfortunately, weblogic.jar can only retrieve
085: * the servlet context from the filter config. Hence, this
086: * returns the servlet context from the singleton that was
087: * setup by {@link #setFilterConfig(FilterConfig)}.
088: *
089: * @param session the HTTP session. Not used
090: * @return the servlet context.
091: */
092: protected ServletContext getServletContext(HttpSession session) {
093: ServletContextSingleton singleton = ServletContextSingleton
094: .getInstance();
095: return singleton.getServletContext();
096: }
097:
098: /**
099: * 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: }
|