View Javadoc

    1   /*
    2    * Licensed to the Apache Software Foundation (ASF) under one
    3    * or more contributor license agreements.  See the NOTICE file
    4    * distributed with this work for additional information
    5    * regarding copyright ownership.  The ASF licenses this file
    6    * to you under the Apache License, Version 2.0 (the
    7    * "License"); you may not use this file except in compliance
    8    * with the License.  You may obtain a copy of the License at
    9    *
    10   *   http://www.apache.org/licenses/LICENSE-2.0
    11   *
    12   * Unless required by applicable law or agreed to in writing,
    13   * software distributed under the License is distributed on an
    14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    15   * KIND, either express or implied.  See the License for the
    16   * specific language governing permissions and limitations
    17   * under the License.
    18   */
    19
    20  package org.apache.myfaces.orchestra.filter;
    21
    22  import java.io.IOException;
    23
    24  import javax.servlet.Filter;
    25  import javax.servlet.FilterChain;
    26  import javax.servlet.FilterConfig;
    27  import javax.servlet.ServletException;
    28  import javax.servlet.ServletRequest;
    29  import javax.servlet.ServletResponse;
    30
    31  import org.apache.myfaces.orchestra.CoreConfig;
    32
    33  /**
    34   * Perform a number of useful per-request tasks.
    35   * <p>
    36   * This filter has been deprecated. The configuration settings it supports are
    37   * still implemented; however web.xml files defining this filter should instead
    38   * simply define context params using the corresponding constants from class
    39   * org.apache.myfaces.orchestra.CoreConfig instead.
    40   * <p>
    41   * <h2>Request Serialization</h2>
    42   * Request serialization functionality can be enabled or disabled via a filter init
    43   * parameter; setting "serializeRequests" to "false" disables this feature. Default
    44   * value: true (enabled).
    45   * <p>
    46   * See {@link org.apache.myfaces.orchestra.CoreConfig#SERIALIZE_REQUESTS} for further details.
    47   * <p>
    48   * <h2>JDBC Connection Management</h2>
    49   * This servlet always enables connection management; see
    50   * {@link org.apache.myfaces.orchestra.CoreConfig#CLEANUP_CONNECTIONS}
    51   * for further details.
    52   */
    53
    54  public class OrchestraServletFilter implements Filter
    55  {
    56      /**
    57       * This filter init property can be set to "true" or "false". Default: "true".
    58       */
    59      public final static String SERIALIZE_REQUESTS = "serializeRequests"; // NON-NLS
    60
    61      private boolean serializeRequests = true;
    62
    63      public void init(FilterConfig filterConfig) throws ServletException
    64      {
    65          String value = filterConfig.getInitParameter(SERIALIZE_REQUESTS);
    66          if ("false".equals(value)) // NON-NLS
    67          {
    68              serializeRequests = false;
    69          }
    70      }
    71
    72      public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse,
    73        final FilterChain filterChain) throws IOException, ServletException
    74      {
    75          // Copy the setting over to where the ContextLockRequestHandler class can see it.
    76          servletRequest.setAttribute(CoreConfig.SERIALIZE_REQUESTS, Boolean.valueOf(serializeRequests));
    77          filterChain.doFilter(servletRequest, servletResponse);
    78      }
    79
    80      public void destroy()
    81      {
    82      }
    83  }