2011/08/05 - Jakarta Cactus has been retired.

For more information, please explore the Attic.

Clover coverage report - Cactus 1.8dev for J2EE API 1.3
Coverage timestamp: Sun Mar 26 2006 18:50:18 BRT
file stats: LOC: 695   Methods: 22
NCLOC: 303   Classes: 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
 
 Source file Conditionals Statements Methods TOTAL
ServletURL.java 46.8% 74.3% 100% 68.5%
coverage coverage
 1   
 /* 
 2   
  * ========================================================================
 3   
  * 
 4   
  * Copyright 2001-2004 The Apache Software Foundation.
 5   
  *
 6   
  * Licensed under the Apache License, Version 2.0 (the "License");
 7   
  * you may not use this file except in compliance with the License.
 8   
  * You may obtain a copy of the License at
 9   
  * 
 10   
  *   http://www.apache.org/licenses/LICENSE-2.0
 11   
  * 
 12   
  * Unless required by applicable law or agreed to in writing, software
 13   
  * distributed under the License is distributed on an "AS IS" BASIS,
 14   
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 15   
  * See the License for the specific language governing permissions and
 16   
  * limitations under the License.
 17   
  * 
 18   
  * ========================================================================
 19   
  */
 20   
 package org.apache.cactus;
 21   
 
 22   
 import javax.servlet.http.HttpServletRequest;
 23   
 
 24   
 import org.apache.cactus.internal.server.ServletUtil;
 25   
 import org.apache.commons.logging.Log;
 26   
 import org.apache.commons.logging.LogFactory;
 27   
 
 28   
 /**
 29   
  * Simulate an HTTP URL by breaking it into its different parts.
 30   
  * <br><code><pre><b>
 31   
  * URL = "http://" + serverName (including port) + requestURI ? queryString<br>
 32   
  * requestURI = contextPath + servletPath + pathInfo
 33   
  * </b></pre></code>
 34   
  * From the Servlet 2.2 specification :<br>
 35   
  * <code><pre><ul><li><b>Context Path</b>: The path prefix associated with the
 36   
  *   ServletContext that this servlet is a part of. If this context is the
 37   
  *   default context rooted at the base of the web server's URL namespace, this
 38   
  *   path will be an empty string. Otherwise, this path starts with a "/"
 39   
  *   character but does not end with a "/" character.</li>
 40   
  * <li><b>Servlet Path</b>: The path section that directly corresponds to the
 41   
  *   mapping which activated this request. This path starts with a "/"
 42   
  *   character.</li>
 43   
  * <li><b>PathInfo</b>: The part of the request path that is not part of the
 44   
  *   Context Path or the Servlet Path.</li></ul></pre></code>
 45   
  * From the Servlet 2.3 specification :<br>
 46   
  * <code><pre><ul><li><b>Context Path</b>: The path prefix associated with the
 47   
  *   ServletContext that this servlet is a part of. If this context is the
 48   
  *   default context rooted at the base of the web server's URL namespace, this
 49   
  *   path will be an empty string. Otherwise, this path starts with a "/"
 50   
  *   character but does not end with a "/" character.</li>
 51   
  * <li><b>Servlet Path</b>: The path section that directly corresponds to the
 52   
  *   mapping which activated this request. This path starts with a "/"
 53   
  *   character <b>except in the case where the request is matched with the 
 54   
  *   "/*" pattern, in which case it is the empty string</b>.</li>
 55   
  * <li><b>PathInfo</b>: The part of the request path that is not part of the
 56   
  *   Context Path or the Servlet Path. <b>It is either null if there is no 
 57   
  *   extra path, or is a string with a leading "/"</b>.</li></ul></pre></code>
 58   
  *
 59   
  * @version $Id: ServletURL.java 238991 2004-05-22 11:34:50Z vmassol $
 60   
  */
 61   
 public class ServletURL
 62   
 {
 63   
     /**
 64   
      * Name of the parameter in the HTTP request that represents the protocol
 65   
      * (HTTP, HTTPS, etc) in the URL to simulate. The name is voluntarily long
 66   
      * so that it will not clash with a user-defined parameter.
 67   
      */
 68   
     public static final String URL_PROTOCOL_PARAM = "Cactus_URL_Protocol";
 69   
 
 70   
     /**
 71   
      * Name of the parameter in the HTTP request that represents the Server
 72   
      * name (+ port) in the URL to simulate. The name is voluntarily long so
 73   
      * that it will not clash with a user-defined parameter.
 74   
      */
 75   
     public static final String URL_SERVER_NAME_PARAM = "Cactus_URL_Server";
 76   
 
 77   
     /**
 78   
      * Name of the parameter in the HTTP request that represents the context
 79   
      * path in the URL to simulate. The name is voluntarily long so that it
 80   
      * will not clash with a user-defined parameter.
 81   
      */
 82   
     public static final String URL_CONTEXT_PATH_PARAM = 
 83   
         "Cactus_URL_ContextPath";
 84   
 
 85   
     /**
 86   
      * Name of the parameter in the HTTP request that represents the Servlet
 87   
      * Path in the URL to simulate. The name is voluntarily long so that it
 88   
      * will not clash with a user-defined parameter.
 89   
      */
 90   
     public static final String URL_SERVLET_PATH_PARAM = 
 91   
         "Cactus_URL_ServletPath";
 92   
 
 93   
     /**
 94   
      * Name of the parameter in the HTTP request that represents the Path Info
 95   
      * in the URL to simulate. The name is voluntarily long so that it will not
 96   
      * clash with a user-defined parameter.
 97   
      */
 98   
     public static final String URL_PATH_INFO_PARAM = "Cactus_URL_PathInfo";
 99   
 
 100   
     /**
 101   
      * Name of the parameter in the HTTP request that represents the Query
 102   
      * String in the URL to simulate. The name is voluntarily long so that it
 103   
      * will not clash with a user-defined parameter.
 104   
      */
 105   
     public static final String URL_QUERY_STRING_PARAM = 
 106   
         "Cactus_URL_QueryString";
 107   
 
 108   
     /**
 109   
      * Http protocol.
 110   
      */
 111   
     public static final String PROTOCOL_HTTP = "http";
 112   
 
 113   
     /**
 114   
      * Https protocol.
 115   
      */
 116   
     public static final String PROTOCOL_HTTPS = "https";
 117   
 
 118   
     /**
 119   
      * Default port of the HTTP protocol.
 120   
      */
 121   
     private static final int DEFAULT_PORT_HTTP = 80;
 122   
 
 123   
     /**
 124   
      * Default port of HTTP over SSL.
 125   
      */
 126   
     private static final int DEFAULT_PORT_HTTPS = 443;
 127   
 
 128   
     /**
 129   
      * The logger
 130   
      */
 131   
     private static final Log LOGGER = LogFactory.getLog(ServletURL.class);
 132   
 
 133   
     /**
 134   
      * The server name to simulate (including port number)
 135   
      */
 136   
     private String serverName;
 137   
 
 138   
     /**
 139   
      * The context path to simulate
 140   
      */
 141   
     private String contextPath;
 142   
 
 143   
     /**
 144   
      * The servlet path to simulate
 145   
      */
 146   
     private String servletPath;
 147   
 
 148   
     /**
 149   
      * The Path Info to simulate
 150   
      */
 151   
     private String pathInfo;
 152   
 
 153   
     /**
 154   
      * The Query string
 155   
      */
 156   
     private String queryString;
 157   
 
 158   
     /**
 159   
      * The protocol to use. Default to HTTP.
 160   
      */
 161   
     private String protocol = PROTOCOL_HTTP;
 162   
 
 163   
     /**
 164   
      * Default constructor. Need to call the different setters to make this
 165   
      * a valid object.
 166   
      */
 167  29
     public ServletURL()
 168   
     {
 169   
     }
 170   
 
 171   
     /**
 172   
      * Creates the URL to simulate.
 173   
      *
 174   
      * @param theProtocol   the protocol to simulate (either
 175   
      *                      <code>ServletURL.PROTOCOL_HTTP</code> or
 176   
      *                      <code>ServletURL.PROTOCOL_HTTPS</code>.
 177   
      * @param theServerName the server name (and port) in the URL to simulate,
 178   
      *                      i.e. this is the name that will be returned by the
 179   
      *                      <code>HttpServletRequest.getServerName()</code> and
 180   
      *                      <code>HttpServletRequest.getServerPort()</code>. Can
 181   
      *                      be null. If null, then the server name and port from
 182   
      *                      the Servlet Redirector will be returned.
 183   
      * @param theContextPath the webapp context path in the URL to simulate,
 184   
      *                      i.e. this is the name that will be returned by the
 185   
      *                      <code>HttpServletRequest.getContextPath()</code>.
 186   
      *                      Can be null. If null, then the context from the
 187   
      *                      Servlet Redirector will be used.
 188   
      *                      Format: "/" + name or an empty string for the 
 189   
      *                      default context. Must not end with a "/" character.
 190   
      * @param theServletPath the servlet path in the URL to simulate,
 191   
      *                      i.e. this is the name that will be returned by the
 192   
      *                      <code>HttpServletRequest.getServletPath()</code>.
 193   
      *                      Can be null. If null, then the servlet path from 
 194   
      *                      the Servlet Redirector will be used.
 195   
      *                      Format : "/" + name or an empty string.
 196   
      * @param thePathInfo   the path info in the URL to simulate, i.e. this is
 197   
      *                      the name that will be returned by the
 198   
      *                      <code>HttpServletRequest.getPathInfo()</code>. Can
 199   
      *                      be null. Format : "/" + name.
 200   
      * @param theQueryString the Query string in the URL to simulate, i.e. this
 201   
      *                       is the string that will be returned by the
 202   
      *                       <code>HttpServletResquest.getQueryString()</code>.
 203   
      *                       Can be null.
 204   
      */
 205  1
     public ServletURL(String theProtocol, String theServerName, 
 206   
         String theContextPath, String theServletPath, String thePathInfo, 
 207   
         String theQueryString)
 208   
     {
 209  1
         setProtocol(theProtocol);
 210  1
         setServerName(theServerName);
 211  1
         setContextPath(theContextPath);
 212  1
         setServletPath(theServletPath);
 213  1
         setPathInfo(thePathInfo);
 214  1
         setQueryString(theQueryString);
 215   
     }
 216   
 
 217   
     /**
 218   
      * Creates the URL to simulate, using the default HTTP protocol.
 219   
      *
 220   
      * @param theServerName the server name (and port) in the URL to simulate,
 221   
      *                      i.e. this is the name that will be returned by the
 222   
      *                      <code>HttpServletRequest.getServerName()</code> and
 223   
      *                      <code>HttpServletRequest.getServerPort()</code>. Can
 224   
      *                      be null. If null, then the server name and port from
 225   
      *                      the Servlet Redirector will be returned.
 226   
      * @param theContextPath the webapp context path in the URL to simulate,
 227   
      *                      i.e. this is the name that will be returned by the
 228   
      *                      <code>HttpServletRequest.getContextPath()</code>.
 229   
      *                      Can be null. If null, then the context from the
 230   
      *                      Servlet Redirector will be used.
 231   
      *                      Format: "/" + name or an empty string for the 
 232   
      *                      default context. Must not end with a "/" character.
 233   
      * @param theServletPath the servlet path in the URL to simulate,
 234   
      *                      i.e. this is the name that will be returned by the
 235   
      *                      <code>HttpServletRequest.getServletPath()</code>.
 236   
      *                      Can be null. If null, then the servlet path from 
 237   
      *                      the Servlet Redirector will be used.
 238   
      *                      Format : "/" + name or an empty string.
 239   
      * @param thePathInfo   the path info in the URL to simulate, i.e. this is
 240   
      *                      the name that will be returned by the
 241   
      *                      <code>HttpServletRequest.getPathInfo()</code>. Can
 242   
      *                      be null. Format : "/" + name.
 243   
      * @param theQueryString the Query string in the URL to simulate, i.e. this
 244   
      *                       is the string that will be returned by the
 245   
      *                       <code>HttpServletResquest.getQueryString()</code>.
 246   
      *                       Can be null.
 247   
      */
 248  1
     public ServletURL(String theServerName, String theContextPath, 
 249   
         String theServletPath, String thePathInfo, String theQueryString)
 250   
     {
 251  1
         this(PROTOCOL_HTTP, theServerName, theContextPath, theServletPath, 
 252   
             thePathInfo, theQueryString);
 253   
     }
 254   
 
 255   
     /**
 256   
      * @return the protocol used to connect to the URL (HTTP, HTTPS, etc).
 257   
      */
 258  5
     public String getProtocol()
 259   
     {
 260  5
         return this.protocol;
 261   
     }
 262   
 
 263   
     /**
 264   
      * Sets the protocol to simulate (either
 265   
      * <code>ServletURL.PROTOCOL_HTTP</code> or
 266   
      * <code>ServletURL.PROTOCOL_HTTPS</code>. If parameter is null then
 267   
      * PROTOCOL_HTTP is assumed.
 268   
      *
 269   
      * @param theProtocol the protocol to simulate
 270   
      */
 271  2
     public void setProtocol(String theProtocol)
 272   
     {
 273   
         // Only HTTP and HTTPS are currently supported.
 274  2
         if ((!theProtocol.equals(PROTOCOL_HTTP))
 275   
             && (!theProtocol.equals(PROTOCOL_HTTPS)))
 276   
         {
 277  0
             throw new RuntimeException("Invalid protocol [" + theProtocol
 278   
                 + "]. Currently supported protocols are ["
 279   
                 + PROTOCOL_HTTP + "] and ["
 280   
                 + PROTOCOL_HTTPS + "].");
 281   
         }
 282   
 
 283  2
         this.protocol = theProtocol;
 284   
     }
 285   
 
 286   
     /**
 287   
      * @return the simulated URL server name (including the port number)
 288   
      */
 289  15
     public String getServerName()
 290   
     {
 291  15
         return this.serverName;
 292   
     }
 293   
 
 294   
     /**
 295   
      * Sets the server name (and port) in the URL to simulate, ie this is the
 296   
      * name that will be returned by the
 297   
      * <code>HttpServletRequest.getServerName()</code> and
 298   
      * <code>HttpServletRequest.getServerPort()</code>. Does not need to be
 299   
      * set. If not set or null, then the server name and port from the Servlet
 300   
      * Redirector will be returned.
 301   
      *
 302   
      * @param theServerName the server name and port (ex:
 303   
      *        "jakarta.apache.org:80")
 304   
      */
 305  2
     public void setServerName(String theServerName)
 306   
     {
 307  2
         this.serverName = theServerName;
 308   
     }
 309   
 
 310   
     /**
 311   
      * Returns the host name.
 312   
      * 
 313   
      * <p>
 314   
      *   The host name is extracted from the specified server name (as in 
 315   
      *   <code><strong>jakarta.apache.org</strong>:80</code>). If the server
 316   
      *   name has not been set, this method will return <code>null</code>.
 317   
      * </p>
 318   
      * 
 319   
      * @return the simulated URL server name (excluding the port number)
 320   
      */
 321  7
     public String getHost()
 322   
     {
 323  7
         String host = getServerName();
 324   
 
 325  7
         if (host != null)
 326   
         {
 327  7
             int pos = host.indexOf(":");
 328   
 
 329  7
             if (pos > 0)
 330   
             {
 331  0
                 host = host.substring(0, pos);
 332   
             }
 333   
         }
 334   
 
 335  7
         return host;
 336   
     }
 337   
 
 338   
     /**
 339   
      * Returns the port.
 340   
      * 
 341   
      * <p>
 342   
      *   The port is extracted from the specified server name (as in 
 343   
      *   <code>jakarta.apache.org:<strong>80</strong></code>). If the server
 344   
      *   name doesn't contain a port number, the default port number is returned
 345   
      *   (80 for HTTP, 443 for HTTP over SSL). If a port number is specified but
 346   
      *   illegal, or the server name has not been set, this method will return
 347   
      *   -1.
 348   
      * </p>
 349   
      * 
 350   
      * @return the simulated port number or -1 if an illegal port has been
 351   
      *          specified
 352   
      */
 353  3
     public int getPort()
 354   
     {
 355  3
         int port = -1;
 356   
 
 357  3
         if (getServerName() != null)
 358   
         {
 359  3
             int pos = getServerName().indexOf(":");
 360   
 
 361  3
             if (pos < 0)
 362   
             {
 363   
                 // the server name doesn't contain a port specification, so use
 364   
                 // the default port for the protocol
 365  3
                 port = getDefaultPort();
 366   
             }
 367   
             else
 368   
             {
 369   
                 // parse the port encoded in the server name
 370  0
                 try
 371   
                 {
 372  0
                     port = Integer.parseInt(getServerName().substring(pos + 1));
 373  0
                     if (port < 0)
 374   
                     {
 375  0
                         port = -1;
 376   
                     }
 377   
                 }
 378   
                 catch (NumberFormatException e)
 379   
                 {
 380  0
                     port = -1;
 381   
                 }
 382   
             }
 383   
         }
 384   
 
 385  3
         return port;
 386   
     }
 387   
 
 388   
     /**
 389   
      * @return the simulated URL context path
 390   
      */
 391  4
     public String getContextPath()
 392   
     {
 393  4
         return this.contextPath;
 394   
     }
 395   
 
 396   
     /**
 397   
      * Sets the webapp context path in the URL to simulate, ie this is the
 398   
      * name that will be returned by the
 399   
      * <code>HttpServletRequest.getContextPath()</code>. If not set, the
 400   
      * context from the Servlet Redirector will be returned. Format: "/" +
 401   
      * name or an empty string for the default context. If not an empty
 402   
      * string the last character must not be "/".
 403   
      *
 404   
      * @param theContextPath the context path to simulate
 405   
      */
 406  1
     public void setContextPath(String theContextPath)
 407   
     {
 408  1
         if ((theContextPath != null) && (theContextPath.length() > 0))
 409   
         {
 410  0
             if (!theContextPath.startsWith("/"))
 411   
             {
 412  0
                 throw new IllegalArgumentException("The Context Path must"
 413   
                     + " start with a \"/\" character.");
 414   
             }
 415  0
             if (theContextPath.endsWith("/"))
 416   
             {
 417  0
                 throw new IllegalArgumentException("The Context Path must not"
 418   
                     + " end with a \"/\" character.");                
 419   
             }
 420   
         }
 421   
 
 422  1
         this.contextPath = theContextPath;
 423   
     }
 424   
 
 425   
     /**
 426   
      * @return the simulated URL servlet path
 427   
      */
 428  4
     public String getServletPath()
 429   
     {
 430  4
         return this.servletPath;
 431   
     }
 432   
 
 433   
     /**
 434   
      * Sets the servlet path in the URL to simulate, ie this is the name that
 435   
      * will be returned by the <code>HttpServletRequest.getServletPath()</code>.
 436   
      * If null then the servlet path from the Servlet Redirector will be
 437   
      * returned. Format : "/" + name or an empty string.
 438   
      *
 439   
      * @param theServletPath the servlet path to simulate
 440   
      */
 441  1
     public void setServletPath(String theServletPath)
 442   
     {
 443  1
         if ((theServletPath != null) && (theServletPath.length() > 0))
 444   
         {
 445  0
             if (!theServletPath.startsWith("/"))
 446   
             {
 447  0
                 throw new IllegalArgumentException("The Servlet Path must"
 448   
                     + " start with a \"/\" character.");
 449   
             }            
 450   
         }
 451   
 
 452  1
         this.servletPath = theServletPath;
 453   
     }
 454   
 
 455   
     /**
 456   
      * @return the simulated URL path info
 457   
      */
 458  4
     public String getPathInfo()
 459   
     {
 460  4
         return this.pathInfo;
 461   
     }
 462   
 
 463   
     /**
 464   
      * Sets the path info in the URL to simulate, ie this is the name that will
 465   
      * be returned by the <code>HttpServletRequest.getPathInfo()</code>. 
 466   
      * If null then no path info will be set (and the Path Info from the 
 467   
      * Servlet Redirector will <b>not</b> be used). 
 468   
      * Format : "/" + name.
 469   
      *
 470   
      * @param thePathInfo the path info to simulate
 471   
      */
 472  1
     public void setPathInfo(String thePathInfo)
 473   
     {
 474  1
         if ((thePathInfo != null) && (thePathInfo.length() == 0))
 475   
         { 
 476  0
             throw new IllegalArgumentException("The Path Info must"
 477   
                 + " not be an empty string. Use null if you don't"
 478   
                 + " want to have a path info.");
 479   
         }
 480  1
         else if (thePathInfo != null)
 481   
         {
 482  0
             if (!thePathInfo.startsWith("/"))
 483   
             {
 484  0
                 throw new IllegalArgumentException("The Path Info must"
 485   
                     + " start with a \"/\" character.");
 486   
             }            
 487   
         }
 488   
 
 489  1
         this.pathInfo = thePathInfo;
 490   
     }
 491   
 
 492   
     /**
 493   
      * @return the simulated Query String
 494   
      */
 495  2
     public String getQueryString()
 496   
     {
 497  2
         return this.queryString;
 498   
     }
 499   
 
 500   
     /**
 501   
      * Sets the Query string in the URL to simulate, ie this is the string that
 502   
      * will be returned by the
 503   
      * <code>HttpServletResquest.getQueryString()</code>. If not set, the
 504   
      * query string from the Servlet Redirector will be returned.
 505   
      *
 506   
      * @param theQueryString the query string to simulate
 507   
      */
 508  1
     public void setQueryString(String theQueryString)
 509   
     {
 510  1
         this.queryString = theQueryString;
 511   
     }
 512   
 
 513   
     /**
 514   
      * @return the path (contextPath + servletPath + pathInfo) or null if
 515   
      *         not set
 516   
      */
 517  2
     public String getPath()
 518   
     {
 519  2
         String path;
 520   
 
 521  2
         path = (getContextPath() == null) ? "" : getContextPath();
 522  2
         path += ((getServletPath() == null) ? "" : getServletPath());
 523  2
         path += ((getPathInfo() == null) ? "" : getPathInfo());
 524   
 
 525  2
         if (path.length() == 0)
 526   
         {
 527  2
             path = null;
 528   
         }
 529   
 
 530  2
         return path;
 531   
     }
 532   
 
 533   
     /**
 534   
      * Saves the current URL to a <code>WebRequest</code> object.
 535   
      *
 536   
      * @param theRequest the object to which the current URL should be saved to
 537   
      */
 538  1
     public void saveToRequest(WebRequest theRequest)
 539   
     {
 540   
         // Note: All these pareameters are passed in the URL. This is to allow
 541   
         // the user to send whatever he wants in the request body. For example
 542   
         // a file, ...
 543  1
         theRequest.addParameter(URL_PROTOCOL_PARAM, getProtocol(), 
 544   
             WebRequest.GET_METHOD);
 545   
 
 546  1
         if (getServerName() != null)
 547   
         {
 548  1
             theRequest.addParameter(URL_SERVER_NAME_PARAM, getServerName(), 
 549   
                 WebRequest.GET_METHOD);
 550   
         }
 551   
 
 552  1
         if (getContextPath() != null)
 553   
         {
 554  0
             theRequest.addParameter(URL_CONTEXT_PATH_PARAM, getContextPath(), 
 555   
                 WebRequest.GET_METHOD);
 556   
         }
 557   
 
 558  1
         if (getServletPath() != null)
 559   
         {
 560  0
             theRequest.addParameter(URL_SERVLET_PATH_PARAM, getServletPath(), 
 561   
                 WebRequest.GET_METHOD);
 562   
         }
 563   
 
 564  1
         if (getPathInfo() != null)
 565   
         {
 566  0
             theRequest.addParameter(URL_PATH_INFO_PARAM, getPathInfo(), 
 567   
                 WebRequest.GET_METHOD);
 568   
         }
 569   
 
 570  1
         if (getQueryString() != null)
 571   
         {
 572  0
             theRequest.addParameter(URL_QUERY_STRING_PARAM, getQueryString(), 
 573   
                 WebRequest.GET_METHOD);
 574   
         }
 575   
     }
 576   
 
 577   
     /**
 578   
      * Creates a <code>ServletURL</code> object by loading it's values from the
 579   
      * HTTP request.
 580   
      *
 581   
      * @param theRequest the incoming HTTP request.
 582   
      * @return the <code>ServletURL</code> object unserialized from the HTTP
 583   
      *         request
 584   
      */
 585  29
     public static ServletURL loadFromRequest(HttpServletRequest theRequest)
 586   
     {
 587  29
         String qString = theRequest.getQueryString();
 588  29
         boolean isDefined = false;
 589   
 
 590  29
         ServletURL url = new ServletURL();
 591   
 
 592  29
         String protocol = ServletUtil.getQueryStringParameter(qString, 
 593   
             URL_PROTOCOL_PARAM);
 594   
 
 595  29
         if (protocol != null)
 596   
         {
 597  1
             isDefined = true;
 598  1
             url.setProtocol(protocol);
 599   
         }
 600   
 
 601  29
         String serverName = ServletUtil.getQueryStringParameter(qString, 
 602   
             URL_SERVER_NAME_PARAM);
 603   
 
 604  29
         if (serverName != null)
 605   
         {
 606  1
             isDefined = true;
 607  1
             url.setServerName(serverName);
 608   
         }
 609   
 
 610  29
         String contextPath = ServletUtil.getQueryStringParameter(qString, 
 611   
             URL_CONTEXT_PATH_PARAM);
 612   
 
 613  29
         if (contextPath != null)
 614   
         {
 615  0
             isDefined = true;
 616  0
             url.setContextPath(contextPath);
 617   
         }
 618   
 
 619  29
         String servletPath = ServletUtil.getQueryStringParameter(qString, 
 620   
             URL_SERVLET_PATH_PARAM);
 621   
 
 622  29
         if (servletPath != null)
 623   
         {
 624  0
             isDefined = true;
 625  0
             url.setServletPath(servletPath);
 626   
         }
 627   
 
 628  29
         String pathInfo = ServletUtil.getQueryStringParameter(qString, 
 629   
             URL_PATH_INFO_PARAM);
 630   
 
 631  29
         if (pathInfo != null)
 632   
         {
 633  0
             isDefined = true;
 634  0
             url.setPathInfo(pathInfo);
 635   
         }
 636   
 
 637  29
         String queryString = ServletUtil.getQueryStringParameter(qString, 
 638   
             URL_QUERY_STRING_PARAM);
 639   
 
 640  29
         if (queryString != null)
 641   
         {
 642  0
             isDefined = true;
 643  0
             url.setQueryString(queryString);
 644   
         }
 645   
 
 646  29
         if (!isDefined)
 647   
         {
 648  28
             LOGGER.debug("Undefined simulation URL");
 649  28
             url = null;
 650   
         }
 651   
         else
 652   
         {
 653  1
             LOGGER.debug("Simulation URL = [" + url + "]");
 654   
         }
 655   
 
 656  29
         return url;
 657   
     }
 658   
 
 659   
     /**
 660   
      * @return a string representation
 661   
      */
 662  1
     public String toString()
 663   
     {
 664  1
         StringBuffer buffer = new StringBuffer();
 665   
 
 666  1
         buffer.append("protocol = [" + getProtocol() + "], ");
 667  1
         buffer.append("host name = [" + getHost() + "], ");
 668  1
         buffer.append("port = [" + getPort() + "], ");
 669  1
         buffer.append("context path = [" + getContextPath() + "], ");
 670  1
         buffer.append("servlet path = [" + getServletPath() + "], ");
 671  1
         buffer.append("path info = [" + getPathInfo() + "], ");
 672  1
         buffer.append("query string = [" + getQueryString() + "]");
 673   
 
 674  1
         return buffer.toString();
 675   
     }
 676   
 
 677   
     /**
 678   
      * Returns the default port for the protocol.
 679   
      * 
 680   
      * @return the default port (80 for HTTP, 443 for HTTP over SSL)
 681   
      */
 682  3
     private int getDefaultPort()
 683   
     {
 684  3
         if (PROTOCOL_HTTPS.equals(getProtocol()))
 685   
         {
 686  0
             return DEFAULT_PORT_HTTPS;
 687   
         }
 688   
         else
 689   
         {
 690  3
             return DEFAULT_PORT_HTTP;
 691   
         }
 692   
     }
 693   
 
 694   
 }
 695