org.apache.cactus
class ServletURL

java.lang.Object
  |
  +--org.apache.cactus.ServletURL
Known Advisors:
LogAspect

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.3 2002/04/14 10:46:25 vmassol Exp $
Author:
Vincent Massol

Field Summary
static String PROTOCOL_HTTP
          Http protocol.
          
static String PROTOCOL_HTTPS
          Https protocol.
          
static String URL_CONTEXT_PATH_PARAM
          Name of the parameter in the HTTP request that represents the context path in the URL to simulate.
          
static String URL_PATH_INFO_PARAM
          Name of the parameter in the HTTP request that represents the Path Info in the URL to simulate.
          
static String URL_PROTOCOL_PARAM
          Name of the parameter in the HTTP request that represents the protocol (HTTP, HTTPS, etc) in the URL to simulate.
          
static String URL_QUERY_STRING_PARAM
          Name of the parameter in the HTTP request that represents the Query String in the URL to simulate.
          
static String URL_SERVER_NAME_PARAM
          Name of the parameter in the HTTP request that represents the Server name (+ port) in the URL to simulate.
          
static 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(String theProtocol, String theServerName, String theContextPath, String theServletPath, String thePathInfo, String theQueryString)
          Creates the URL to simulate.
ServletURL(String theServerName, String theContextPath, String theServletPath, String thePathInfo, String theQueryString)
          Creates the URL to simulate, using the default HTTP protocol.
 
Method Summary
 String getContextPath()
           
 String getHost()
           
 String getPath()
           
 String getPathInfo()
           
 int getPort()
           
 String getProtocol()
           
 String getQueryString()
           
 String getServerName()
           
 String getServletPath()
           
static ServletURL loadFromRequest(HttpServletRequest theRequest)
          Creates a ServletURL object by loading it's values from the HTTP request.
          Affected by: LogAspect
 void saveToRequest(WebRequest theRequest)
          Saves the current URL to a WebRequest object.
          Affected by: LogAspect
 String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

PROTOCOL_HTTP

public static final String PROTOCOL_HTTP
Http protocol.

PROTOCOL_HTTPS

public static final String PROTOCOL_HTTPS
Https protocol.

URL_CONTEXT_PATH_PARAM

public static final 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_PATH_INFO_PARAM

public static final 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_PROTOCOL_PARAM

public static final String URL_PROTOCOL_PARAM
Name of the parameter in the HTTP request that represents the protocol (HTTP, HTTPS, etc) 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 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.

URL_SERVER_NAME_PARAM

public static final String URL_SERVER_NAME_PARAM
Name of the parameter in the HTTP request that represents the Server name (+ port) 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 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.
Constructor Detail

ServletURL

public ServletURL(String theProtocol,
                  String theServerName,
                  String theContextPath,
                  String theServletPath,
                  String thePathInfo,
                  String theQueryString)
Creates the URL to simulate.
Parameters:
theProtocol - the protocol to simulate (either ServletURL.PROTOCOL_HTTP or ServletUEL.PROTOCOL_HTTPS.
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.

ServletURL

public ServletURL(String theServerName,
                  String theContextPath,
                  String theServletPath,
                  String thePathInfo,
                  String theQueryString)
Creates the URL to simulate, using the default HTTP protocol.
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

getContextPath

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

getHost

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

getPath

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

getPathInfo

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

getPort

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

getProtocol

public String getProtocol()
Returns:
the protocol used to connect to the URL (HTTP, HTTPS, etc).

getQueryString

public String getQueryString()
Returns:
the simulated Query String

getServerName

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

getServletPath

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

loadFromRequest

public static ServletURL loadFromRequest(HttpServletRequest theRequest)
Creates a ServletURL object by loading it's values from the HTTP request.
Parameters:
theRequest - the incoming HTTP request.
Returns:
the ServletURL object unserialized from the HTTP request
Affected by:
around() in LogAspect.

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
Affected by:
around() in LogAspect.

toString

public String toString()
Returns:
a string representation


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