Clover coverage report - Cactus 1.4b1 for J2EE API 13
Coverage timestamp: Mon Jul 29 2002 00:34:41 BST
file stats: LOC: 679   Methods: 38
NCLOC: 266   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
WebRequest.java 95% 90.8% 73.7% 88.6%
 1   
 /*   Generated by AspectJ version 1.0.5 */
 2   
 package org.apache.cactus;
 3   
 import java.io.InputStream;
 4   
 import java.util.Enumeration;
 5   
 import java.util.Hashtable;
 6   
 import java.util.StringTokenizer;
 7   
 import java.util.Vector;
 8   
 import org.apache.cactus.client.authentication.AbstractAuthentication;
 9   
 import org.apache.cactus.util.ChainedRuntimeException;
 10   
 
 11   
 /** 
 12   
  * Contains all HTTP request data for a test case. It is the data that 
 13   
  * will be sent to the server redirector and that will be available to the test 
 14   
  * methods through the <code>HttpServletRequest</code> object. 
 15   
  * <br><br> 
 16   
  * Namely, it is : 
 17   
  * <ul> 
 18   
  *   <li>Request parameters that the test case can retrieve using 
 19   
  *       <code>HttpServletRequest.getParameters()</code>,</li> 
 20   
  *   <li>Cookies that the test case can retrieve using 
 21   
  *       <code>HttpServletRequest.getCookies()</code>,</li> 
 22   
  *   <li>HTTP headers that the test case can retrieve using the 
 23   
  *       <code>HttpServletRequest.getHeader(), getHeaders(), 
 24   
  *       ...</code> APIs,</li> 
 25   
  *   <li>URL data the the test case can retrieve using 
 26   
  *       <code>HttpServletRequest.getRequestURI(), ...</code></li> 
 27   
  *   <li>Whether you want the server redirector to automatically create a 
 28   
  *       session for you or not,</li> 
 29   
  *   <li>Whether you want the HTTP connection to the server redirector to 
 30   
  *       use a POST or GET method. Default is POST</li> 
 31   
  *   <li>Authentication to use (optional)</li> 
 32   
  *   <li>Content type (optional)</li> 
 33   
  * </ul> 
 34   
  * 
 35   
  * @author <a href="mailto:vmassol@apache.org">Vincent Massol</a> 
 36   
  * @author <a href="mailto:Jason.Robertson@acs-inc.com">Jason Robertson</a> 
 37   
  * 
 38   
  * @version $Id: WebRequest.java,v 1.5 2002/07/26 18:50:29 vmassol Exp $ 
 39   
  */
 40   
 public class WebRequest implements Request {
 41   
   /** 
 42   
        * The request parameters that need to be sent in the body (POST) 
 43   
        */
 44   
   private Hashtable parametersPost;
 45   
   /** 
 46   
        * The request parameters that need to be sent in the URL (GET) 
 47   
        */
 48   
   private Hashtable parametersGet;
 49   
   /** 
 50   
        * GET Method identifier. 
 51   
        */
 52   
   public static final String GET_METHOD = "GET";
 53   
   /** 
 54   
        * POST Method identifier. 
 55   
        */
 56   
   public static final String POST_METHOD = "POST";
 57   
   /** 
 58   
        * The Cookies 
 59   
        */
 60   
   private Vector cookies;
 61   
   /** 
 62   
        * HTTP Headers. 
 63   
        */
 64   
   private Hashtable headers;
 65   
   /** 
 66   
        * The URL to simulate 
 67   
        */
 68   
   private ServletURL url;
 69   
   /** 
 70   
        * Automatic session creation flag (default is true). 
 71   
        */
 72   
   private boolean isAutomaticSession;
 73   
   /** 
 74   
        * Binary data to send in the request body (if any) 
 75   
        */
 76   
   private InputStream dataStream;
 77   
   /** 
 78   
        * The content type to set in the http request 
 79   
        */
 80   
   private String contentType;
 81   
   /** 
 82   
        * The Authentication Object that will configure the http request 
 83   
        */
 84   
   private AbstractAuthentication authentication;
 85   
   /** 
 86   
        * Redirector Name. This is to let the user the possibility to override 
 87   
        * the default Redirector Name specified in <code>cactus.properties</code>. 
 88   
        */
 89   
   private String redirectorName;
 90   
   /** 
 91   
        * Override the redirector Name defined in <code>cactus.properties</code>. 
 92   
        * This is useful to define a per test case Name (for example, if some 
 93   
        * test case need to have authentication turned on and not other tests, 
 94   
        * etc). 
 95   
        * 
 96   
        * @param theRedirectorName the new redirector Name to use 
 97   
        */
 98  0
   public void setRedirectorName(String theRedirectorName) {
 99  0
     this.redirectorName = theRedirectorName;
 100   
   } 
 101   
 
 102   
   /** 
 103   
        * @return the overriden redirector Name or null if none has been defined 
 104   
        */
 105  0
   public String getRedirectorName() {
 106  0
     return this.redirectorName;
 107   
   } 
 108   
 
 109   
   /** 
 110   
        * Sets the authentication object that will configure the http request 
 111   
        * 
 112   
        * @param theAuthenticationObject the authentication object 
 113   
        */
 114  0
   public void setAuthentication(AbstractAuthentication theAuthenticationObject) {
 115  0
     this.authentication = theAuthenticationObject;
 116   
   } 
 117   
 
 118   
   /** 
 119   
        * @return the authentication object that will configure the http request 
 120   
        */
 121  0
   public AbstractAuthentication getAuthentication() {
 122  0
     return this.authentication;
 123   
   } 
 124   
 
 125   
   /** 
 126   
        * Sets the content type that will be set in the http request 
 127   
        * 
 128   
        * @param theContentType the content type 
 129   
        */
 130  0
   public void setContentType(String theContentType) {
 131  0
     this.contentType = theContentType;
 132   
   } 
 133   
 
 134   
   /** 
 135   
        * @return the content type that will be set in the http request 
 136   
        */
 137  0
   public String getContentType() {
 138  0
     return this.contentType;
 139   
   } 
 140   
 
 141   
   /** 
 142   
        * Allow the user to send arbitrary data in the request body 
 143   
        * 
 144   
        * @param theDataStream the stream on which the data are put by the user 
 145   
        */
 146  0
   public void setUserData(InputStream theDataStream) {
 147  0
     this.dataStream = theDataStream;
 148   
   } 
 149   
 
 150   
   /** 
 151   
        * @return the data stream set up by the user 
 152   
        */
 153  0
   public InputStream getUserData() {
 154  0
     return this.dataStream;
 155   
   } 
 156   
 
 157   
   /** 
 158   
        * @param isAutomaticSession whether the redirector servlet will 
 159   
        *        automatically create the HTTP session or not. Default is true. 
 160   
        */
 161  1
   public void setAutomaticSession(boolean isAutomaticSession) {
 162  1
     this.isAutomaticSession = isAutomaticSession;
 163   
   } 
 164   
 
 165   
   /** 
 166   
        * @return true if session will be automatically created for the user or 
 167   
        *         false otherwise. 
 168   
        */
 169  1
   public boolean getAutomaticSession() {
 170  1
     return this.isAutomaticSession;
 171   
   } 
 172   
 
 173   
   /** 
 174   
        * Sets the simulated URL. A URL is of the form :<br> 
 175   
        * <code><pre><b> 
 176   
        * URL = "http://" + serverName (including port) + requestURI ? queryString 
 177   
        * <br>requestURI = contextPath + servletPath + pathInfo 
 178   
        * </b></pre></code> 
 179   
        * From the Servlet 2.2 specification :<br> 
 180   
        * <code><pre><ul> 
 181   
        * <li><b>Context Path</b>: The path prefix associated with the 
 182   
        *   ServletContext that this servlet is a part of. If this context is the 
 183   
        *   default context rooted at the base of the web server's URL namespace, 
 184   
        *   this path will be an empty string. Otherwise, this path starts with a 
 185   
        *   character but does not end with a character.</li> 
 186   
        * <li><b>Servlet Path</b>: The path section that directly corresponds to 
 187   
        *   the mapping which activated this request. This path starts with a 
 188   
        *   character.</li> 
 189   
        * <li><b>PathInfo</b>: The part of the request path that is not part of the 
 190   
        *   Context Path or the Servlet Path.</li> 
 191   
        * </ul></pre></code> 
 192   
        * 
 193   
        * @param theServerName the server name (and port) in the URL to simulate, 
 194   
        *                      i.e. this is the name that will be returned by the 
 195   
        *                      <code>HttpServletRequest.getServerName()</code> and 
 196   
        *                      <code>HttpServletRequest.getServerPort()</code>. 
 197   
        * @param theContextPath the webapp context path in the URL to simulate, 
 198   
        *                      i.e. this is the name that will be returned by the 
 199   
        *                      <code>HttpServletRequest.getContextPath()</code>. 
 200   
        *                      Can be null. Format: "/" + name or an empty string 
 201   
        *                      for the default context. 
 202   
        * @param theServletPath the servlet path in the URL to simulate, 
 203   
        *                      i.e. this is the name that will be returned by the 
 204   
        *                      <code>HttpServletRequest.getServletPath()</code>. 
 205   
        *                      Can be null. Format : "/" + name. 
 206   
        * @param thePathInfo   the path info in the URL to simulate, i.e. this is 
 207   
        *                      the name that will be returned by the 
 208   
        *                      <code>HttpServletRequest.getPathInfo()</code>. Can 
 209   
        *                      be null. Format : "/" + name. 
 210   
        * @param theQueryString the Query string in the URL to simulate, i.e. this 
 211   
        *                       is the string that will be returned by the 
 212   
        *                       <code>HttpServletResquest.getQueryString()</code>. 
 213   
        *                       Can be null. 
 214   
        */
 215  2
   public void setURL(String theServerName, String theContextPath, String theServletPath, 
 216   
       String thePathInfo, String theQueryString) {
 217  2
     this.url = new ServletURL(theServerName, theContextPath, theServletPath, thePathInfo, 
 218   
         theQueryString);
 219  2
     this.addQueryStringParameters(theQueryString);
 220   
   } 
 221   
 
 222   
   /** 
 223   
        * @return the simulated URL 
 224   
        */
 225  1
   public ServletURL getURL() {
 226  1
     return this.url;
 227   
   } 
 228   
 
 229   
   /** 
 230   
        * Adds a parameter to the request. It is possible to add several times the 
 231   
        * the same parameter name, but with different value (the same as for the 
 232   
        * <code>HttpServletRequest</code>). 
 233   
        * 
 234   
        * @param theName the parameter's name 
 235   
        * @param theValue the parameter's value 
 236   
        * @param theMethod GET_METHOD or POST_METHOD. If GET_METHOD then the 
 237   
        *        parameter will be sent in the query string of the URL. If 
 238   
        *        POST_METHOD, it will be sent as a parameter in the request body. 
 239   
        */
 240  12
   public void addParameter(String theName, String theValue, String theMethod) {
 241  12
     Hashtable parameters;
 242  12
     if (theMethod.equalsIgnoreCase("POST")) {
 243  4
       parameters = this.parametersPost;
 244  8
     } else if (theMethod.equalsIgnoreCase("GET")) {
 245  7
       parameters = this.parametersGet;
 246   
     } else {
 247  1
       throw new ChainedRuntimeException("The method need to be either \"POST\" or \"GET\"");
 248   
     } 
 249  11
     if (parameters.containsKey(theName)) {
 250  3
       Vector v = (Vector)parameters.get(theName);
 251  3
       v.addElement(theValue);
 252   
     } else {
 253  8
       Vector v = new Vector();
 254  8
       v.addElement(theValue);
 255  8
       parameters.put(theName, v);
 256   
     } 
 257   
   } 
 258   
 
 259   
   /** 
 260   
        * Adds a parameter to the request. The parameter is added to the query 
 261   
        * string of the URL. 
 262   
        * 
 263   
        * @param theName  the parameter's name 
 264   
        * @param theValue the parameter's value 
 265   
        * 
 266   
        * @see #addParameter(String, String, String) 
 267   
        */
 268  3
   public void addParameter(String theName, String theValue) {
 269  3
     this.addParameter(theName, theValue, "GET");
 270   
   } 
 271   
 
 272   
   /** 
 273   
        * @return the parameter names that will be passed in the request body 
 274   
        * (POST) 
 275   
        */
 276  0
   public Enumeration getParameterNamesPost() {
 277  0
     return this.getParameterNames(this.parametersPost);
 278   
   } 
 279   
 
 280   
   /** 
 281   
        * @return the parameter names that will be passed in the URL (GET) 
 282   
        */
 283  0
   public Enumeration getParameterNamesGet() {
 284  0
     return this.getParameterNames(this.parametersGet);
 285   
   } 
 286   
 
 287   
   /** 
 288   
        * Returns all the values in the passed hashtable of parameters. 
 289   
        * 
 290   
        * @param theParameters the hashtable of parameters 
 291   
        * @return the parameter names 
 292   
        */
 293  2
   private Enumeration getParameterNames(Hashtable theParameters) {
 294  2
     return theParameters.keys();
 295   
   } 
 296   
 
 297   
   /** 
 298   
        * Returns the first value corresponding to this parameter's name (provided 
 299   
        * this parameter is passed in the URL). 
 300   
        * 
 301   
        * @param theName the parameter's name 
 302   
        * @return the first value corresponding to this parameter's name or null 
 303   
        *         if not found in the list of parameters to be sent in the URL 
 304   
        */
 305  2
   public String getParameterGet(String theName) {
 306  2
     String[] values = this.getParameterValuesGet(theName);
 307  2
     if (values != null) {
 308  1
       return values[0];
 309   
     } 
 310  1
     return ((String)(null));
 311   
   } 
 312   
 
 313   
   /** 
 314   
        * Returns the first value corresponding to this parameter's name (provided 
 315   
        * this parameter is passed in the request body - POST). 
 316   
        * 
 317   
        * @param theName the parameter's name 
 318   
        * @return the first value corresponding to this parameter's name or null 
 319   
        *         if not found in the list of parameters to be sent in the request 
 320   
        *         body 
 321   
        */
 322  2
   public String getParameterPost(String theName) {
 323  2
     String[] values = this.getParameterValuesPost(theName);
 324  2
     if (values != null) {
 325  1
       return values[0];
 326   
     } 
 327  1
     return ((String)(null));
 328   
   } 
 329   
 
 330   
   /** 
 331   
        * Returns all the values corresponding to this parameter's name (provided 
 332   
        * this parameter is passed in the URL). 
 333   
        * 
 334   
        * @param theName the parameter's name 
 335   
        * @return the first value corresponding to this parameter's name or null 
 336   
        *         if not found in the list of parameters to be sent in the URL 
 337   
        */
 338  2
   public String[] getParameterValuesGet(String theName) {
 339  2
     return this.getParameterValues(theName, this.parametersGet);
 340   
   } 
 341   
 
 342   
   /** 
 343   
        * Returns all the values corresponding to this parameter's name (provided 
 344   
        * this parameter is passed in the request body - POST). 
 345   
        * 
 346   
        * @param theName the parameter's name 
 347   
        * @return the first value corresponding to this parameter's name or null 
 348   
        *         if not found in the list of parameters to be sent in the request 
 349   
        *         body 
 350   
        */
 351  2
   public String[] getParameterValuesPost(String theName) {
 352  2
     return this.getParameterValues(theName, this.parametersPost);
 353   
   } 
 354   
 
 355   
   /** 
 356   
        * Returns all the values corresponding to this parameter's name in the 
 357   
        * provided hashtable. 
 358   
        * 
 359   
        * @param theName the parameter's name 
 360   
        * @param theParameters the hashtable containing the parameters 
 361   
        * @return the first value corresponding to this parameter's name or null 
 362   
        *         if not found in the passed hashtable 
 363   
        */
 364  8
   private String[] getParameterValues(String theName, Hashtable theParameters) {
 365  8
     if (theParameters.containsKey(theName)) {
 366  6
       Vector v = (Vector)theParameters.get(theName);
 367  6
       Object[] objs = new java.lang.Object[v.size()];
 368  6
       v.copyInto(objs);
 369  6
       String[] result = new java.lang.String[objs.length];
 370  6
       for (int i = 0; i < objs.length; i++) {
 371  9
         result[i] = (String)objs[i];
 372   
       } 
 373  6
       return result;
 374   
     } 
 375  2
     return ((java.lang.String[])(null));
 376   
   } 
 377   
 
 378   
   /** 
 379   
        * Adds a cookie to the request. The cookie will be created with a 
 380   
        * default localhost domain. Use the 
 381   
        * <code>addCookie(String theDomain, String theName, 
 382   
        * String theValue)</code> method or the 
 383   
        * <code>addCookie(Cookie theCookie)</code> if you wish to specify a 
 384   
        * domain. 
 385   
        * 
 386   
        * Note that the domain must match either the redirector host 
 387   
        * (specified in <code>cactus.properties</code>) or the host set 
 388   
        * using <code>setURL()</code>. 
 389   
        * 
 390   
        * @param theName the cookie's name 
 391   
        * @param theValue the cookie's value 
 392   
        */
 393  1
   public void addCookie(String theName, String theValue) {
 394  1
     this.addCookie("localhost", theName, theValue);
 395   
   } 
 396   
 
 397   
   /** 
 398   
        * Adds a cookie to the request. The cookie will be created with the 
 399   
        * domain passed as parameter (i.e. the cookie will get sent only to 
 400   
        * requests to that domain). 
 401   
        * 
 402   
        * Note that the domain must match either the redirector host 
 403   
        * (specified in <code>cactus.properties</code>) or the host set 
 404   
        * using <code>setURL()</code>. 
 405   
        * 
 406   
        * @param theDomain the cookie domain 
 407   
        * @param theName the cookie name 
 408   
        * @param theValue the cookie value 
 409   
        */
 410  1
   public void addCookie(String theDomain, String theName, String theValue) {
 411  1
     this.addCookie(new Cookie(theDomain, theName, theValue));
 412   
   } 
 413   
 
 414   
   /** 
 415   
        * Adds a cookie to the request. 
 416   
        * 
 417   
        * Note that the domain must match either the redirector host 
 418   
        * (specified in <code>cactus.properties</code>) or the host set 
 419   
        * using <code>setURL()</code>. 
 420   
        * 
 421   
        * @param theCookie the cookie to add 
 422   
        */
 423  1
   public void addCookie(Cookie theCookie) {
 424  1
     this.cookies.addElement(theCookie);
 425   
   } 
 426   
 
 427   
   /** 
 428   
        * @return the cookies (vector of <code>Cookie</code> objects) 
 429   
        */
 430  1
   public Vector getCookies() {
 431  1
     return this.cookies;
 432   
   } 
 433   
 
 434   
   /** 
 435   
        * Adds a header to the request. Supports adding several values for the 
 436   
        * same header name. 
 437   
        * 
 438   
        * @param theName  the header's name 
 439   
        * @param theValue the header's value 
 440   
        */
 441  4
   public void addHeader(String theName, String theValue) {
 442  4
     if (theName.equalsIgnoreCase("Content-type")) {
 443  0
       this.setContentType(theValue);
 444  0
       return;
 445   
     } 
 446  4
     if (this.headers.containsKey(theName)) {
 447  1
       Vector v = (Vector)this.headers.get(theName);
 448  1
       v.addElement(theValue);
 449   
     } else {
 450  3
       Vector v = new Vector();
 451  3
       v.addElement(theValue);
 452  3
       this.headers.put(theName, v);
 453   
     } 
 454   
   } 
 455   
 
 456   
   /** 
 457   
        * @return the header names 
 458   
        */
 459  1
   public Enumeration getHeaderNames() {
 460  1
     return this.headers.keys();
 461   
   } 
 462   
 
 463   
   /** 
 464   
        * Returns the first value corresponding to this header's name. 
 465   
        * 
 466   
        * @param  theName the header's name 
 467   
        * @return the first value corresponding to this header's name or null if 
 468   
        *         not found 
 469   
        */
 470  2
   public String getHeader(String theName) {
 471  2
     String[] values = this.getHeaderValues(theName);
 472  2
     if (values != null) {
 473  1
       return values[0];
 474   
     } 
 475  1
     return ((String)(null));
 476   
   } 
 477   
 
 478   
   /** 
 479   
        * Returns all the values associated with this header's name. 
 480   
        * 
 481   
        * @param  theName the header's name 
 482   
        * @return the values corresponding to this header's name or null if not 
 483   
        *         found 
 484   
        */
 485  3
   public String[] getHeaderValues(String theName) {
 486  3
     if (this.headers.containsKey(theName)) {
 487  2
       Vector v = (Vector)this.headers.get(theName);
 488  2
       Object[] objs = new java.lang.Object[v.size()];
 489  2
       v.copyInto(objs);
 490  2
       String[] result = new java.lang.String[objs.length];
 491  2
       for (int i = 0; i < objs.length; i++) {
 492  3
         result[i] = (String)objs[i];
 493   
       } 
 494  2
       return result;
 495   
     } 
 496  1
     return ((java.lang.String[])(null));
 497   
   } 
 498   
 
 499   
   /** 
 500   
        * Extract the HTTP parameters that might have been specified on the 
 501   
        * query string and add them to the list of parameters to pass to the 
 502   
        * servlet redirector. 
 503   
        * 
 504   
        * @param theQueryString the Query string in the URL to simulate, i.e. this 
 505   
        *                       is the string that will be returned by the 
 506   
        *                       <code>HttpServletResquest.getQueryString()</code>. 
 507   
        *                       Can be null. 
 508   
        */
 509  2
   private void addQueryStringParameters(String theQueryString) {
 510  2
     if (theQueryString == null) {
 511  0
       return;
 512   
     } 
 513  2
     String nameValue = null;
 514  2
     StringTokenizer tokenizer = new StringTokenizer(theQueryString, "&");
 515  2
     int breakParam = -1;
 516  2
     while (tokenizer.hasMoreTokens()){
 517  4
       nameValue = tokenizer.nextToken();
 518  4
       breakParam = nameValue.indexOf("=");
 519  4
       if (breakParam != -1) {
 520  3
         this.addParameter(nameValue.substring(0, breakParam), nameValue.substring(breakParam + 1));
 521   
       } else {
 522  1
         throw new RuntimeException("Bad QueryString [" + theQueryString + "] NameValue pair: [" + 
 523   
             nameValue + "]");
 524   
       } 
 525   
     } 
 526   
   } 
 527   
 
 528   
   /** 
 529   
        * @return a string representation of the request 
 530   
        */
 531  1
   public String toString() {
 532  1
     StringBuffer buffer = new StringBuffer();
 533  1
     buffer.append("simulation URL = [" + this.getURL() + "], ");
 534  1
     buffer.append("automatic session = [" + this.getAutomaticSession() + "], ");
 535  1
     buffer.append("cookies = [");
 536  1
     buffer.append(this.toStringAppendCookies());
 537  1
     buffer.append("], ");
 538  1
     buffer.append("headers = [");
 539  1
     buffer.append(this.toStringAppendHeaders());
 540  1
     buffer.append("], ");
 541  1
     buffer.append("GET parameters = [");
 542  1
     buffer.append(this.toStringAppendParametersGet());
 543  1
     buffer.append("], ");
 544  1
     buffer.append("POST parameters = [");
 545  1
     buffer.append(this.toStringAppendParametersPost());
 546  1
     buffer.append("]");
 547  1
     return buffer.toString();
 548   
   } 
 549   
 
 550   
   /** 
 551   
        * @return a string representation of the headers 
 552   
        */
 553  1
   private String toStringAppendHeaders() {
 554  1
     StringBuffer buffer = new StringBuffer();
 555  1
     Enumeration headers = this.getHeaderNames();
 556  1
     while (headers.hasMoreElements()){
 557  1
       buffer.append("[");
 558  1
       String headerName = (String)headers.nextElement();
 559  1
       String[] headerValues = this.getHeaderValues(headerName);
 560  1
       buffer.append("[" + headerName + "] = [");
 561  1
       for (int i = 0; i < headerValues.length - 1; i++) {
 562  1
         buffer.append("[" + headerValues[i] + "], ");
 563   
       } 
 564  1
       buffer.append("[" + headerValues[headerValues.length - 1] + "]]");
 565  1
       buffer.append("]");
 566   
     } 
 567  1
     return buffer.toString();
 568   
   } 
 569   
 
 570   
   /** 
 571   
        * @return a string representation of the cookies 
 572   
        */
 573  1
   private String toStringAppendCookies() {
 574  1
     StringBuffer buffer = new StringBuffer();
 575  1
     Enumeration cookies = this.getCookies().elements();
 576  1
     while (cookies.hasMoreElements()){
 577  1
       Cookie cookie = (Cookie)cookies.nextElement();
 578  1
       buffer.append("[" + cookie + "]");
 579   
     } 
 580  1
     return buffer.toString();
 581   
   } 
 582   
 
 583   
   /** 
 584   
        * @return a string representation of the parameters to be added in the 
 585   
        *         request body 
 586   
        */
 587  1
   private String toStringAppendParametersPost() {
 588  1
     return this.toStringAppendParameters(this.parametersPost);
 589   
   } 
 590   
 
 591   
   /** 
 592   
        * @return a string representation of the parameters to be added in the 
 593   
        *         URL 
 594   
        */
 595  1
   private String toStringAppendParametersGet() {
 596  1
     return this.toStringAppendParameters(this.parametersGet);
 597   
   } 
 598   
 
 599   
   /** 
 600   
        * @param theParameters the HTTP parameters 
 601   
        * @return a string representation of the HTTP parameters passed as 
 602   
        *         parameters 
 603   
        */
 604  2
   private String toStringAppendParameters(Hashtable theParameters) {
 605  2
     StringBuffer buffer = new StringBuffer();
 606  2
     Enumeration parameters = this.getParameterNames(theParameters);
 607  2
     while (parameters.hasMoreElements()){
 608  4
       buffer.append("[");
 609  4
       String parameterName = (String)parameters.nextElement();
 610  4
       String[] parameterValues = this.getParameterValues(parameterName, theParameters);
 611  4
       buffer.append("[" + parameterName + "] = [");
 612  4
       for (int i = 0; i < parameterValues.length - 1; i++) {
 613  1
         buffer.append("[" + parameterValues[i] + "], ");
 614   
       } 
 615  4
       buffer.append("[" + parameterValues[parameterValues.length - 1] + "]]");
 616  4
       buffer.append("]");
 617   
     } 
 618  2
     return buffer.toString();
 619   
   } 
 620   
 
 621   
   /** 
 622   
    * Contains all HTTP request data for a test case. It is the data that 
 623   
    * will be sent to the server redirector and that will be available to the test 
 624   
    * methods through the <code>HttpServletRequest</code> object. 
 625   
    * <br><br> 
 626   
    * Namely, it is : 
 627   
    * <ul> 
 628   
    *   <li>Request parameters that the test case can retrieve using 
 629   
    *       <code>HttpServletRequest.getParameters()</code>,</li> 
 630   
    *   <li>Cookies that the test case can retrieve using 
 631   
    *       <code>HttpServletRequest.getCookies()</code>,</li> 
 632   
    *   <li>HTTP headers that the test case can retrieve using the 
 633   
    *       <code>HttpServletRequest.getHeader(), getHeaders(), 
 634   
    *       ...</code> APIs,</li> 
 635   
    *   <li>URL data the the test case can retrieve using 
 636   
    *       <code>HttpServletRequest.getRequestURI(), ...</code></li> 
 637   
    *   <li>Whether you want the server redirector to automatically create a 
 638   
    *       session for you or not,</li> 
 639   
    *   <li>Whether you want the HTTP connection to the server redirector to 
 640   
    *       use a POST or GET method. Default is POST</li> 
 641   
    *   <li>Authentication to use (optional)</li> 
 642   
    *   <li>Content type (optional)</li> 
 643   
    * </ul> 
 644   
    * 
 645   
    * @author <a href="mailto:vmassol@apache.org">Vincent Massol</a> 
 646   
    * @author <a href="mailto:Jason.Robertson@acs-inc.com">Jason Robertson</a> 
 647   
    * 
 648   
    * @version $Id: WebRequest.java,v 1.5 2002/07/26 18:50:29 vmassol Exp $ 
 649   
    */
 650  21
   public WebRequest() {
 651  21
     super();
 652   
     {
 653   
       /** 
 654   
            * The request parameters that need to be sent in the body (POST) 
 655   
            */
 656  21
       this.parametersPost = new Hashtable();
 657   
       /** 
 658   
            * The request parameters that need to be sent in the URL (GET) 
 659   
            */
 660  21
       this.parametersGet = new Hashtable();
 661   
       /** 
 662   
            * The Cookies 
 663   
            */
 664  21
       this.cookies = new Vector();
 665   
       /** 
 666   
            * HTTP Headers. 
 667   
            */
 668  21
       this.headers = new Hashtable();
 669   
       /** 
 670   
            * Automatic session creation flag (default is true). 
 671   
            */
 672  21
       this.isAutomaticSession = true;
 673   
       /** 
 674   
            * The content type to set in the http request 
 675   
            */
 676  21
       this.contentType = "application/x-www-form-urlencoded";
 677   
     } 
 678   
   } 
 679   
 }