org.apache.commons.messagelet.impl
Class HttpServletRequestImpl

java.lang.Object
  extended by org.apache.commons.messagelet.impl.ServletRequestImpl
      extended by org.apache.commons.messagelet.impl.HttpServletRequestImpl
All Implemented Interfaces:
javax.servlet.http.HttpServletRequest, javax.servlet.ServletRequest

public class HttpServletRequestImpl
extends ServletRequestImpl
implements javax.servlet.http.HttpServletRequest

Based on the HttpRequestBase code from Catalina.

Version:
$Revision: 155459 $ $Date: 2005-02-26 13:24:44 +0000 (Sat, 26 Feb 2005) $
Author:
Craig R. McClanahan, James Strachan

Field Summary
protected  String authType
          The authentication type used for this request.
protected  String contextPath
          The context path for this request.
protected  ArrayList cookies
          The set of cookies associated with this Request.
protected  SimpleDateFormat[] formats
          The set of SimpleDateFormat formats to use in getDateHeader().
protected  HashMap headers
          The HTTP headers associated with this Request, keyed by name.
protected  String method
          The request method associated with this Request.
protected  String pathInfo
          The path information for this request.
protected  String queryString
          The query string for this request.
protected  boolean requestedSessionCookie
          Was the requested session ID received in a cookie?
protected  String requestedSessionId
          The requested session ID (if any) for this request.
protected  boolean requestedSessionURL
          Was the requested session ID received in a URL?
protected  String requestURI
          The request URI associated with this request.
protected  String servletPath
          The servlet path for this request.
protected  HttpSessionImpl session
          The currently active session for this request.
protected  Principal userPrincipal
          The Principal who has been authenticated for this Request.
 
Fields inherited from class org.apache.commons.messagelet.impl.ServletRequestImpl
attributes, authorization, characterEncoding, contentLength, contentType, defaultLocale, input, locales, protocol, reader, remoteAddr, remoteHost, scheme, secure, serverName, serverPort, servletContext, stream
 
Fields inherited from interface javax.servlet.http.HttpServletRequest
BASIC_AUTH, CLIENT_CERT_AUTH, DIGEST_AUTH, FORM_AUTH
 
Constructor Summary
HttpServletRequestImpl(javax.servlet.ServletContext servletContext)
           
 
Method Summary
 void addCookie(javax.servlet.http.Cookie cookie)
          Add a Cookie to the set of Cookies associated with this Request.
 void addHeader(String name, String value)
          Add a Header to the set of Headers associated with this Request.
 void clearCookies()
          Clear the collection of Cookies associated with this Request.
 void clearHeaders()
          Clear the collection of Headers associated with this Request.
 String getAuthType()
          Return the authentication type used for this Request.
 String getContextPath()
          Return the portion of the request URI used to select the Context of the Request.
 javax.servlet.http.Cookie[] getCookies()
          Return the set of Cookies received with this Request.
 long getDateHeader(String name)
          Return the value of the specified date header, if any; otherwise return -1.
 String getHeader(String name)
          Return the first value of the specified header, if any; otherwise, return null
 Enumeration getHeaderNames()
          Return the names of all headers received with this request.
 Enumeration getHeaders(String name)
          Return all of the values of the specified header, if any; otherwise, return an empty enumeration.
 int getIntHeader(String name)
          Return the value of the specified header as an integer, or -1 if there is no such header for this request.
 String getMethod()
          Return the HTTP request method used in this Request.
 Map getParameterMap()
          Returns a Map of the parameters of this request.
 String getPathInfo()
          Return the path information associated with this Request.
 String getPathTranslated()
          Return the extra path information for this request, translated to a real path.
 String getQueryString()
          Return the query string associated with this request.
 String getRemoteUser()
          Return the name of the remote user that has been authenticated for this Request.
 String getRequestedSessionId()
          Return the session identifier included in this request, if any.
 String getRequestURI()
          Return the request URI for this request.
 StringBuffer getRequestURL()
          Reconstructs the URL the client used to make the request.
 String getServletPath()
          Return the portion of the request URI used to select the servlet that will process this request.
 javax.servlet.http.HttpSession getSession()
          Return the session associated with this Request, creating one if necessary.
 javax.servlet.http.HttpSession getSession(boolean create)
          Return the session associated with this Request, creating one if necessary and requested.
 Principal getUserPrincipal()
          Return the principal that has been authenticated for this Request.
 boolean isRequestedSessionIdFromCookie()
          Return true if the session identifier included in this request came from a cookie.
 boolean isRequestedSessionIdFromUrl()
          Deprecated. As of Version 2.1 of the Java Servlet API, use isRequestedSessionIdFromURL() instead.
 boolean isRequestedSessionIdFromURL()
          Return true if the session identifier included in this request came from the request URI.
 boolean isRequestedSessionIdValid()
          Return true if the session identifier included in this request identifies a valid session.
 boolean isUserInRole(String role)
          Return true if the authenticated user principal possesses the specified role name.
 void setAuthType(String authType)
          Set the authentication type used for this request, if any; otherwise set the type to null.
 void setContextPath(String path)
          Set the context path for this Request.
 void setMethod(String method)
          Set the HTTP request method used for this Request.
 void setPathInfo(String path)
          Set the path information for this Request.
 void setQueryString(String query)
          Set the query string for this Request.
 void setRequestedSessionCookie(boolean flag)
          Set a flag indicating whether or not the requested session ID for this request came in through a cookie.
 void setRequestedSessionId(String id)
          Set the requested session ID for this request.
 void setRequestedSessionURL(boolean flag)
          Set a flag indicating whether or not the requested session ID for this request came in through a URL.
 void setRequestURI(String uri)
          Set the unparsed request URI for this Request.
 void setServletPath(String path)
          Set the servlet path for this Request.
 void setUserPrincipal(Principal principal)
          Set the Principal who has been authenticated for this Request.
 
