Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.apache.cactus
Class ServletURL  view ServletURL download ServletURL.java

java.lang.Object
  extended byorg.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 :
  • 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.
From the Servlet 2.3 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 except in the case where the request is matched with the "/*" pattern, in which case it is the empty string.
  • PathInfo: The part of the request path that is not part of the Context Path or the Servlet Path. It is either null if there is no extra path, or is a string with a leading "/".

Version:
$Id: ServletURL.java,v 1.1 2004/05/22 11:34:45 vmassol Exp $

Field Summary
private  java.lang.String contextPath
          The context path to simulate
private static int DEFAULT_PORT_HTTP
          Default port of the HTTP protocol.
private static int DEFAULT_PORT_HTTPS
          Default port of HTTP over SSL.
private static org.apache.commons.logging.Log LOGGER
          The logger
private  java.lang.String pathInfo
          The Path Info to simulate
private  java.lang.String protocol
          The protocol to use.
static java.lang.String PROTOCOL_HTTP
          Http protocol.
static java.lang.String PROTOCOL_HTTPS
          Https protocol.
private  java.lang.String queryString
          The Query string
private  java.lang.String serverName
          The server name to simulate (including port number)
private  java.lang.String servletPath
          The servlet path to simulate
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_PROTOCOL_PARAM
          Name of the parameter in the HTTP request that represents the protocol (HTTP, HTTPS, etc) 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 (+ port) 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()
          Default constructor.
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, using the default HTTP protocol.
ServletURL(java.lang.String theProtocol, 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()
           
private  int getDefaultPort()
          Returns the default port for the protocol.
 java.lang.String getHost()
          Returns the host name.
 java.lang.String getPath()
           
 java.lang.String getPathInfo()
           
 int getPort()
          Returns the port.
 java.lang.String getProtocol()
           
 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.
 void setContextPath(java.lang.String theContextPath)
          Sets the webapp context path in the URL to simulate, ie this is the name that will be returned by the HttpServletRequest.getContextPath().
 void setPathInfo(java.lang.String thePathInfo)
          Sets the path info in the URL to simulate, ie this is the name that will be returned by the HttpServletRequest.getPathInfo().
 void setProtocol(java.lang.String theProtocol)
          Sets the protocol to simulate (either ServletURL.PROTOCOL_HTTP or ServletURL.PROTOCOL_HTTPS.
 void setQueryString(java.lang.String theQueryString)
          Sets the Query string in the URL to simulate, ie this is the string that will be returned by the HttpServletResquest.getQueryString().
 void setServerName(java.lang.String theServerName)
          Sets the server name (and port) in the URL to simulate, ie this is the name that will be returned by the HttpServletRequest.getServerName() and HttpServletRequest.getServerPort().
 void setServletPath(java.lang.String theServletPath)
          Sets the servlet path in the URL to simulate, ie this is the name that will be returned by the HttpServletRequest.getServletPath().
 java.lang.String toString()
          Convert this Object to a human-readable String.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

URL_PROTOCOL_PARAM

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

See Also:
Constant Field Values

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 (+ port) in the URL to simulate. The name is voluntarily long so that it will not clash with a user-defined parameter.

See Also:
Constant Field Values

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.

See Also:
Constant Field Values

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.

See Also:
Constant Field Values

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.

See Also:
Constant Field Values

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.

See Also:
Constant Field Values

PROTOCOL_HTTP

public static final java.lang.String PROTOCOL_HTTP
Http protocol.

See Also:
Constant Field Values

PROTOCOL_HTTPS

public static final java.lang.String PROTOCOL_HTTPS
Https protocol.

See Also:
Constant Field Values

DEFAULT_PORT_HTTP

private static final int DEFAULT_PORT_HTTP
Default port of the HTTP protocol.

See Also:
Constant Field Values

DEFAULT_PORT_HTTPS

private static final int DEFAULT_PORT_HTTPS
Default port of HTTP over SSL.

See Also:
Constant Field Values

LOGGER

private static final org.apache.commons.logging.Log LOGGER
The logger


serverName

private java.lang.String serverName
The server name to simulate (including port number)


contextPath

private java.lang.String contextPath
The context path to simulate


servletPath

private java.lang.String servletPath
The servlet path to simulate


pathInfo

private java.lang.String pathInfo
The Path Info to simulate


queryString

private java.lang.String queryString
The Query string


protocol

private java.lang.String protocol
The protocol to use. Default to HTTP.

Constructor Detail

ServletURL

public ServletURL()
Default constructor. Need to call the different setters to make this a valid object.


ServletURL

public ServletURL(java.lang.String theProtocol,
                  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.


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, using the default HTTP protocol.

Method Detail

getProtocol

public java.lang.String getProtocol()

setProtocol

public void setProtocol(java.lang.String theProtocol)
Sets the protocol to simulate (either ServletURL.PROTOCOL_HTTP or ServletURL.PROTOCOL_HTTPS. If parameter is null then PROTOCOL_HTTP is assumed.


getServerName

public java.lang.String getServerName()

setServerName

public void setServerName(java.lang.String theServerName)
Sets the server name (and port) in the URL to simulate, ie this is the name that will be returned by the HttpServletRequest.getServerName() and HttpServletRequest.getServerPort(). Does not need to be set. If not set or null, then the server name and port from the Servlet Redirector will be returned.


getHost

public java.lang.String getHost()
Returns the host name.

The host name is extracted from the specified server name (as in jakarta.apache.org:80). If the server name has not been set, this method will return null.


getPort

public int getPort()
Returns the port.

The port is extracted from the specified server name (as in jakarta.apache.org:80). If the server name doesn't contain a port number, the default port number is returned (80 for HTTP, 443 for HTTP over SSL). If a port number is specified but illegal, or the server name has not been set, this method will return -1.


getContextPath

public java.lang.String getContextPath()

setContextPath

public void setContextPath(java.lang.String theContextPath)
Sets the webapp context path in the URL to simulate, ie this is the name that will be returned by the HttpServletRequest.getContextPath(). If not set, the context from the Servlet Redirector will be returned. Format: "/" + name or an empty string for the default context. If not an empty string the last character must not be "/".


getServletPath

public java.lang.String getServletPath()

setServletPath

public void setServletPath(java.lang.String theServletPath)
Sets the servlet path in the URL to simulate, ie this is the name that will be returned by the HttpServletRequest.getServletPath(). If null then the servlet path from the Servlet Redirector will be returned. Format : "/" + name or an empty string.


getPathInfo

public java.lang.String getPathInfo()

setPathInfo

public void setPathInfo(java.lang.String thePathInfo)
Sets the path info in the URL to simulate, ie this is the name that will be returned by the HttpServletRequest.getPathInfo(). If null then no path info will be set (and the Path Info from the Servlet Redirector will not be used). Format : "/" + name.


getQueryString

public java.lang.String getQueryString()

setQueryString

public void setQueryString(java.lang.String theQueryString)
Sets the Query string in the URL to simulate, ie this is the string that will be returned by the HttpServletResquest.getQueryString(). If not set, the query string from the Servlet Redirector will be returned.


getPath

public java.lang.String getPath()

saveToRequest

public void saveToRequest(WebRequest theRequest)
Saves the current URL to a WebRequest object.


loadFromRequest

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


toString

public java.lang.String toString()
Description copied from class: java.lang.Object
Convert this Object to a human-readable String. There are no limits placed on how long this String should be or what it should contain. We suggest you make it as intuitive as possible to be able to place it into System.out.println() 55 and such.

It is typical, but not required, to ensure that this method never completes abruptly with a java.lang.RuntimeException.

This method will be called when performing string concatenation with this object. If the result is null, string concatenation will instead use "null".

The default implementation returns getClass().getName() + "@" + Integer.toHexString(hashCode()).


getDefaultPort

private int getDefaultPort()
Returns the default port for the protocol.