vmassol     2003/06/22 07:53:58

  Modified:    framework/src/java/share/org/apache/cactus/client/connector/http
                        AbstractConnectionHelper.java
               framework/src/java/share/org/apache/cactus Cookie.java
                        WebResponse.java
  Added:       framework/src/java/share/org/apache/cactus/client/connector/http
                        CookieUtil.java
  Log:
  Started refactoring cookie utility methods in a CookieUtil class. These are not 
API-public methods.
  
  Revision  Changes    Path
  1.5       +5 -6      
jakarta-cactus/framework/src/java/share/org/apache/cactus/client/connector/http/AbstractConnectionHelper.java
  
  Index: AbstractConnectionHelper.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-cactus/framework/src/java/share/org/apache/cactus/client/connector/http/AbstractConnectionHelper.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- AbstractConnectionHelper.java     6 May 2003 09:39:45 -0000       1.4
  +++ AbstractConnectionHelper.java     22 Jun 2003 14:53:58 -0000      1.5
  @@ -75,7 +75,6 @@
    * methods are common to any implementation.
    *
    * @author <a href="mailto:[EMAIL PROTECTED]">Vincent Massol</a>
  - *
    * @version $Id$
    */
   public abstract class AbstractConnectionHelper
  @@ -180,8 +179,8 @@
   
               // and create the cookie header to send
               Header cookieHeader = createCookieHeader(
  -                Cookie.getCookieDomain(theRequest, theUrl.getHost()), 
  -                Cookie.getCookiePath(theRequest, theUrl.getFile()), 
  +                CookieUtil.getCookieDomain(theRequest, theUrl.getHost()), 
  +                CookieUtil.getCookiePath(theRequest, theUrl.getFile()), 
                   httpclientCookies);
   
               return cookieHeader.getValue();
  @@ -233,7 +232,7 @@
           String domain;
           if (theCactusCookie.getDomain() == null)
           {
  -            domain = Cookie.getCookieDomain(theRequest, theUrl.getHost());
  +            domain = CookieUtil.getCookieDomain(theRequest, theUrl.getHost());
           }
           else
           {
  @@ -244,7 +243,7 @@
           String path;
           if (theCactusCookie.getPath() == null)
           {
  -            path = Cookie.getCookiePath(theRequest, theUrl.getFile());
  +            path = CookieUtil.getCookiePath(theRequest, theUrl.getFile());
           }
           else
           {
  
  
  
  1.1                  
jakarta-cactus/framework/src/java/share/org/apache/cactus/client/connector/http/CookieUtil.java
  
  Index: CookieUtil.java
  ===================================================================
  /*
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001-2003 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 acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Cactus" 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 [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * 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/>.
   *
   */
  package org.apache.cactus.client.connector.http;
  
  import org.apache.cactus.ServletURL;
  import org.apache.cactus.WebRequest;
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  
  /**
   * Utility methods to manipulate cookies and transform Cactus cookie objects 
   * to HttpClient cookie objects.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Vincent Massol</a>
   * @version $Id: CookieUtil.java,v 1.1 2003/06/22 14:53:58 vmassol Exp $
   * @since 1.5
   */
  public class CookieUtil
  {
      /**
       * The logger
       */
      private static final Log LOGGER = LogFactory.getLog(CookieUtil.class);
  
      /**
       * Returns the domain that will be used to send the cookies. If a host
       * was specified using <code>setURL()</code> then the domain will be
       * this host. Otherwise it will be the real redirector host.
       *
       * @param theRequest the request containing all data to pass to the server
       *        redirector.
       * @param theRealHost the real host to which we are connecting to. We will
       *        use it if no simulation host has been specified.
       * @return the cookie domain to use
       */
      public static String getCookieDomain(WebRequest theRequest, 
          String theRealHost)
      {
          String domain;
          ServletURL url = theRequest.getURL();
  
          if ((url != null) && (url.getHost() != null))
          {
              domain = url.getHost();
          }
          else
          {
              domain = theRealHost;
          }
  
          LOGGER.debug("Cookie validation domain = [" + domain + "]");
  
          return domain;
      }
  
      /**
       * Returns the port that will be used to send the cookies. If a port
       * was specified using <code>setURL()</code> then the port sent will be
       * this port. Otherwise it will be the real redirector port.
       *
       * @param theRequest the request containing all data to pass to the server
       *        redirector.
       * @param theRealPort the real port to which we are connecting to. We will
       *        use it if no simulation port has been specified.
       * @return the cookie domain to use
       */
      public static int getCookiePort(WebRequest theRequest, int theRealPort)
      {
          int port;
          ServletURL url = theRequest.getURL();
  
          if ((url != null) && (url.getHost() != null))
          {
              port = url.getPort();
          }
          else
          {
              port = theRealPort;
          }
  
          LOGGER.debug("Cookie validation port = [" + port + "]");
  
          return port;
      }
  
      /**
       * Returns the path that will be used to validate if a cookie will be
       * sent or not. The algorithm is as follows : if the cookie path is not
       * set (i.e. null) then the cookie is always sent (provided the domain
       * is right). If the cookie path is set, the cookie is sent only if
       * the request path starts with the same string as the cookie path. If
       * <code>setURL()</code> has been called, return the path it has been
       * set to (context + servletPath + pathInfo). Otherwise return the
       * real redirector path.
       *
       * @param theRequest the request containing all data to pass to the server
       *        redirector.
       * @param theRealPath the real path to which we are connecting to. We will
       *        use it if no simulation path has been specified.
       * @return the path to use to decide if a cookie will get sent
       */
      public static String getCookiePath(WebRequest theRequest, 
          String theRealPath)
      {
          String path;
          ServletURL url = theRequest.getURL();
  
          if ((url != null) && (url.getPath() != null))
          {
              path = url.getPath();
          }
          else
          {
              String file = theRealPath;
  
              if (file != null)
              {
                  int q = file.lastIndexOf('?');
  
                  if (q != -1)
                  {
                      path = file.substring(0, q);
                  }
                  else
                  {
                      path = file;
                  }
              }
              else
              {
                  path = null;
              }
          }
  
          LOGGER.debug("Cookie validation path = [" + path + "]");
  
          return path;
      }
  }
  
  
  
  1.8       +11 -103   
jakarta-cactus/framework/src/java/share/org/apache/cactus/Cookie.java
  
  Index: Cookie.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-cactus/framework/src/java/share/org/apache/cactus/Cookie.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- Cookie.java       26 May 2003 11:45:23 -0000      1.7
  +++ Cookie.java       22 Jun 2003 14:53:58 -0000      1.8
  @@ -60,8 +60,7 @@
   
   import java.util.Date;
   
  -import org.apache.commons.logging.Log;
  -import org.apache.commons.logging.LogFactory;
  +import org.apache.cactus.client.connector.http.CookieUtil;
   
   /**
    * Client cookie. Used for manipulating client cookies either in
  @@ -75,11 +74,6 @@
   public class Cookie implements Serializable
   {
       /**
  -     * The logger
  -     */
  -    private static final Log LOGGER = LogFactory.getLog(Cookie.class);
  -
  -    /**
        * The cookie name
        */
       private String name;
  @@ -385,117 +379,31 @@
       }
   
       /**
  -     * Returns the domain that will be used to send the cookies. If a host
  -     * was specified using <code>setURL()</code> then the domain will be
  -     * this host. Otherwise it will be the real redirector host.
  -     *
  -     * @param theRequest the request containing all data to pass to the server
  -     *        redirector.
  -     * @param theRealHost the real host to which we are connecting to. We will
  -     *        use it if no simulation host has been specified.
  -     * @return the cookie domain to use
  +     * @see CookieUtil#getCookieDomain(WebRequest, String)
  +     * @deprecated use [EMAIL PROTECTED] CookieUtil#getCookieDomain(WebRequest, 
String)} 
        */
       public static String getCookieDomain(WebRequest theRequest, 
           String theRealHost)
       {
  -        String domain;
  -        ServletURL url = theRequest.getURL();
  -
  -        if ((url != null) && (url.getHost() != null))
  -        {
  -            domain = url.getHost();
  -        }
  -        else
  -        {
  -            domain = theRealHost;
  -        }
  -
  -        LOGGER.debug("Cookie validation domain = [" + domain + "]");
  -
  -        return domain;
  +        return CookieUtil.getCookieDomain(theRequest, theRealHost);
       }
   
       /**
  -     * Returns the port that will be used to send the cookies. If a port
  -     * was specified using <code>setURL()</code> then the port sent will be
  -     * this port. Otherwise it will be the real redirector port.
  -     *
  -     * @param theRequest the request containing all data to pass to the server
  -     *        redirector.
  -     * @param theRealPort the real port to which we are connecting to. We will
  -     *        use it if no simulation port has been specified.
  -     * @return the cookie domain to use
  +     * @see CookieUtil#getCookiePort(WebRequest, int)
  +     * @deprecated use [EMAIL PROTECTED] CookieUtil#getCookiePort(WebRequest, int)} 
        */
       public static int getCookiePort(WebRequest theRequest, int theRealPort)
       {
  -        int port;
  -        ServletURL url = theRequest.getURL();
  -
  -        if ((url != null) && (url.getHost() != null))
  -        {
  -            port = url.getPort();
  -        }
  -        else
  -        {
  -            port = theRealPort;
  -        }
  -
  -        LOGGER.debug("Cookie validation port = [" + port + "]");
  -
  -        return port;
  +        return CookieUtil.getCookiePort(theRequest, theRealPort);
       }
   
       /**
  -     * Returns the path that will be used to validate if a cookie will be
  -     * sent or not. The algorithm is as follows : if the cookie path is not
  -     * set (i.e. null) then the cookie is always sent (provided the domain
  -     * is right). If the cookie path is set, the cookie is sent only if
  -     * the request path starts with the same string as the cookie path. If
  -     * <code>setURL()</code> has been called, return the path it has been
  -     * set to (context + servletPath + pathInfo). Otherwise return the
  -     * real redirector path.
  -     *
  -     * @param theRequest the request containing all data to pass to the server
  -     *        redirector.
  -     * @param theRealPath the real path to which we are connecting to. We will
  -     *        use it if no simulation path has been specified.
  -     * @return the path to use to decide if a cookie will get sent
  +     * @see CookieUtil#getCookiePath(WebRequest, String)
  +     * @deprecated use [EMAIL PROTECTED] CookieUtil#getCookiePath(WebRequest, 
String)} 
        */
       public static String getCookiePath(WebRequest theRequest, 
           String theRealPath)
       {
  -        String path;
  -        ServletURL url = theRequest.getURL();
  -
  -        if ((url != null) && (url.getPath() != null))
  -        {
  -            path = url.getPath();
  -        }
  -        else
  -        {
  -            String file = theRealPath;
  -
  -            if (file != null)
  -            {
  -                int q = file.lastIndexOf('?');
  -
  -                if (q != -1)
  -                {
  -                    path = file.substring(0, q);
  -                }
  -                else
  -                {
  -                    path = file;
  -                }
  -            }
  -            else
  -            {
  -                path = null;
  -            }
  -        }
  -
  -        LOGGER.debug("Cookie validation path = [" + path + "]");
  -
  -        return path;
  +        return CookieUtil.getCookiePath(theRequest, theRealPath);
       }
   }
  
  
  
  1.13      +5 -4      