Methods inherited from class org.apache.commons.messagelet.impl.ServletRequestImpl
addLocale, createInputStream, finishRequest, getAttribute, getAttributeNames, getCharacterEncoding, getContentLength, getContentType, getInputStream, getLocale, getLocales, getParameter, getParameterNames, getParameterValues, getProtocol, getReader, getRealPath, getRemoteAddr, getRemoteHost, getRequestDispatcher, getScheme, getServerName, getServerPort, getStream, isSecure, log, log, removeAttribute, setAttribute, setCharacterEncoding, setContentLength, setContentType, setProtocol, setRemoteAddr, setRemoteHost, setScheme, setSecure, setServerName, setServerPort, setStream
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.servlet.ServletRequest
getAttribute, getAttributeNames, getCharacterEncoding, getContentLength, getContentType, getInputStream, getLocale, getLocales, getParameter, getParameterNames, getParameterValues, getProtocol, getReader, getRealPath, getRemoteAddr, getRemoteHost, getRequestDispatcher, getScheme, getServerName, getServerPort, isSecure, removeAttribute, setAttribute, setCharacterEncoding
 

Field Detail

authType

protected String authType
The authentication type used for this request.


contextPath

protected String contextPath
The context path for this request.


cookies

protected ArrayList cookies
The set of cookies associated with this Request.


formats

protected SimpleDateFormat[] formats
The set of SimpleDateFormat formats to use in getDateHeader().


headers

protected HashMap headers
The HTTP headers associated with this Request, keyed by name. The values are ArrayLists of the corresponding header values.


method

protected String method
The request method associated with this Request.


pathInfo

protected String pathInfo
The path information for this request.


queryString

protected String queryString
The query string for this request.


requestedSessionCookie

protected boolean requestedSessionCookie
Was the requested session ID received in a cookie?


requestedSessionId

protected String requestedSessionId
The requested session ID (if any) for this request.


requestedSessionURL

protected boolean requestedSessionURL
Was the requested session ID received in a URL?


requestURI

protected String requestURI
The request URI associated with this request.


servletPath

protected String servletPath
The servlet path for this request.


session

protected HttpSessionImpl session
The currently active session for this request.


userPrincipal

protected Principal userPrincipal
The Principal who has been authenticated for this Request.

Constructor Detail

HttpServletRequestImpl

public HttpServletRequestImpl(javax.servlet.ServletContext servletContext)
Method Detail

addCookie

public void addCookie(javax.servlet.http.Cookie cookie)
Add a Cookie to the set of Cookies associated with this Request.

Parameters:
cookie - The new cookie

addHeader

