org.apache.commons.messagelet.impl
Class ServletRequestImpl

java.lang.Object
  extended byorg.apache.commons.messagelet.impl.ServletRequestImpl
All Implemented Interfaces:
javax.servlet.ServletRequest
Direct Known Subclasses:
HttpServletRequestImpl

public class ServletRequestImpl
extends java.lang.Object
implements javax.servlet.ServletRequest

Based on the RequestBase code from Catalina.

Version:
$Revision: 1.6 $ $Date: 2003/10/13 08:12:31 $
Author:
Craig R. McClanahan, James Strachan

Field Summary
protected  java.util.HashMap attributes
          The attributes associated with this Request, keyed by attribute name.
protected  java.lang.String authorization
          The authorization credentials sent with this Request.
protected  java.lang.String characterEncoding
          The character encoding for this Request.
protected  int contentLength
          The content length associated with this request.
protected  java.lang.String contentType
          The content type associated with this request.
protected static java.util.Locale defaultLocale
          The default Locale if none are specified.
protected  java.io.InputStream input
          The input stream associated with this Request.
protected  java.util.ArrayList locales
          The preferred Locales assocaited with this Request.
protected  java.lang.String protocol
          The protocol name and version associated with this Request.
protected  java.io.BufferedReader reader
          The reader that has been returned by getReader, if any.
protected  java.lang.String remoteAddr
          The remote address associated with this request.
protected  java.lang.String remoteHost
          The fully qualified name of the remote host.
protected  java.lang.String scheme
          The scheme associated with this Request.
protected  boolean secure
          Was this request received on a secure connection?
protected  java.lang.String serverName
          The server name associated with this Request.
protected  int serverPort
          The server port associated with this Request.
protected  javax.servlet.ServletContext servletContext
          The ServletContext which is used to dispatch further requests
protected  javax.servlet.ServletInputStream stream
          The ServletInputStream that has been returned by getInputStream(), if any.
 
Constructor Summary
ServletRequestImpl(javax.servlet.ServletContext servletContext)
           
 
Method Summary
 void addLocale(java.util.Locale locale)
          Add a Locale to the set of preferred Locales for this Request.
 javax.servlet.ServletInputStream createInputStream()
          Create and return a ServletInputStream to read the content associated with this Request.
 void finishRequest()
          Perform whatever actions are required to flush and close the input stream or reader, in a single operation.
 java.lang.Object getAttribute(java.lang.String name)
          Return the specified request attribute if it exists; otherwise, return null.
 java.util.Enumeration getAttributeNames()
          Return the names of all request attributes for this Request, or an empty Enumeration if there are none.
 java.lang.String getCharacterEncoding()
          Return the character encoding for this Request.
 int getContentLength()
          Return the content length for this Request.
 java.lang.String getContentType()
          Return the content type for this Request.
 javax.servlet.ServletInputStream getInputStream()
          Return the servlet input stream for this Request.
 java.util.Locale getLocale()
          Return the preferred Locale that the client will accept content in, based on the value for the first Accept-Language header that was encountered.
 java.util.Enumeration getLocales()
          Return the set of preferred Locales that the client will accept content in, based on the values for any Accept-Language headers that were encountered.
 java.lang.String getParameter(java.lang.String name)
          Return the value of the specified request parameter, if any; otherwise, return null.
 java.util.Map getParameterMap()
          Returns a Map of the parameters of this request.
 java.util.Enumeration getParameterNames()
          Return the names of all defined request parameters for this request.
 java.lang.String[] getParameterValues(java.lang.String name)
          Return the defined values for the specified request parameter, if any; otherwise, return null.
 java.lang.String getProtocol()
          Return the protocol and version used to make this Request.
 java.io.BufferedReader getReader()
          Read the Reader wrapping the input stream for this Request.
 java.lang.String getRealPath(java.lang.String path)
          Deprecated. As of version 2.1 of the Java Servlet API, use ServletContext.getRealPath().
 java.lang.String getRemoteAddr()
          Return the remote IP address making this Request.
 java.lang.String getRemoteHost()
          Return the remote host name making this Request.
 javax.servlet.RequestDispatcher getRequestDispatcher(java.lang.String path)
          Return a RequestDispatcher that wraps the resource at the specified path, which may be interpreted as relative to the current request path.
 java.lang.String getScheme()
          Return the scheme used to make this Request.
 java.lang.String getServerName()
          Return the server name responding to this Request.
 int getServerPort()
          Return the server port responding to this Request.
 java.io.InputStream getStream()
          Return the input stream associated with this Request.
 boolean isSecure()
          Was this request received on a secure connection?