jakarta-cactus/framework/src/java/share/org/apache/cactus/WebResponse.java
  
  Index: WebResponse.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-cactus/framework/src/java/share/org/apache/cactus/WebResponse.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- WebResponse.java  9 Jun 2003 20:17:09 -0000       1.12
  +++ WebResponse.java  22 Jun 2003 14:53:58 -0000      1.13
  @@ -65,6 +65,7 @@
   
   import java.util.Vector;
   
  +import org.apache.cactus.client.connector.http.CookieUtil;
   import org.apache.cactus.util.ChainedRuntimeException;
   import org.apache.cactus.util.IoUtil;
   import org.apache.commons.httpclient.Header;
  @@ -291,11 +292,11 @@
                   try
                   {
                       cookies = org.apache.commons.httpclient.Cookie.parse(
  -                        Cookie.getCookieDomain(getWebRequest(), 
  +                        CookieUtil.getCookieDomain(getWebRequest(), 
                               getConnection().getURL().getHost()), 
  -                        Cookie.getCookiePort(getWebRequest(), 
  +                        CookieUtil.getCookiePort(getWebRequest(), 
                               getConnection().getURL().getPort()), 
  -                        Cookie.getCookiePath(getWebRequest(), 
  +                        CookieUtil.getCookiePath(getWebRequest(), 
                               getConnection().getURL().getFile()), 
                           new Header(headerName, headerValue));
                   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to