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 :
- 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.
- 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. |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
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.
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.
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.