View Javadoc

    1   /*
    2    * $Id: FilterDispatcherCompatWeblogic61.java 476075 2006-11-17 08:28:30Z mrdon $
    3    *
    4    * Licensed to the Apache Software Foundation (ASF) under one
    5    * or more contributor license agreements.  See the NOTICE file
    6    * distributed with this work for additional information
    7    * regarding copyright ownership.  The ASF licenses this file
    8    * to you under the Apache License, Version 2.0 (the
    9    * "License"); you may not use this file except in compliance
    10   * with the License.  You may obtain a copy of the License at
    11   *
    12   *  http://www.apache.org/licenses/LICENSE-2.0
    13   *
    14   * Unless required by applicable law or agreed to in writing,
    15   * software distributed under the License is distributed on an
    16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    17   * KIND, either express or implied.  See the License for the
    18   * specific language governing permissions and limitations
    19   * under the License.
    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 }