protected  void log(java.lang.String message)
          Log a message to the current ServletContext
protected  void log(java.lang.String message, java.lang.Throwable throwable)
          Log a message to the current ServletContext
 void removeAttribute(java.lang.String name)
          Remove the specified request attribute if it exists.
 void setAttribute(java.lang.String name, java.lang.Object value)
          Set the specified request attribute to the specified value.
 void setCharacterEncoding(java.lang.String enc)
          Overrides the name of the character encoding used in the body of this request.
 void setContentLength(int length)
          Set the content length associated with this Request.
 void setContentType(java.lang.String type)
          Set the content type (and optionally the character encoding) associated with this Request.
 void setProtocol(java.lang.String protocol)
          Set the protocol name and version associated with this Request.
 void setRemoteAddr(java.lang.String remoteAddr)
          Set the IP address of the remote client associated with this Request.
 void setRemoteHost(java.lang.String remoteHost)
          Set the fully qualified name of the remote client associated with this Request.
 void setScheme(java.lang.String scheme)
          Set the name of the scheme associated with this request.
 void setSecure(boolean secure)
          Set the value to be returned by isSecure() for this Request.
 void setServerName(java.lang.String name)
          Set the name of the server (virtual host) to process this request.
 void setServerPort(int port)
          Set the port number of the server to process this request.
 void setStream(java.io.InputStream input)
          Set the input stream associated with this Request.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

attributes

protected java.util.HashMap attributes
The attributes associated with this Request, keyed by attribute name.


authorization

protected java.lang.String authorization
The authorization credentials sent with this Request.


characterEncoding

protected java.lang.String characterEncoding
The character encoding for this Request.


contentLength

protected int contentLength
The content length associated with this request.


contentType

protected java.lang.String contentType
The content type associated with this request.


defaultLocale

protected static java.util.Locale defaultLocale
The default Locale if none are specified.


input

protected java.io.InputStream input
The input stream associated with this Request.


locales

protected java.util.ArrayList locales
The preferred Locales assocaited with this Request.


protocol

protected java.lang.String protocol
The protocol name and version associated with this Request.


reader

protected java.io.BufferedReader reader
The reader that has been returned by getReader, if any.


remoteAddr

protected java.lang.String remoteAddr
The remote address associated with this request.


remoteHost

protected java.lang.String remoteHost
The fully qualified name of the remote host.


scheme

protected java.lang.String scheme
The scheme associated with this Request.


secure

protected boolean secure
Was this request received on a secure connection?


serverName

protected java.lang.String serverName
The server name associated with this Request.


serverPort

protected int serverPort
The server port associated with this Request.


stream

protected javax.servlet.ServletInputStream stream
The ServletInputStream that has been returned by getInputStream(), if any.


servletContext

protected javax.servlet.ServletContext servletContext
The ServletContext which is used to dispatch further requests

Constructor Detail

ServletRequestImpl

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

getStream

public java.io.InputStream getStream()
Return the input stream associated with this Request.


setStream

public void setStream(java.io.InputStream input)
Set the input stream associated with this Request.

Parameters:
input - The new input stream

addLocale

public void addLocale(java.util.Locale locale)
Add a Locale to the set of preferred Locales for this Request. The first added Locale will be the first one returned by getLocales().

Parameters:
locale - The new preferred Locale

createInputStream

