org.apache.cactus
Class WebRequest

java.lang.Object
  |
  +--org.apache.cactus.WebRequest
Direct Known Subclasses:
ServletTestRequest

public class WebRequest
extends java.lang.Object

Contains all HTTP request data for a test case. It is the data that will be sent to the server redirector and that will be available to the test methods through the HttpServletRequest object.

Namely, it is :

Version:
$Id: WebRequest.java,v 1.5 2001/09/14 20:21:23 pier Exp $
Author:
Vincent Massol

Field Summary
static java.lang.String GET_METHOD
          GET Method identifier.
static java.lang.String POST_METHOD
          POST Method identifier.
 
Constructor Summary
WebRequest()
           
 
Method Summary
 void addCookie(Cookie theCookie)
          Adds a cookie to the request.
 void addCookie(java.lang.String theName, java.lang.String theValue)
          Adds a cookie to the request.
 void addCookie(java.lang.String theDomain, java.lang.String theName, java.lang.String theValue)
          Adds a cookie to the request.
 void addHeader(java.lang.String theName, java.lang.String theValue)
          Adds a header to the request.
 void addParameter(java.lang.String theName, java.lang.String theValue)
          Adds a parameter to the request.
 boolean getAutomaticSession()
           
 java.util.Vector getCookies()
           
 java.lang.String getHeader(java.lang.String theName)
          Returns the first value corresponding to this header's name.
 java.util.Enumeration getHeaderNames()
           
 java.lang.String[] getHeaderValues(java.lang.String theName)
          Returns all the values associated with this header's name.
 java.lang.String getMethod()
           
 java.lang.String getParameter(java.lang.String theName)
          Returns the first value corresponding to this parameter's name.
 java.util.Enumeration getParameterNames()
           
 java.lang.String[] getParameterValues(java.lang.String theName)
          Returns all the values associated with this parameter's name.
 ServletURL getURL()
           
 void setAutomaticSession(boolean isAutomaticSession)
           
 void setMethod(java.lang.String theMethod)
           
 void setURL(java.lang.String theServerName, java.lang.String theContextPath, java.lang.String theServletPath, java.lang.String thePathInfo, java.lang.String theQueryString)
          Sets the simulated URL.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

GET_METHOD

public static final java.lang.String GET_METHOD
GET Method identifier.

POST_METHOD

public static final java.lang.String POST_METHOD
POST Method identifier.
Constructor Detail

WebRequest

public WebRequest()
Method Detail

setMethod

public void setMethod(java.lang.String theMethod)
Parameters:
theMethod - the method to use to post data (GET or POST)

getMethod

public java.lang.String getMethod()
Returns:
the method to use for posting data to the server redirector.

setAutomaticSession

public void setAutomaticSession(boolean isAutomaticSession)
Parameters:
isAutomaticSession - whether the redirector servlet will automatically create the HTTP session or not. Default is true.

getAutomaticSession

public boolean getAutomaticSession()
Returns:
true if session will be automatically created for the user or false otherwise.

setURL

public void setURL(java.lang.String theServerName,
                   java.lang.String theContextPath,
                   java.lang.String theServletPath,
                   java.lang.String thePathInfo,
                   java.lang.String theQueryString)
Sets the simulated URL. A URL is of the form :

 URL        = "http://" + serverName (including port) + requestURI ? queryString
requestURI = contextPath + servletPath + pathInfo
From the Servlet 2.2 specification :
  • Context Path: The path prefix associated with the ServletContext that this servlet is a part of. If this context is the default context rooted at the base of the web server's URL namespace, this path will be an empty string. Otherwise, this path starts with a character but does not end with a character.
  • Servlet Path: The path section that directly corresponds to the mapping which activated this request. This path starts with a character.
  • PathInfo: The part of the request path that is not part of the Context Path or the Servlet Path.
Parameters:
theServerName - the server name (and port) in the URL to simulate, i.e. this is the name that will be returned by the HttpServletRequest.getServerName() and HttpServletRequest.getServerPort().
theContextPath - the webapp context path in the URL to simulate, i.e. this is the name that will be returned by the HttpServletRequest.getContextPath(). Can be null. Format: "/" + name or an empty string for the default context.
theServletPath - the servlet path in the URL to simulate, i.e. this is the name that will be returned by the HttpServletRequest.getServletPath(). Can be null. Format : "/" + name.
thePathInfo - the path info in the URL to simulate, i.e. this is the name that will be returned by the HttpServletRequest.getPathInfo(). Can be null. Format : "/" + name.
theQueryString - the Query string in the URL to simulate, i.e. this is the string that will be returned by the HttpServletResquest.getQueryString(). Can be null.

getURL

public ServletURL getURL()
Returns:
the simulated URL

addParameter

public void addParameter(java.lang.String theName,
                         java.lang.String theValue)
Adds a parameter to the request. It is possible to add several times the the same parameter name (the same as for the HttpServletRequest).
Parameters:
theName - the parameter's name
theValue - the parameter's value

getParameterNames

public java.util.Enumeration getParameterNames()
Returns:
the parameter names

getParameter

public java.lang.String getParameter(java.lang.String theName)
Returns the first value corresponding to this parameter's name.
Parameters:
theName - the parameter's name
Returns:
the first value corresponding to this parameter's name or null if not found

getParameterValues

public java.lang.String[] getParameterValues(java.lang.String theName)
Returns all the values associated with this parameter's name.
Parameters:
theName - the parameter's name
Returns:
the values corresponding to this parameter's name or null if not found

addCookie

public void addCookie(java.lang.String theName,
                      java.lang.String theValue)
Adds a cookie to the request. The cookie will be created with a default localhost domain. Use the addCookie(String theDomain, String theName, String theValue) method or the addCookie(Cookie theCookie) if you wish to specify a domain. Note that the domain must match either the redirector host (specified in cactus.properties) or the host set using setURL().
Parameters:
theName - the cookie's name
theValue - the cookie's value

addCookie

public void addCookie(java.lang.String theDomain,
                      java.lang.String theName,
                      java.lang.String theValue)
Adds a cookie to the request. The cookie will be created with the domain passed as parameter (i.e. the cookie will get sent only to requests to that domain). Note that the domain must match either the redirector host (specified in cactus.properties) or the host set using setURL().
Parameters:
theDomain - the cookie domain
theName - the cookie name
theValue - the cookie value

addCookie

public void addCookie(Cookie theCookie)
Adds a cookie to the request. Note that the domain must match either the redirector host (specified in cactus.properties) or the host set using setURL().
Parameters:
theCookie - the cookie to add

getCookies

public java.util.Vector getCookies()
Returns:
the cookies (vector of Cookie objects)

addHeader

public void addHeader(java.lang.String theName,
                      java.lang.String theValue)
Adds a header to the request. Supports adding several values for the same header name.
Parameters:
theName - the header's name
theValue - the header's value

getHeaderNames

public java.util.Enumeration getHeaderNames()
Returns:
the header names

getHeader

public java.lang.String getHeader(java.lang.String theName)
Returns the first value corresponding to this header's name.
Parameters:
theName - the header's name
Returns:
the first value corresponding to this header's name or null if not found

getHeaderValues

public java.lang.String[] getHeaderValues(java.lang.String theName)
Returns all the values associated with this header's name.
Parameters:
theName - the header's name
Returns:
the values corresponding to this header's name or null if not found

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
Returns:
a string representation of the request


Copyright © 2000-2001 Apache Software Foundation. All Rights Reserved.