You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by re...@apache.org on 2003/11/20 19:43:45 UTC

cvs commit: jakarta-tomcat-catalina/webapps/balancer/docs/javadoc/resources inherit.gif

remm        2003/11/20 10:43:45

  Added:       webapps/balancer/WEB-INF/classes/org/apache/webapp/balancer
                        BalancerFilter.java Rule.java RuleChain.java
                        RulesParser.java overview.html package.html
               webapps/balancer/WEB-INF/classes/org/apache/webapp/balancer/rules
                        AcceptEverythingRule.java BaseRule.java
                        CharacterEncodingRule.java RemoteAddressRule.java
                        RequestAttributeRule.java RequestHeaderRule.java
                        RequestParameterRule.java SessionAttributeRule.java
                        URLStringMatchRule.java UserRoleRule.java
                        package.html
  Removed:     webapps/balancer/docs/javadoc/resources inherit.gif
  Log:
  - Reformat webapp (part 2).
  
  Revision  Changes    Path
  1.1                  jakarta-tomcat-catalina/webapps/balancer/WEB-INF/classes/org/apache/webapp/balancer/BalancerFilter.java
  
  Index: BalancerFilter.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * Portions of this software are based upon public domain software
   * originally written at the National Center for Supercomputing Applications,
   * University of Illinois, Urbana-Champaign.
   */
  package org.apache.webapp.balancer;
  
  import java.io.IOException;
  import java.io.InputStream;
  
  import java.net.URL;
  
  import javax.servlet.Filter;
  import javax.servlet.FilterChain;
  import javax.servlet.FilterConfig;
  import javax.servlet.ServletContext;
  import javax.servlet.ServletException;
  import javax.servlet.ServletRequest;
  import javax.servlet.ServletResponse;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  
  
  /**
   * The balancer filter redirects incoming requests
   * based on what rules they match.  The rules
   * are configurable via an XML document whose URL
   * is specified as an init-param to this filter.
   *
   * @author Yoav Shapira
   */
  public class BalancerFilter implements Filter {
      /**
       * The rules this filter consults.
       */
      private RuleChain ruleChain;
  
      /**
       * The servlet context.
       */
      private ServletContext context;
  
      /**
       * Returns the rule chain.
       *
       * @return The rule chain
       */
      protected RuleChain getRuleChain() {
          return ruleChain;
      }
  
      /**
       * Initialize this filter.
       *
       * @param filterConfig The filter config
       * @throws ServletException If an error occurs
       */
      public void init(FilterConfig filterConfig) throws ServletException {
          context = filterConfig.getServletContext();
  
          String configUrlParam = filterConfig.getInitParameter("configUrl");
  
          if (configUrlParam == null) {
              throw new ServletException("configUrl is required.");
          }
  
          try {
              InputStream input = context.getResourceAsStream(configUrlParam);
              RulesParser parser = new RulesParser(input);
              ruleChain = parser.getResult();
              context.log(
                  getClass().getName() + ": init(): ruleChain: " + ruleChain);
          } catch (Exception e) {
              throw new ServletException(e);
          }
      }
  
      /**
       * Filter the incoming request.
       * Consults the rule chain to see if
       * any rules match this request, and if
       * so redirects.  Otherwise simply
       * let request through.
       *
       * @param request The request
       * @param response The response
       * @param chain The filter chain
       * @throws IOException If an error occurs
       * @throws ServletException If an error occurs
       */
      public void doFilter(
          ServletRequest request, ServletResponse response, FilterChain chain)
          throws IOException, ServletException {
          if (response.isCommitted()) {
              context.log(
                  getClass().getName()
                  + ": doFilter(): not inspecting committed response.");
              chain.doFilter(request, response);
          } else if (!(request instanceof HttpServletRequest)) {
              context.log(
                  getClass().getName()
                  + ": doFilter(): not inspecting non-Http request.");
              chain.doFilter(request, response);
          } else {
              HttpServletRequest hreq = (HttpServletRequest) request;
              HttpServletResponse hres = (HttpServletResponse) response;
  
              URL redirectUrl = getRuleChain().evaluate(hreq);
  
              if (redirectUrl != null) {
                  String encoded =
                      hres.encodeRedirectURL(redirectUrl.toString());
  
                  context.log(
                      getClass().getName()
                      + ": doFilter(): redirecting request for "
                      + hreq.getRequestURL().toString() + " to " + encoded);
  
                  hres.sendRedirect(encoded);
              } else {
                  chain.doFilter(request, response);
              }
          }
      }
  
      /**
       * Destroy this filter.
       */
      public void destroy() {
          context = null;
          ruleChain = null;
      }
  }
  
  
  // End of file: BalanceFilter.java
  
  
  
  1.1                  jakarta-tomcat-catalina/webapps/balancer/WEB-INF/classes/org/apache/webapp/balancer/Rule.java
  
  Index: Rule.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * Portions of this software are based upon public domain software
   * originally written at the National Center for Supercomputing Applications,
   * University of Illinois, Urbana-Champaign.
   */
  package org.apache.webapp.balancer;
  
  import javax.servlet.http.HttpServletRequest;
  
  
  /**
   * The Rule interface is implemented by
   * load balancing rules.
   *
   * @author Yoav Shapira
   */
  public interface Rule {
      /**
       * Determine if the given request
       * matches the rule.
       *
       * @param request The request
       * @return boolean True if matches, will be redirected.
       */
      boolean matches(HttpServletRequest request);
  
      /**
       * Returns the redirect URL for
       * requests that match this rule.
       *
       * @return The redirect URL
       */
      String getRedirectUrl();
  }
  
  
  // End of file: Rule.java
  
  
  
  1.1                  jakarta-tomcat-catalina/webapps/balancer/WEB-INF/classes/org/apache/webapp/balancer/RuleChain.java
  
  Index: RuleChain.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * Portions of this software are based upon public domain software
   * originally written at the National Center for Supercomputing Applications,
   * University of Illinois, Urbana-Champaign.
   */
  package org.apache.webapp.balancer;
  
  import java.net.URL;
  
  import java.util.ArrayList;
  import java.util.Iterator;
  import java.util.List;
  
  import javax.servlet.http.HttpServletRequest;
  
  
  /**
   * A RuleChain is a list of rules
   * considered in order.  The first
   * rule to succeed stops the evaluation
   * of rules.
   *
   * @author Yoav Shapira
   */
  public class RuleChain {
      /**
       * The list of rules to evaluate.
       */
      private List rules;
  
      /**
       * Constructor.
       */
      public RuleChain() {
          rules = new ArrayList();
      }
  
      /**
       * Returns the list of rules
       * to evaluate.
       *
       * @return List
       */
      protected List getRules() {
          return rules;
      }
  
      /**
       * Returns an iterator over
       * the list of rules to evaluate.
       *
       * @return Iterator
       */
      protected Iterator getRuleIterator() {
          return getRules().iterator();
      }
  
      /**
       * Adds a rule to evaluate.
       *
       * @param theRule The rule to add
       */
      public void addRule(Rule theRule) {
          if (theRule == null) {
              throw new IllegalArgumentException("The rule cannot be null.");
          } else {
              getRules().add(theRule);
          }
      }
  
      /**
       * Evaluates the given request to see if
       * any of the rules matches.  Returns the
       * redirect URL for the first matching
       * rule.  Returns null if no rules match
       * the request.
       *
       * @param request The request
       * @return URL The first matching rule URL
       * @see Rule#matches(HttpServletRequest)
       */
      public URL evaluate(HttpServletRequest request) {
          Iterator iter = getRuleIterator();
  
          Rule currentRule = null;
          boolean currentMatches = false;
  
          while (iter.hasNext()) {
              currentRule = (Rule) iter.next();
              currentMatches = currentRule.matches(request);
  
              if (currentMatches) {
                  try {
                      return new URL(currentRule.getRedirectUrl());
                  } catch (Exception e) {
                      throw new RuntimeException(e);
                  }
              }
          }
  
          return null;
      }
  
      /**
       * Returns a String representation of this object.
       *
       * @return String
       */
      public String toString() {
          StringBuffer buffer = new StringBuffer();
  
          buffer.append("[");
          buffer.append(getClass().getName());
          buffer.append(": ");
  
          Iterator iter = getRuleIterator();
          Rule currentRule = null;
  
          while (iter.hasNext()) {
              currentRule = (Rule) iter.next();
              buffer.append(currentRule);
  
              if (iter.hasNext()) {
                  buffer.append(", ");
              }
          }
  
          buffer.append("]");
  
          return buffer.toString();
      }
  }
  
  
  // End of file: RuleChain.java
  
  
  
  1.1                  jakarta-tomcat-catalina/webapps/balancer/WEB-INF/classes/org/apache/webapp/balancer/RulesParser.java
  
  Index: RulesParser.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * Portions of this software are based upon public domain software
   * originally written at the National Center for Supercomputing Applications,
   * University of Illinois, Urbana-Champaign.
   */
  package org.apache.webapp.balancer;
  
  import org.apache.commons.digester.Digester;
  
  import java.io.InputStream;
  
  
  /**
   * The rules parser uses Digester
   * to parse the rules definition
   * file and return a RuleChain object.
   *
   * @author Yoav Shapira
   */
  public class RulesParser {
      /**
       * The resulting rule chain.
       */
      private RuleChain result;
  
      /**
       * Constructor.
       *
       * @param input To read the configuration
       */
      public RulesParser(InputStream input) {
          try {
              Digester digester = createDigester();
              result = (RuleChain) digester.parse(input);
          } catch (Exception e) {
              throw new RuntimeException(e);
          }
      }
  
      /**
       * Returns the parsed rule chain.
       *
       * @return The resulting RuleChain
       */
      public RuleChain getResult() {
          return result;
      }
  
      /**
       * Creates the digester instance.
       *
       * @return Digester
       */
      protected Digester createDigester() {
          Digester digester = new Digester();
  
          String rules = "rules";
          String rule = "/rule";
  
          // Construct rule chain
          digester.addObjectCreate(rules, RuleChain.class);
  
          // Construct rule
          digester.addObjectCreate(rules + rule, null, "className");
  
          // Set rule properties
          digester.addSetProperties(rules + rule);
  
          // Add rule to chain
          digester.addSetNext(rules + rule, "addRule");
  
          return digester;
      }
  }
  
  
  // End of class: RulesParser.java
  
  
  
  1.1                  jakarta-tomcat-catalina/webapps/balancer/WEB-INF/classes/org/apache/webapp/balancer/overview.html
  
  Index: overview.html
  ===================================================================
  <html>
  <head>
  <title>Balancer Webapp Overview</title>
  </head>
  <body>
  The balancer webapp is an implementation of a rules-based
  load balancer.  A number of rules are provided and the
  application is written for easy extensibility.  
  
  <p>
  A servlet filter is also provided along with a sample web.xml that
  maps that filter to all requests.  This is only one way
  to use the load balancer.  The user may configure multiple
  filters each with a different rule chain mapped to 
  (possibly multiple) different url-patterns or servlets.  It
  is also possible to use rule chains within a servlet.
  </p>
  
  <p>
  Please note that although this application is being distributed
  with Tomcat, it is compliant with the Servlet Specification v2.3
  and is therefore portable across servlet containers that support
  this specification.
  </p>
  
  <p>
  The balancer webapps uses the 
  <a href="http://jakarta.apache.org/commons/digester">Digester</a> 
  tool from Jakarta Commons.  Digester and its dependencies are
  included in this distribution.
  </p>
  
  <p>
  The balancer webapp uses 
  <a href="http://jalopy.sf.net">Jalopy</a> 
  for source-code formatting and 
  <a href="http://checkstyle.sf.net">CheckStyle</a> 
  for source-code checking.
  <br/>
  The <a href="../checkStyle/checkStyleReport.html">
  CheckStyle Report</a> is available.
  </p>
  
  <p>
  Any suggestions, comments, etc, are welcome: please
  post them to the tomcat-user mailing list.  Enjoy ;)
  </p>
  
  </body>
  </html>
  
  
  1.1                  jakarta-tomcat-catalina/webapps/balancer/WEB-INF/classes/org/apache/webapp/balancer/package.html
  
  Index: package.html
  ===================================================================
  <html>
  <head>
  <title>org.apache.webapp.balancer Package Overview</title>
  </head>
  <body>
  This package contains all classes used by the balancer
  webapp other than actual rule implementations.
  <p>
  The {@link org.apache.webapp.balancer.BalancerFilter Filter} is how the webapp
  is typically used: see the web.xml file in this distribution
  for an example.
  </p>
  
  <p>
  A {@link org.apache.webapp.balancer.RuleChain} is simply a list of rules to be
  evaluated in order.
  </p>
  
  <p>
  The {@link org.apache.webapp.balancer.RulesParser} uses 
  <a href="http://jakarta.apache.org/commons/digester">Digester</a> 
  to parse the rules configuration file.
  </p>
  
  </body>
  </html>
  
  
  1.1                  jakarta-tomcat-catalina/webapps/balancer/WEB-INF/classes/org/apache/webapp/balancer/rules/AcceptEverythingRule.java
  
  Index: AcceptEverythingRule.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * Portions of this software are based upon public domain software
   * originally written at the National Center for Supercomputing Applications,
   * University of Illinois, Urbana-Champaign.
   */
  package org.apache.webapp.balancer.rules;
  
  import javax.servlet.http.HttpServletRequest;
  
  
  /**
   * This rule matches every request
   * passed to it, making it suitable
   * for use as a catch-all or last
   * rule in a chain.
   *
   * @author Yoav Shapira
   */
  public class AcceptEverythingRule extends BaseRule {
      /**
       * @see org.apache.webapp.balancer.Rule#matches(HttpServletRequest)
       *
       * This implementation always matches.
       */
      public boolean matches(HttpServletRequest request) {
          return true;
      }
  }
  
  
  // End of file: AcceptEverythingRule.java
  
  
  
  1.1                  jakarta-tomcat-catalina/webapps/balancer/WEB-INF/classes/org/apache/webapp/balancer/rules/BaseRule.java
  
  Index: BaseRule.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * Portions of this software are based upon public domain software
   * originally written at the National Center for Supercomputing Applications,
   * University of Illinois, Urbana-Champaign.
   */
  package org.apache.webapp.balancer.rules;
  
  import org.apache.webapp.balancer.Rule;
  
  import javax.servlet.http.HttpServletRequest;
  
  
  /**
   * The BaseRule is an empty rule
   * implementation which can be
   * subclassed for extension.
   *
   * @author Yoav Shapira
   */
  public abstract class BaseRule implements Rule {
      /**
       * The rule name.
       */
      private String name;
  
      /**
       * The URL where matching
       * requested will be redirected.
       */
      private String redirectUrl;
  
      /**
       * Sets the rule name.
       *
       * @param theName The rule name.
       */
      public void setName(String theName) {
          if (theName == null) {
              throw new IllegalArgumentException("The name cannot be null.");
          } else {
              name = theName;
          }
      }
  
      /**
       * Returns the rule name.
       *
       * @return String
       */
      protected String getName() {
          return name;
      }
  
      /**
       * @see Rule#getRedirectUrl
       */
      public String getRedirectUrl() {
          return redirectUrl;
      }
  
      /**
       * Sets the redirect URL.
       *
       * @param theRedirectUrl Where matching requests will be redirected
       */
      public void setRedirectUrl(String theRedirectUrl) {
          if (theRedirectUrl == null) {
              throw new IllegalArgumentException("redirectUrl may not be null.");
          } else {
              redirectUrl = theRedirectUrl;
          }
      }
  
      /**
       * @see Rule#matches(HttpServletRequest)
       */
      public abstract boolean matches(HttpServletRequest request);
  
      /**
       * Returns a String representation of this object.
       *
       * @return String
       */
      public String toString() {
          StringBuffer buffer = new StringBuffer();
  
          buffer.append("[");
          buffer.append(getClass().getName());
          buffer.append(": ");
  
          buffer.append("Redirect URL: ");
          buffer.append(getRedirectUrl());
  
          buffer.append("]");
  
          return buffer.toString();
      }
  }
  
  
  // End of file: BaseRule.java
  
  
  
  1.1                  jakarta-tomcat-catalina/webapps/balancer/WEB-INF/classes/org/apache/webapp/balancer/rules/CharacterEncodingRule.java
  
  Index: CharacterEncodingRule.java
  ===================================================================
  package org.apache.webapp.balancer.rules;
  
  import javax.servlet.http.HttpServletRequest;
  
  
  /**
   * This rule redirects requests if they
   * are for a specific character encoding.
   *
   * @author Yoav Shapira
   */
  public class CharacterEncodingRule extends BaseRule {
      /**
       * The character encoding.
       */
      private String encoding;
  
      /**
       * Sets the character encoding.
       *
       * @param theEncoding The encoding value
       */
      public void setEncoding(String theEncoding) {
          if (theEncoding == null) {
              throw new IllegalArgumentException("The encoding cannot be null.");
          } else {
              encoding = theEncoding;
          }
      }
  
      /**
       * Returns the desired encoding.
       *
       * @return String
       */
      protected String getEncoding() {
          return encoding;
      }
  
      /**
       * @see org.apache.webapp.balancer.Rule#matches(HttpServletRequest request)
       */
      public boolean matches(HttpServletRequest request) {
          String actualEncoding = request.getCharacterEncoding();
  
          return (getEncoding().compareTo(actualEncoding) == 0);
      }
  
      /**
       * Returns a String representation of this object.
       *
       * @return String
       */
      public String toString() {
          StringBuffer buffer = new StringBuffer();
  
          buffer.append("[");
          buffer.append(getClass().getName());
          buffer.append(": ");
  
          buffer.append("Target encoding: ");
          buffer.append(getEncoding());
          buffer.append(" / ");
  
          buffer.append("Redirect URL: ");
          buffer.append(getRedirectUrl());
  
          buffer.append("]");
  
          return buffer.toString();
      }
  }
  
  
  // End of file: CharacterEncodingRule.java
  
  
  
  1.1                  jakarta-tomcat-catalina/webapps/balancer/WEB-INF/classes/org/apache/webapp/balancer/rules/RemoteAddressRule.java
  
  Index: RemoteAddressRule.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * Portions of this software are based upon public domain software
   * originally written at the National Center for Supercomputing Applications,
   * University of Illinois, Urbana-Champaign.
   */
  package org.apache.webapp.balancer.rules;
  
  import javax.servlet.http.HttpServletRequest;
  
  
  /**
   * The remote access rule
   * redirects if the request came
   * from specified remote address.
   *
   * @author Yoav Shapira
   */
  public class RemoteAddressRule extends BaseRule {
      /**
       * The target remote address.
       */
      private String remoteAddress;
  
      /**
       * Sets the target remote address.
       *
       * @param theAddress The address
       */
      public void setRemoteAddress(String theAddress) {
          if (theAddress == null) {
              throw new IllegalArgumentException("The address cannot be null.");
          } else {
              remoteAddress = theAddress;
          }
      }
  
      /**
       * Returns the target remote address.
       *
       * @return String
       */
      protected String getRemoteAddress() {
          return remoteAddress;
      }
  
      /**
       * @see org.apache.webapp.balancer.Rule#matches(HttpServletRequest)
       *
       * Looks for the request's remote address.
       */
      public boolean matches(HttpServletRequest request) {
          String requestAddr = request.getRemoteAddr();
  
          return (requestAddr.compareTo(getRemoteAddress()) == 0);
      }
  
      /**
       * Returns a String representation of this object.
       *
       * @return String
       */
      public String toString() {
          StringBuffer buffer = new StringBuffer();
  
          buffer.append("[");
          buffer.append(getClass().getName());
          buffer.append(": ");
  
          buffer.append("Target remote address: ");
          buffer.append(getRemoteAddress());
          buffer.append(" / ");
  
          buffer.append("Redirect URL: ");
          buffer.append(getRedirectUrl());
  
          buffer.append("]");
  
          return buffer.toString();
      }
  }
  
  
  // End of file: RemoteAddressRule.java
  
  
  
  1.1                  jakarta-tomcat-catalina/webapps/balancer/WEB-INF/classes/org/apache/webapp/balancer/rules/RequestAttributeRule.java
  
  Index: RequestAttributeRule.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * Portions of this software are based upon public domain software
   * originally written at the National Center for Supercomputing Applications,
   * University of Illinois, Urbana-Champaign.
   */
  package org.apache.webapp.balancer.rules;
  
  import javax.servlet.http.HttpServletRequest;
  
  
  /**
   * This rule accepts or rejects requests
   * based on the presence of a attribute
   * in the request.
   *
   * @author Yoav Shapira
   */
  public class RequestAttributeRule extends BaseRule {
      /**
       * The target attribute name (attribute
       * must be present for match to succeed).
       */
      private String attributeName;
  
      /**
       * The target attribute value.  This
       * is optional: null means any attribute
       * value is OK for a match.  A non-null
       * value will be matches exactly.
       */
      private Object attributeValue;
  
      /**
       * Sets the target attribute name.
       *
       * @param theAttributeName The attribute name
       */
      public void setAttributeName(String theAttributeName) {
          if (theAttributeName == null) {
              throw new IllegalArgumentException(
                  "attributeName cannot be null.");
          } else {
              attributeName = theAttributeName;
          }
      }
  
      /**
       * Returns the target attribute name.
       *
       * @return String The target attribute name.
       */
      protected String getAttributeName() {
          return attributeName;
      }
  
      /**
       * Sets the attribute value, which may be null.
       *
       * @param theAttributeValue The attribute value
       */
      public void setAttributeValue(Object theAttributeValue) {
          attributeValue = theAttributeValue;
      }
  
      /**
       * Returns the target attribute value,
       * which may be null.
       *
       * @return Object The target attribute value
       */
      protected Object getAttributeValue() {
          return attributeValue;
      }
  
      /**
       * @see org.apache.webapp.balancer.Rule#matches(HttpServletRequest)
       */
      public boolean matches(HttpServletRequest request) {
          Object actualAttributeValue = request.getAttribute(getAttributeName());
  
          if (actualAttributeValue == null) {
              return (getAttributeValue() == null);
          } else {
              return (actualAttributeValue.equals(getAttributeValue()));
          }
      }
  
      /**
       * Returns a String representation of this object.
       *
       * @return String
       */
      public String toString() {
          StringBuffer buffer = new StringBuffer();
  
          buffer.append("[");
          buffer.append(getClass().getName());
          buffer.append(": ");
  
          buffer.append("Target attribute name: ");
          buffer.append(getAttributeName());
          buffer.append(" / ");
  
          buffer.append("Target attribute value: ");
          buffer.append(getAttributeValue());
          buffer.append(" / ");
  
          buffer.append("Redirect URL: ");
          buffer.append(getRedirectUrl());
  
          buffer.append("]");
  
          return buffer.toString();
      }
  }
  
  
  // End of file: RequestAttributeRule.java
  
  
  
  1.1                  jakarta-tomcat-catalina/webapps/balancer/WEB-INF/classes/org/apache/webapp/balancer/rules/RequestHeaderRule.java
  
  Index: RequestHeaderRule.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * Portions of this software are based upon public domain software
   * originally written at the National Center for Supercomputing Applications,
   * University of Illinois, Urbana-Champaign.
   */
  package org.apache.webapp.balancer.rules;
  
  import javax.servlet.http.HttpServletRequest;
  
  
  /**
   * This rule checks for the presence
   * of a specific request header, optionally
   * with a specific value.  The value may
   * be null.
   *
   * @author Yoav Shapira
   */
  public class RequestHeaderRule extends BaseRule {
      /**
       * The header name, cannot be null.
       */
      private String headerName;
  
      /**
       * The header value.  This may be
       * null to indicate any value is OK.
       */
      private String headerValue;
  
      /**
       * Sets the header name.
       *
       * @param theName The name
       */
      public void setHeaderName(String theName) {
          if (theName == null) {
              throw new IllegalArgumentException(
                  "The header name cannot be null.");
          } else {
              headerName = theName;
          }
      }
  
      /**
       * Returns the header name to match.
       *
       * @return The header name
       */
      protected String getHeaderName() {
          return headerName;
      }
  
      /**
       * Sets the header value.
       *
       * @param theValue The header value
       */
      public void setHeaderValue(String theValue) {
          headerValue = theValue;
      }
  
      /**
       * Returns the desired header value,
       * which may be null.
       *
       * @return String
       */
      protected String getHeaderValue() {
          return headerValue;
      }
  
      /**
       * @see org.apache.webapp.balancer.Rule#matches(HttpServletRequest request)
       */
      public boolean matches(HttpServletRequest request) {
          String actualHeaderValue = request.getHeader(getHeaderName());
  
          if (actualHeaderValue == null) {
              return (getHeaderValue() == null);
          } else {
              return (actualHeaderValue.compareTo(getHeaderValue()) == 0);
          }
      }
  
      /**
       * Returns a String representation of this object.
       *
       * @return String
       */
      public String toString() {
          StringBuffer buffer = new StringBuffer();
  
          buffer.append("[");
          buffer.append(getClass().getName());
          buffer.append(": ");
  
          buffer.append("Header name: ");
          buffer.append(getHeaderName());
          buffer.append(" / ");
  
          buffer.append("Header value: ");
          buffer.append(getHeaderValue());
          buffer.append(" / ");
  
          buffer.append("Redirect URL: ");
          buffer.append(getRedirectUrl());
  
          buffer.append("]");
  
          return buffer.toString();
      }
  }
  
  
  // End of file: RequestHeaderRule.java
  
  
  
  1.1                  jakarta-tomcat-catalina/webapps/balancer/WEB-INF/classes/org/apache/webapp/balancer/rules/RequestParameterRule.java
  
  Index: RequestParameterRule.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * Portions of this software are based upon public domain software
   * originally written at the National Center for Supercomputing Applications,
   * University of Illinois, Urbana-Champaign.
   */
  package org.apache.webapp.balancer.rules;
  
  import javax.servlet.http.HttpServletRequest;
  
  
  /**
   * This rule accepts or rejects requests
   * based on the presence of a parameter
   * in the request.
   *
   * @author Yoav Shapira
   */
  public class RequestParameterRule extends BaseRule {
      /**
       * The target parameter name (parameter
       * must be present for match to succeed).
       */
      private String paramName;
  
      /**
       * The target parameter value.  This
       * is optional: null means any parameter
       * value is OK for a match.  A non-null
       * value will be matches exactly.
       */
      private String paramValue;
  
      /**
       * Sets the target parameter name.
       *
       * @param theParamName The parameter name
       */
      public void setParamName(String theParamName) {
          if (theParamName == null) {
              throw new IllegalArgumentException("paramName cannot be null.");
          } else {
              paramName = theParamName;
          }
      }
  
      /**
       * Returns the target parameter name.
       *
       * @return String The target parameter name.
       */
      protected String getParamName() {
          return paramName;
      }
  
      /**
       * Sets the parameter value, which may be null.
       *
       * @param theParamValue The parameter value
       */
      public void setParamValue(String theParamValue) {
          paramValue = theParamValue;
      }
  
      /**
       * Returns the target parameter value,
       * which may be null.
       *
       * @return String The target parameter value
       */
      protected String getParamValue() {
          return paramValue;
      }
  
      /**
       * @see org.apache.webapp.balancer.Rule#matches(HttpServletRequest)
       */
      public boolean matches(HttpServletRequest request) {
          String actualParamValue = request.getParameter(getParamName());
  
          if (actualParamValue == null) {
              return (getParamValue() == null);
          } else {
              return (actualParamValue.compareTo(getParamValue()) == 0);
          }
      }
  
      /**
       * Returns a String representation of this object.
       *
       * @return String
       */
      public String toString() {
          StringBuffer buffer = new StringBuffer();
  
          buffer.append("[");
          buffer.append(getClass().getName());
          buffer.append(": ");
  
          buffer.append("Target param name: ");
          buffer.append(getParamName());
          buffer.append(" / ");
  
          buffer.append("Target param value: ");
          buffer.append(getParamValue());
          buffer.append(" / ");
  
          buffer.append("Redirect URL: ");
          buffer.append(getRedirectUrl());
  
          buffer.append("]");
  
          return buffer.toString();
      }
  }
  
  
  // End of file: RequestParameterRule.java
  
  
  
  1.1                  jakarta-tomcat-catalina/webapps/balancer/WEB-INF/classes/org/apache/webapp/balancer/rules/SessionAttributeRule.java
  
  Index: SessionAttributeRule.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * Portions of this software are based upon public domain software
   * originally written at the National Center for Supercomputing Applications,
   * University of Illinois, Urbana-Champaign.
   */
  package org.apache.webapp.balancer.rules;
  
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpSession;
  
  
  /**
   * This rule accepts or rejects requests
   * based on the presence of a attribute
   * in the request.
   *
   * @author Yoav Shapira
   */
  public class SessionAttributeRule extends BaseRule {
      /**
       * The target attribute name (attribute
       * must be present for match to succeed).
       */
      private String attributeName;
  
      /**
       * The target attribute value.  This
       * is optional: null means any attribute
       * value is OK for a match.  A non-null
       * value will be matches exactly.
       */
      private Object attributeValue;
  
      /**
       * Sets the target attribute name.
       *
       * @param theAttributeName The attribute name
       */
      public void setAttributeName(String theAttributeName) {
          if (theAttributeName == null) {
              throw new IllegalArgumentException(
                  "attributeName cannot be null.");
          } else {
              attributeName = theAttributeName;
          }
      }
  
      /**
       * Returns the target attribute name.
       *
       * @return String The target attribute name.
       */
      protected String getAttributeName() {
          return attributeName;
      }
  
      /**
       * Sets the attribute value, which may be null.
       *
       * @param theAttributeValue The attribute value
       */
      public void setAttributeValue(Object theAttributeValue) {
          attributeValue = theAttributeValue;
      }
  
      /**
       * Returns the target attribute value,
       * which may be null.
       *
       * @return Object The target attribute value
       */
      protected Object getAttributeValue() {
          return attributeValue;
      }
  
      /**
       * @see org.apache.webapp.balancer.Rule#matches(HttpServletRequest)
       */
      public boolean matches(HttpServletRequest request) {
          HttpSession session = request.getSession();
          Object actualAttributeValue = session.getAttribute(getAttributeName());
  
          if (actualAttributeValue == null) {
              return (getAttributeValue() == null);
          } else {
              return (actualAttributeValue.equals(getAttributeValue()));
          }
      }
  
      /**
       * Returns a String representation of this object.
       *
       * @return String
       */
      public String toString() {
          StringBuffer buffer = new StringBuffer();
  
          buffer.append("[");
          buffer.append(getClass().getName());
          buffer.append(": ");
  
          buffer.append("Target attribute name: ");
          buffer.append(getAttributeName());
          buffer.append(" / ");
  
          buffer.append("Target attribute value: ");
          buffer.append(getAttributeValue());
          buffer.append(" / ");
  
          buffer.append("Redirect URL: ");
          buffer.append(getRedirectUrl());
  
          buffer.append("]");
  
          return buffer.toString();
      }
  }
  
  
  // End of file: SessionAttributeRule.java
  
  
  
  1.1                  jakarta-tomcat-catalina/webapps/balancer/WEB-INF/classes/org/apache/webapp/balancer/rules/URLStringMatchRule.java
  
  Index: URLStringMatchRule.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * Portions of this software are based upon public domain software
   * originally written at the National Center for Supercomputing Applications,
   * University of Illinois, Urbana-Champaign.
   */
  package org.apache.webapp.balancer.rules;
  
  import javax.servlet.http.HttpServletRequest;
  
  
  /**
   * This rule looks for a specific string
   * in the URL for a positive match.
   *
   * @author Yoav Shapira
   */
  public class URLStringMatchRule extends BaseRule {
      /**
       * The target string that must be present
       * in the URL, may not be null.
       */
      private String targetString;
  
      /**
       * Sets the target string that must
       * be present in the URL.
       *
       * @param theTargetString The target string
       */
      public void setTargetString(String theTargetString) {
          if (theTargetString == null) {
              throw new IllegalArgumentException(
                  "The target string cannot be null.");
          } else {
              targetString = theTargetString;
          }
      }
  
      /**
       * Returns the target string that must
       * be present in the URL.
       *
       * @return The target string
       */
      protected String getTargetString() {
          return targetString;
      }
  
      /**
       * @see org.apache.webapp.balancer.Rule#matches(HttpServletRequest)
       *
       * Looks for the target string in the request URL.
       */
      public boolean matches(HttpServletRequest request) {
          String requestUrl = request.getRequestURL().toString();
          int index = requestUrl.indexOf(getTargetString());
  
          return (index > -1);
      }
  
      /**
       * Returns a String representation of this object.
       *
       * @return String
       */
      public String toString() {
          StringBuffer buffer = new StringBuffer();
  
          buffer.append("[");
          buffer.append(getClass().getName());
          buffer.append(": ");
  
          buffer.append("Target string: ");
          buffer.append(getTargetString());
          buffer.append(" / ");
  
          buffer.append("Redirect URL: ");
          buffer.append(getRedirectUrl());
  
          buffer.append("]");
  
          return buffer.toString();
      }
  }
  
  
  // End of file: URLStringMatchRule.java
  
  
  
  1.1                  jakarta-tomcat-catalina/webapps/balancer/WEB-INF/classes/org/apache/webapp/balancer/rules/UserRoleRule.java
  
  Index: UserRoleRule.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * Portions of this software are based upon public domain software
   * originally written at the National Center for Supercomputing Applications,
   * University of Illinois, Urbana-Champaign.
   */
  package org.apache.webapp.balancer.rules;
  
  import javax.servlet.http.HttpServletRequest;
  
  
  /**
   * This rule redirects the request based
   * on the user's role.
   *
   * @author Yoav Shapira
   */
  public class UserRoleRule extends BaseRule {
      /**
       * The desired role for the user.
       * If the user is in this role, the
       * match will succeed.
       */
      private String role;
  
      /**
       * Sets the desired role.
       *
       * @param theRole The desire role
       */
      public void setRole(String theRole) {
          if (theRole == null) {
              throw new IllegalArgumentException("The role cannot be null.");
          } else {
              role = theRole;
          }
      }
  
      /**
       * Returns the target role.
       *
       * @return The desired role
       */
      protected String getRole() {
          return role;
      }
  
      /**
       * @see org.apache.webapp.balancer.Rule#matches(HttpServletRequest)
       */
      public boolean matches(HttpServletRequest request) {
          return request.isUserInRole(getRole());
      }
  
      /**
       * Returns a String representation of this object.
       *
       * @return String
       */
      public String toString() {
          StringBuffer buffer = new StringBuffer();
  
          buffer.append("[");
          buffer.append(getClass().getName());
          buffer.append(": ");
  
          buffer.append("Target role: ");
          buffer.append(getRole());
          buffer.append(" / ");
  
          buffer.append("Redirect URL: ");
          buffer.append(getRedirectUrl());
  
          buffer.append("]");
  
          return buffer.toString();
      }
  }
  
  
  // End of file: UserRoleRule.java
  
  
  
  1.1                  jakarta-tomcat-catalina/webapps/balancer/WEB-INF/classes/org/apache/webapp/balancer/rules/package.html
  
  Index: package.html
  ===================================================================
  <html>
  <head>
  <title>org.apache.webapp.balancer.rules Package Overview</title>
  </head>
  <body>
  This package contains all the {@link org.apache.webapp.balancer.Rule} 
  implementations that are distributed with the balancer webapp.  All 
  these rules extend {@link org.apache.webapp.balancer.rules.BaseRule} 
  but users are free to implement the Rule interface as needed.
  </body>
  </html>
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org