public javax.servlet.ServletInputStream createInputStream()
                                                   throws java.io.IOException
Create and return a ServletInputStream to read the content associated with this Request. The default implementation creates an instance of RequestStream associated with this request, but this can be overridden if necessary.

Throws:
java.io.IOException - if an input/output error occurs

finishRequest

public void finishRequest()
                   throws java.io.IOException
Perform whatever actions are required to flush and close the input stream or reader, in a single operation.

Throws:
java.io.IOException - if an input/output error occurs

setContentLength

public void setContentLength(int length)
Set the content length associated with this Request.

Parameters:
length - The new content length

setContentType

public void setContentType(java.lang.String type)
Set the content type (and optionally the character encoding) associated with this Request. For example, text/html; charset=ISO-8859-4.

Parameters:
type - The new content type

setProtocol

public void setProtocol(java.lang.String protocol)
Set the protocol name and version associated with this Request.

Parameters:
protocol - Protocol name and version

setRemoteAddr

public void setRemoteAddr(java.lang.String remoteAddr)
Set the IP address of the remote client associated with this Request.

Parameters:
remoteAddr - The remote IP address

setRemoteHost

public void setRemoteHost(java.lang.String remoteHost)
Set the fully qualified name of the remote client associated with this Request.

Parameters:
remoteHost - The remote host name

setScheme

public void setScheme(java.lang.String scheme)
Set the name of the scheme associated with this request. Typical values are http, https, and ftp.

Parameters:
scheme - The scheme

setSecure

public void setSecure(boolean secure)
Set the value to be returned by isSecure() for this Request.

Parameters:
secure - The new isSecure value

setServerName

public void setServerName(java.lang.String name)
Set the name of the server (virtual host) to process this request.

Parameters:
name - The server name

setServerPort

public void setServerPort(int port)
Set the port number of the server to process this request.

Parameters:
port - The server port

getAttribute

public java.lang.Object getAttribute(java.lang.String name)
Return the specified request attribute if it exists; otherwise, return null.

Specified by:
getAttribute in interface javax.servlet.ServletRequest
Parameters:
name - Name of the request attribute to return

getAttributeNames

public java.util.Enumeration getAttributeNames()
Return the names of all request attributes for this Request, or an empty Enumeration if there are none.

Specified by:
getAttributeNames in interface javax.servlet.ServletRequest

getCharacterEncoding

public java.lang.String getCharacterEncoding()
Return the character encoding for this Request.

Specified by:
getCharacterEncoding in interface javax.servlet.ServletRequest

getContentLength

public int getContentLength()
Return the content length for this Request.

Specified by:
getContentLength in interface javax.servlet.ServletRequest

getContentType

public java.lang.String getContentType()
Return the content type for this Request.

Specified by:
getContentType in interface javax.servlet.ServletRequest

getInputStream

public javax.servlet.ServletInputStream getInputStream()
                                                throws java.io.IOException
Return the servlet input stream for this Request. The default implementation returns a servlet input stream created by createInputStream().

Specified by:
getInputStream in interface javax.servlet.ServletRequest
Throws:
java.lang.IllegalStateException - if getReader() has already been called for this request
java.io.IOException - if an input/output error occurs

getLocale

public java.util.Locale getLocale()
Return the preferred Locale that the client will accept content in, based on the value for the first Accept-Language header that was encountered. If the request did not specify a preferred language, the server's default Locale is returned.

Specified by:
getLocale in interface javax.servlet.ServletRequest

getLocales

public java.util.Enumeration getLocales()
Return the set of preferred Locales that the client will accept content in, based on the values for any Accept-Language headers that were encountered. If the request did not specify a preferred language, the server's default Locale is returned.

Specified by:
getLocales in interface javax.servlet.ServletRequest

getParameter

public java.lang.String getParameter(java.lang.String name)
Return the value of the specified request parameter, if any; otherwise, return null. If there is more than one value defined, return only the first one.

Specified by:
getParameter in interface javax.servlet.ServletRequest
Parameters:
name - Name of the desired request parameter

