You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cactus-dev@jakarta.apache.org by vm...@apache.org on 2002/03/28 17:03:03 UTC

cvs commit: jakarta-cactus/framework/src/java/share/org/apache/cactus ServletURL.java

vmassol     02/03/28 08:03:03

  Modified:    framework/src/java/share/org/apache/cactus ServletURL.java
  Log:
  added notion of protocol
  
  Revision  Changes    Path
  1.2       +85 -6     jakarta-cactus/framework/src/java/share/org/apache/cactus/ServletURL.java
  
  Index: ServletURL.java
  ===================================================================
  RCS file: /home/cvs/jakarta-cactus/framework/src/java/share/org/apache/cactus/ServletURL.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ServletURL.java	1 Mar 2002 00:43:45 -0000	1.1
  +++ ServletURL.java	28 Mar 2002 16:03:03 -0000	1.2
  @@ -82,14 +82,22 @@
    *
    * @author <a href="mailto:vmassol@apache.org">Vincent Massol</a>
    *
  - * @version $Id: ServletURL.java,v 1.1 2002/03/01 00:43:45 vmassol Exp $
  + * @version $Id: ServletURL.java,v 1.2 2002/03/28 16:03:03 vmassol Exp $
    */
   public class ServletURL
   {
       /**
  +     * Name of the parameter in the HTTP request that represents the protocol
  +     * (HTTP, HTTPS, etc) in the URL to simulate. The name is voluntarily long
  +     * so that it will not clash with a user-defined parameter.
  +     */
  +    public final static String URL_PROTOCOL_PARAM =
  +        "Cactus_URL_Protocol";
  +
  +    /**
        * Name of the parameter in the HTTP request that represents the Server
  -     * name in the URL to simulate. The name is voluntarily long so that it
  -     * will not clash with a user-defined parameter.
  +     * name (+ port) in the URL to simulate. The name is voluntarily long so
  +     * that it will not clash with a user-defined parameter.
        */
       public final static String URL_SERVER_NAME_PARAM =
           "Cactus_URL_Server";
  @@ -127,6 +135,16 @@
           "Cactus_URL_QueryString";
   
       /**
  +     * Http protocol.
  +     */
  +    public final static String PROTOCOL_HTTP = "http";
  +
  +    /**
  +     * Https protocol.
  +     */
  +    public final static String PROTOCOL_HTTPS = "https";
  +
  +    /**
        * The server name to simulate (including port number)
        */
       private String serverName;
  @@ -152,6 +170,11 @@
       private String queryString;
   
       /**
  +     * The protocol to use.
  +     */
  +    private String protocol;
  +
  +    /**
        * The logger
        */
       private static final Log LOGGER =
  @@ -160,6 +183,9 @@
       /**
        * Creates the URL to simulate.
        *
  +     * @param theProtocol   the protocol to simulate (either
  +     *                      <code>ServletURL.PROTOCOL_HTTP</code> or
  +     *                      <code>ServletUEL.PROTOCOL_HTTPS</code>.
        * @param theServerName the server name (and port) in the URL to simulate,
        *                      i.e. this is the name that will be returned by the
        *                      <code>HttpServletRequest.getServerName()</code> and
  @@ -186,9 +212,11 @@
        *                       <code>HttpServletResquest.getQueryString()</code>.
        *                       Can be null.
        */
  -    public ServletURL(String theServerName, String theContextPath,
  -        String theServletPath, String thePathInfo, String theQueryString)
  +    public ServletURL(String theProtocol, String theServerName,
  +        String theContextPath, String theServletPath, String thePathInfo,
  +        String theQueryString)
       {
  +        this.protocol = theProtocol;
           this.serverName = theServerName;
           this.contextPath = theContextPath;
           this.servletPath = theServletPath;
  @@ -197,6 +225,50 @@
       }
   
       /**
  +     * Creates the URL to simulate, using the default HTTP protocol.
  +     *
  +     * @param theServerName the server name (and port) in the URL to simulate,
  +     *                      i.e. this is the name that will be returned by the
  +     *                      <code>HttpServletRequest.getServerName()</code> and
  +     *                      <code>HttpServletRequest.getServerPort()</code>. Can
  +     *                      be null. If null, then the server name and port from
  +     *                      the Servlet Redirector will be returned.
  +     * @param theContextPath the webapp context path in the URL to simulate,
  +     *                      i.e. this is the name that will be returned by the
  +     *                      <code>HttpServletRequest.getContextPath()</code>.
  +     *                      Can be null. If null, then the context from the
  +     *                      Servlet Redirector will be returned.
  +     *                      Format: "/" + name or an empty string
  +     *                      for the default context.
  +     * @param theServletPath the servlet path in the URL to simulate,
  +     *                      i.e. this is the name that will be returned by the
  +     *                      <code>HttpServletRequest.getServletPath()</code>.
  +     *                      Can be null. Format : "/" + name.
  +     * @param thePathInfo   the path info in the URL to simulate, i.e. this is
  +     *                      the name that will be returned by the
  +     *                      <code>HttpServletRequest.getPathInfo()</code>. Can
  +     *                      be null. Format : "/" + name.
  +     * @param theQueryString the Query string in the URL to simulate, i.e. this
  +     *                       is the string that will be returned by the
  +     *                       <code>HttpServletResquest.getQueryString()</code>.
  +     *                       Can be null.
  +     */
  +    public ServletURL(String theServerName, String theContextPath,
  +        String theServletPath, String thePathInfo, String theQueryString)
  +    {
  +        this(PROTOCOL_HTTP, theServerName, theContextPath, theServletPath,
  +            thePathInfo, theQueryString);
  +    }
  +
  +    /**
  +     * @return the protocol used to connect to the URL (HTTP, HTTPS, etc).
  +     */
  +    public String getProtocol()
  +    {
  +        return this.protocol;
  +    }
  +
  +    /**
        * @return the simulated URL server name (including the port number)
        */
       public String getServerName()
  @@ -309,6 +381,10 @@
           // the user to send whatever he wants in the request body. For example
           // a file, ...
   
  +        if (getProtocol() != null) {
  +            theRequest.addParameter(URL_PROTOCOL_PARAM, getProtocol(),
  +                WebRequest.GET_METHOD);
  +        }
           if (getServerName() != null) {
               theRequest.addParameter(URL_SERVER_NAME_PARAM, getServerName(),
                   WebRequest.GET_METHOD);
  @@ -343,6 +419,8 @@
       {
           String qString = theRequest.getQueryString();
   
  +        String protocol = ServletUtil.getQueryStringParameter(qString,
  +            URL_PROTOCOL_PARAM);
           String serverName = ServletUtil.getQueryStringParameter(qString,
               URL_SERVER_NAME_PARAM);
           String contextPath = ServletUtil.getQueryStringParameter(qString,
  @@ -354,7 +432,7 @@
           String queryString = ServletUtil.getQueryStringParameter(qString,
               URL_QUERY_STRING_PARAM);
   
  -        ServletURL url = new ServletURL(serverName, contextPath,
  +        ServletURL url = new ServletURL(protocol, serverName, contextPath,
               servletPath, pathInfo, queryString);
   
           LOGGER.debug("URL = [" + url + "]");
  @@ -368,6 +446,7 @@
       public String toString()
       {
           StringBuffer buffer = new StringBuffer();
  +        buffer.append("protocol = [" + getProtocol() + "], ");
           buffer.append("host name = [" + getHost() + "], ");
           buffer.append("port = [" + getPort() + "], ");
           buffer.append("context path = [" + getContextPath() + "], ");
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>