org.apache.commons.cactus
Class ServletURL

java.lang.Object
  |
  +--org.apache.commons.cactus.ServletURL

public class ServletURL
extends java.lang.Object

Simulate an HTTP URL by breaking it into its different parts :


 URL        = "http://" + serverName (including port) + requestURI ? queryString
requestURI = contextPath + servletPath + pathInfo
From the Servlet 2.2 specification :

Version:
1.1

Field Summary
static java.lang.String URL_CONTEXT_PATH_PARAM
          Name of the parameter in the HTTP request that represents the context path in the URL to simulate.
static java.lang.String URL_PATH_INFO_PARAM
          Name of the parameter in the HTTP request that represents the Path Info in the URL to simulate.
static java.lang.String URL_QUERY_STRING_PARAM
          Name of the parameter in the HTTP request that represents the Query String in the URL to simulate.
static java.lang.String URL_SERVER_NAME_PARAM
          Name of the parameter in the HTTP request that represents the Server name in the URL to simulate.
static java.lang.String URL_SERVLET_PATH_PARAM
          Name of the parameter in the HTTP request that represents the Servlet Path in the URL to simulate.
 
Constructor Summary
ServletURL(java.lang.String theServerName, java.lang.String theContextPath, java.lang.String theServletPath, java.lang.String thePathInfo, java.lang.String theQueryString)
          Creates the URL to simulate.
 
Method Summary
 java.lang.String getContextPath()
           
 java.lang.String getPathInfo()
           
 java.lang.String getQueryString()
           
 java.lang.String getServerName()
           
 java.lang.String getServletPath()
           
 java.net.URL getURL()
           
static ServletURL loadFromRequest(javax.servlet.http.HttpServletRequest theRequest)
          Creates a ServletURL object by loading it's values from the HTTP request.
 void saveToRequest(ServletTestRequest theRequest)
          Saves the current URL to a ServletTestRequest object.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

URL_SERVER_NAME_PARAM

public static final java.lang.String URL_SERVER_NAME_PARAM
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.

URL_CONTEXT_PATH_PARAM

public static final java.lang.String URL_CONTEXT_PATH_PARAM
Name of the parameter in the HTTP request that represents the context path in the URL to simulate. The name is voluntarily long so that it will not clash with a user-defined parameter.

URL_SERVLET_PATH_PARAM

public static final java.lang.String URL_SERVLET_PATH_PARAM
Name of the parameter in the HTTP request that represents the Servlet Path in the URL to simulate. The name is voluntarily long so that it will not clash with a user-defined parameter.

URL_PATH_INFO_PARAM

public static final java.lang.String URL_PATH_INFO_PARAM
Name of the parameter in the HTTP request that represents the Path Info in the URL to simulate. The name is voluntarily long so that it will not clash with a user-defined parameter.

URL_QUERY_STRING_PARAM

public static final java.lang.String URL_QUERY_STRING_PARAM
Name of the parameter in the HTTP request that represents the Query String in the URL to simulate. The name is voluntarily long so that it will not clash with a user-defined parameter.
Constructor Detail

ServletURL

public ServletURL(java.lang.String theServerName,
                  java.lang.String theContextPath,
                  java.lang.String theServletPath,
                  java.lang.String thePathInfo,
                  java.lang.String theQueryString)
Creates the URL to simulate.
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.
Method Detail

getURL

public java.net.URL getURL()
Returns:
the full URL as a URL object.

getServerName

public java.lang.String getServerName()
Returns:
the simulated URL server name (including the port number)

getContextPath

public java.lang.String getContextPath()
Returns:
the simulated URL context path

getServletPath

public java.lang.String getServletPath()
Returns:
the simulated URL servlet path

getPathInfo

public java.lang.String getPathInfo()
Returns:
the simulated URL path info

getQueryString

public java.lang.String getQueryString()
Returns:
the simulated Query String

saveToRequest

public void saveToRequest(ServletTestRequest theRequest)
Saves the current URL to a ServletTestRequest object.
Parameters:
theRequest - the object to which the current URL should be saved to

loadFromRequest

public static ServletURL loadFromRequest(javax.servlet.http.HttpServletRequest theRequest)
Creates a ServletURL object by loading it's values from the HTTP request.
Parameters:
theRequest - the incoming HTTP request.


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