public void addHeader(String name,
                      String value)
Add a Header to the set of Headers associated with this Request.

Parameters:
name - The new header name
value - The new header value

clearCookies

public void clearCookies()
Clear the collection of Cookies associated with this Request.


clearHeaders

public void clearHeaders()
Clear the collection of Headers associated with this Request.


setAuthType

public void setAuthType(String authType)
Set the authentication type used for this request, if any; otherwise set the type to null. Typical values are "BASIC", "DIGEST", or "SSL".

Parameters:
authType - The authentication type used

setContextPath

public void setContextPath(String path)
Set the context path for this Request. This will normally be called when the associated Context is mapping the Request to a particular Wrapper.

Parameters:
path - The context path

setMethod

public void setMethod(String method)
Set the HTTP request method used for this Request.

Parameters:
method - The request method

setPathInfo

public void setPathInfo(String path)
Set the path information for this Request. This will normally be called when the associated Context is mapping the Request to a particular Wrapper.

Parameters:
path - The path information

setQueryString

public void setQueryString(String query)
Set the query string for this Request. This will normally be called by the HTTP Connector, when it parses the request headers.

Parameters:
query - The query string

setRequestedSessionCookie

public void setRequestedSessionCookie(boolean flag)
Set a flag indicating whether or not the requested session ID for this request came in through a cookie. This is normally called by the HTTP Connector, when it parses the request headers.

Parameters:
flag - The new flag

setRequestedSessionId

public void setRequestedSessionId(String id)
Set the requested session ID for this request. This is normally called by the HTTP Connector, when it parses the request headers.

Parameters:
id - The new session id

setRequestedSessionURL

public void setRequestedSessionURL(boolean flag)
Set a flag indicating whether or not the requested session ID for this request came in through a URL. This is normally called by the HTTP Connector, when it parses the request headers.

Parameters:
flag - The new flag

setRequestURI

public void setRequestURI(String uri)
Set the unparsed request URI for this Request. This will normally be called by the HTTP Connector, when it parses the request headers.

Parameters:
uri - The request URI

setServletPath

public void setServletPath(String path)
Set the servlet path for this Request. This will normally be called when the associated Context is mapping the Request to a particular Wrapper.

Parameters:
path - The servlet path

setUserPrincipal

public void setUserPrincipal(Principal principal)
Set the Principal who has been authenticated for this Request. This value is also used to calculate the value to be returned by the getRemoteUser() method.

Parameters:
principal - The user Principal

getAuthType

public String getAuthType()
Return the authentication type used for this Request.

Specified by:
getAuthType in interface javax.servlet.http.HttpServletRequest

getContextPath

public String getContextPath()
Return the portion of the request URI used to select the Context of the Request.

Specified by:
getContextPath in interface javax.servlet.http.HttpServletRequest

getCookies

public javax.servlet.http.Cookie[] getCookies()
Return the set of Cookies received with this Request.

Specified by:
getCookies in interface javax.servlet.http.HttpServletRequest

getDateHeader

public long getDateHeader(String name)
Return the value of the specified date header, if any; otherwise return -1.

Specified by:
getDateHeader in interface javax.servlet.http.HttpServletRequest
Parameters:
name - Name of the requested date header
Throws:
IllegalArgumentException - if the specified header value cannot be converted to a date

getHeader

public String getHeader(String name)
Return the first value of the specified header, if any; otherwise, return null

Specified by:
getHeader in interface javax.servlet.http.HttpServletRequest
Parameters:
name - Name of the requested header

getHeaders

public Enumeration getHeaders(String name)
Return all of the values of the specified header, if any; otherwise, return an empty enumeration.

Specified by:
getHeaders in interface javax.servlet.http.HttpServletRequest
Parameters:
name - Name of the requested header

getHeaderNames

public Enumeration getHeaderNames()
Return the names of all headers received with this request.

Specified by:
getHeaderNames in interface javax.servlet.http.HttpServletRequest

getIntHeader

public int getIntHeader(String name)
Return the value of the specified header as an integer, or -1 if there is no such header for this request.

Specified by:
getIntHeader in interface javax.servlet.http.HttpServletRequest
Parameters:
name - Name of the requested header
Throws:
IllegalArgumentException - if the specified header value cannot be converted to an integer