getParameterValues

public java.lang.String[] getParameterValues(java.lang.String name)
Return the defined values for the specified request parameter, if any; otherwise, return null.

Specified by:
getParameterValues in interface javax.servlet.ServletRequest
Parameters:
name - Name of the desired request parameter

getParameterMap

public java.util.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
Returns:
A Map containing parameter names as keys and parameter values as map values.

getParameterNames

public java.util.Enumeration getParameterNames()
Return the names of all defined request parameters for this request.

Specified by:
getParameterNames in interface javax.servlet.ServletRequest

getProtocol

public java.lang.String getProtocol()
Return the protocol and version used to make this Request.

Specified by:
getProtocol in interface javax.servlet.ServletRequest

getReader

public java.io.BufferedReader getReader()
                                 throws java.io.IOException
Read the Reader wrapping the input stream for this Request. The default implementation wraps a BufferedReader around the servlet input stream returned by createInputStream().

Specified by:
getReader in interface javax.servlet.ServletRequest
Throws:
java.lang.IllegalStateException - if getInputStream() has already been called for this request
java.io.IOException - if an input/output error occurs

getRealPath

public java.lang.String getRealPath(java.lang.String path)
Deprecated. As of version 2.1 of the Java Servlet API, use ServletContext.getRealPath().

Return the real path of the specified virtual path.

Specified by:
getRealPath in interface javax.servlet.ServletRequest
Parameters:
path - Path to be translated

getRemoteAddr

public java.lang.String getRemoteAddr()
Return the remote IP address making this Request.

Specified by:
getRemoteAddr in interface javax.servlet.ServletRequest

getRemoteHost

public java.lang.String getRemoteHost()
Return the remote host name making this Request.

Specified by:
getRemoteHost in interface javax.servlet.ServletRequest

getRequestDispatcher

public javax.servlet.RequestDispatcher getRequestDispatcher(java.lang.String path)
Return a RequestDispatcher that wraps the resource at the specified path, which may be interpreted as relative to the current request path.

Specified by:
getRequestDispatcher in interface javax.servlet.ServletRequest
Parameters:
path - Path of the resource to be wrapped

getScheme

public java.lang.String getScheme()
Return the scheme used to make this Request.

Specified by:
getScheme in interface javax.servlet.ServletRequest

getServerName

public java.lang.String getServerName()
Return the server name responding to this Request.

Specified by:
getServerName in interface javax.servlet.ServletRequest

getServerPort

public int getServerPort()
Return the server port responding to this Request.

Specified by:
getServerPort in interface javax.servlet.ServletRequest

isSecure

public boolean isSecure()
Was this request received on a secure connection?

Specified by:
isSecure in interface javax.servlet.ServletRequest

removeAttribute

public void removeAttribute(java.lang.String name)
Remove the specified request attribute if it exists.

Specified by:
removeAttribute in interface javax.servlet.ServletRequest
Parameters:
name - Name of the request attribute to remove

setAttribute

public void setAttribute(java.lang.String name,
                         java.lang.Object value)
Set the specified request attribute to the specified value.

Specified by:
setAttribute in interface javax.servlet.ServletRequest
Parameters:
name - Name of the request attribute to set
value - The associated value

setCharacterEncoding

public void setCharacterEncoding(java.lang.String enc)
                          throws java.io.UnsupportedEncodingException
Overrides the name of the character encoding used in the body of this request. This method must be called prior to reading request parameters or reading input using getReader().

Specified by:
setCharacterEncoding in interface javax.servlet.ServletRequest
Parameters:
enc - The character encoding to be used
Throws:
java.io.UnsupportedEncodingException - if the specified encoding is not supported
Since:
Servlet 2.3

log

protected void log(java.lang.String message)
Log a message to the current ServletContext

Parameters:
message - Message to be logged

log

protected void log(java.lang.String message,
                   java.lang.Throwable throwable)
Log a message to the current ServletContext

Parameters:
message - Message to be logged
throwable - Associated exception