org.apache.cactus
Class ServletURL

java.lang.Object
  |
  +--org.apache.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:
$Id: ServletURL.java,v 1.7 2001/09/14 20:19:52 pier Exp $
Author:
Vincent Massol

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 getHost()
           
 java.lang.String getPath()
           
 java.lang.String getPathInfo()
           
 int getPort()
           
 java.lang.String getQueryString()
           
 java.lang.String getServerName()
           
 java.lang.String getServletPath()
           
static ServletURL loadFromRequest(javax.servlet.http.HttpServletRequest theRequest)
          Creates a ServletURL object by loading it's values from the HTTP request.
 void saveToRequest(WebRequest theRequest)
          Saves the current URL to a WebRequest object.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, 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(). Can be null. If null, then the server name and port from the Servlet Redirector will be returned.
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. If null, then the context from the Servlet Redirector will be returned. 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

getServerName

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

getHost

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

getPort

public int getPort()
Returns:
the port number or -1 if none has been defined or it is a bad port

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

getPath

public java.lang.String getPath()
Returns:
the path (contextPath + servletPath + pathInfo) or null if not set

saveToRequest

public void saveToRequest(WebRequest theRequest)
Saves the current URL to a WebRequest 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.

toString

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


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