getMethod

public String getMethod()
Return the HTTP request method used in this Request.

Specified by:
getMethod in interface javax.servlet.http.HttpServletRequest

getParameterMap

public Map getParameterMap()
Returns a Map of the parameters of this request. Request parameters are extra information sent with the request. For HTTP servlets, parameters are contained in the query string or posted form data.

Specified by:
getParameterMap in interface javax.servlet.ServletRequest
Overrides:
getParameterMap in class ServletRequestImpl
Returns:
A Map containing parameter names as keys and parameter values as map values.

getPathInfo

public String getPathInfo()
Return the path information associated with this Request.

Specified by:
getPathInfo in interface javax.servlet.http.HttpServletRequest

getPathTranslated

public String getPathTranslated()
Return the extra path information for this request, translated to a real path.

Specified by:
getPathTranslated in interface javax.servlet.http.HttpServletRequest

getQueryString

public String getQueryString()
Return the query string associated with this request.

Specified by:
getQueryString in interface javax.servlet.http.HttpServletRequest

getRemoteUser

public String getRemoteUser()
Return the name of the remote user that has been authenticated for this Request.

Specified by:
getRemoteUser in interface javax.servlet.http.HttpServletRequest

getRequestedSessionId

public String getRequestedSessionId()
Return the session identifier included in this request, if any.

Specified by:
getRequestedSessionId in interface javax.servlet.http.HttpServletRequest

getRequestURI

public String getRequestURI()
Return the request URI for this request.

Specified by:
getRequestURI in interface javax.servlet.http.HttpServletRequest

getRequestURL

public StringBuffer getRequestURL()
Reconstructs the URL the client used to make the request. The returned URL contains a protocol, server name, port number, and server path, but it does not include query string parameters.

Because this method returns a StringBuffer, not a String, you can modify the URL easily, for example, to append query parameters.

This method is useful for creating redirect messages and for reporting errors.

Specified by:
getRequestURL in interface javax.servlet.http.HttpServletRequest
Returns:
A StringBuffer object containing the reconstructed URL

getServletPath

public String getServletPath()
Return the portion of the request URI used to select the servlet that will process this request.

Specified by:
getServletPath in interface javax.servlet.http.HttpServletRequest

getSession

public javax.servlet.http.HttpSession getSession()
Return the session associated with this Request, creating one if necessary.

Specified by:
getSession in interface javax.servlet.http.HttpServletRequest

getSession

public javax.servlet.http.HttpSession getSession(boolean create)
Return the session associated with this Request, creating one if necessary and requested.

Specified by:
getSession in interface javax.servlet.http.HttpServletRequest
Parameters:
create - Create a new session if one does not exist

isRequestedSessionIdFromCookie

public boolean isRequestedSessionIdFromCookie()
Return true if the session identifier included in this request came from a cookie.

Specified by:
isRequestedSessionIdFromCookie in interface javax.servlet.http.HttpServletRequest

isRequestedSessionIdFromURL

public boolean isRequestedSessionIdFromURL()
Return true if the session identifier included in this request came from the request URI.

Specified by:
isRequestedSessionIdFromURL in interface javax.servlet.http.HttpServletRequest

isRequestedSessionIdFromUrl

public boolean isRequestedSessionIdFromUrl()
Deprecated. As of Version 2.1 of the Java Servlet API, use isRequestedSessionIdFromURL() instead.

Return true if the session identifier included in this request came from the request URI.

Specified by:
isRequestedSessionIdFromUrl in interface javax.servlet.http.HttpServletRequest

isRequestedSessionIdValid

public boolean isRequestedSessionIdValid()
Return true if the session identifier included in this request identifies a valid session.

Specified by:
isRequestedSessionIdValid in interface javax.servlet.http.HttpServletRequest

isUserInRole

public boolean isUserInRole(String role)
Return true if the authenticated user principal possesses the specified role name.

Specified by:
isUserInRole in interface javax.servlet.http.HttpServletRequest
Parameters:
role - Role name to be validated

getUserPrincipal

public Principal getUserPrincipal()
Return the principal that has been authenticated for this Request.

Specified by:
getUserPrincipal in interface javax.servlet.http.HttpServletRequest


Copyright © 2001-2010 The Apache Software Foundation. All Rights Reserved.