Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## 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.

` 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 238991 2004-05-22 11:34:50Z vmassol $

Field Summary
`static java.lang.String` | `PROTOCOL_HTTP` Http protocol.
`static java.lang.String` | `PROTOCOL_HTTPS` Https protocol.
`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()`
`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()`

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

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.

Parameters:
  `theProtocol` - the protocol to simulate (either `ServletURL.PROTOCOL_HTTP` or `ServletURL.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 used. Format: "/" + name or an empty string for the default context. Must not end with a "/" character.
  `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. If null, then the servlet path from the Servlet Redirector will be used. Format : "/" + name or an empty string.
  `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(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.

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 used. Format: "/" + name or an empty string for the default context. Must not end with a "/" character.
  `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. If null, then the servlet path from the Servlet Redirector will be used. Format : "/" + name or an empty string.
  `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

### getProtocol

    public java.lang.String getProtocol()

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

### 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.

  Parameters:
    `theProtocol` - the protocol to simulate

### getServerName

    public java.lang.String getServerName()

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

### 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.

  Parameters:
    `theServerName` - the server name and port (ex: "jakarta.apache.org:80")

### 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`.

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

### 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.

  Returns:
    the simulated port number or -1 if an illegal port has been specified

### getContextPath

    public java.lang.String getContextPath()

  Returns:
    the simulated URL context path

### 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 "/".

  Parameters:
    `theContextPath` - the context path to simulate

### getServletPath

    public java.lang.String getServletPath()

  Returns:
    the simulated URL servlet path

### 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.

  Parameters:
    `theServletPath` - the servlet path to simulate

### getPathInfo

    public java.lang.String getPathInfo()

  Returns:
    the simulated URL path info

### 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.

  Parameters:
    `thePathInfo` - the path info to simulate

### getQueryString

    public java.lang.String getQueryString()

  Returns:
    the simulated Query String

### 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.

  Parameters:
    `theQueryString` - the query string to simulate

### 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.
  Returns:
    the `ServletURL` object unserialized from the HTTP request

### toString

    public java.lang.String toString()

  Returns:
    a string representation

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

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