ServletRequestWrapper (Java EE 6 ) (original) (raw)



javax.servlet

Class ServletRequestWrapper

java.lang.Object extended by javax.servlet.ServletRequestWrapper

All Implemented Interfaces:

ServletRequest

Direct Known Subclasses:

HttpServletRequestWrapper


public class ServletRequestWrapper

extends java.lang.Object

implements ServletRequest

Provides a convenient implementation of the ServletRequest interface that can be subclassed by developers wishing to adapt the request to a Servlet. This class implements the Wrapper or Decorator pattern. Methods default to calling through to the wrapped request object.

Since:

Servlet 2.3

See Also:

ServletRequest


Constructor Summary
ServletRequestWrapper(ServletRequest request) Creates a ServletRequest adaptor wrapping the given request object.
Method Summary
AsyncContext getAsyncContext() Gets the AsyncContext that was created or reinitialized by the most recent invocation of startAsync() or[startAsync(ServletRequest,ServletResponse)](../../javax/servlet/ServletRequestWrapper.html#startAsync%28javax.servlet.ServletRequest, javax.servlet.ServletResponse%29) on the wrapped request.
java.lang.Object getAttribute(java.lang.String name) The default behavior of this method is to call getAttribute(String name) on the wrapped request object.
java.util.Enumeration<java.lang.String> getAttributeNames() The default behavior of this method is to return getAttributeNames() on the wrapped request object.
java.lang.String getCharacterEncoding() The default behavior of this method is to return getCharacterEncoding() on the wrapped request object.
int getContentLength() The default behavior of this method is to return getContentLength() on the wrapped request object.
java.lang.String getContentType() The default behavior of this method is to return getContentType() on the wrapped request object.
DispatcherType getDispatcherType() Gets the dispatcher type of the wrapped request.
ServletInputStream getInputStream() The default behavior of this method is to return getInputStream() on the wrapped request object.
java.lang.String getLocalAddr() The default behavior of this method is to return getLocalAddr() on the wrapped request object.
java.util.Locale getLocale() The default behavior of this method is to return getLocale() on the wrapped request object.
java.util.Enumeration<java.util.Locale> getLocales() The default behavior of this method is to return getLocales() on the wrapped request object.
java.lang.String getLocalName() The default behavior of this method is to return getLocalName() on the wrapped request object.
int getLocalPort() The default behavior of this method is to return getLocalPort() on the wrapped request object.
java.lang.String getParameter(java.lang.String name) The default behavior of this method is to return getParameter(String name) on the wrapped request object.
java.util.Map<java.lang.String,java.lang.String[]> getParameterMap() The default behavior of this method is to return getParameterMap() on the wrapped request object.
java.util.Enumeration<java.lang.String> getParameterNames() The default behavior of this method is to return getParameterNames() on the wrapped request object.
java.lang.String[] getParameterValues(java.lang.String name) The default behavior of this method is to return getParameterValues(String name) on the wrapped request object.
java.lang.String getProtocol() The default behavior of this method is to return getProtocol() on the wrapped request object.
java.io.BufferedReader getReader() The default behavior of this method is to return getReader() on the wrapped request object.
java.lang.String getRealPath(java.lang.String path) Deprecated. As of Version 2.1 of the Java Servlet API, use ServletContext#getRealPath instead
java.lang.String getRemoteAddr() The default behavior of this method is to return getRemoteAddr() on the wrapped request object.
java.lang.String getRemoteHost() The default behavior of this method is to return getRemoteHost() on the wrapped request object.
int getRemotePort() The default behavior of this method is to return getRemotePort() on the wrapped request object.
ServletRequest getRequest() Return the wrapped request object.
RequestDispatcher getRequestDispatcher(java.lang.String path) The default behavior of this method is to return getRequestDispatcher(String path) on the wrapped request object.
java.lang.String getScheme() The default behavior of this method is to return getScheme() on the wrapped request object.
java.lang.String getServerName() The default behavior of this method is to return getServerName() on the wrapped request object.
int getServerPort() The default behavior of this method is to return getServerPort() on the wrapped request object.
ServletContext getServletContext() Gets the servlet context to which the wrapped servlet request was last dispatched.
boolean isAsyncStarted() Checks if the wrapped request has been put into asynchronous mode.
boolean isAsyncSupported() Checks if the wrapped request supports asynchronous operation.
boolean isSecure() The default behavior of this method is to return isSecure() on the wrapped request object.
boolean isWrapperFor(java.lang.Class wrappedType) Checks (recursively) if this ServletRequestWrapper wraps aServletRequest of the given class type.
boolean isWrapperFor(ServletRequest wrapped) Checks (recursively) if this ServletRequestWrapper wraps the givenServletRequest instance.
void removeAttribute(java.lang.String name) The default behavior of this method is to call removeAttribute(String name) on the wrapped request object.
void [setAttribute](../../javax/servlet/ServletRequestWrapper.html#setAttribute%28java.lang.String, java.lang.Object%29)(java.lang.String name, java.lang.Object o) The default behavior of this method is to return setAttribute(String name, Object o) on the wrapped request object.
void setCharacterEncoding(java.lang.String enc) The default behavior of this method is to set the character encoding on the wrapped request object.
void setRequest(ServletRequest request) Sets the request object being wrapped.
AsyncContext startAsync() The default behavior of this method is to invokeServletRequest#startAsync on the wrapped request object.
AsyncContext [startAsync](../../javax/servlet/ServletRequestWrapper.html#startAsync%28javax.servlet.ServletRequest, javax.servlet.ServletResponse%29)(ServletRequest servletRequest,ServletResponse servletResponse) The default behavior of this method is to invokeServletRequest#startAsync(ServletRequest, ServletResponse) on the wrapped request object.
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Constructor Detail

ServletRequestWrapper

public ServletRequestWrapper(ServletRequest request)

Creates a ServletRequest adaptor wrapping the given request object.

Throws:

java.lang.IllegalArgumentException - if the request is null

Method Detail

getRequest

public ServletRequest getRequest()

Return the wrapped request object.


setRequest

public void setRequest(ServletRequest request)

Sets the request object being wrapped.

Throws:

java.lang.IllegalArgumentException - if the request is null.


getAttribute

public java.lang.Object getAttribute(java.lang.String name)

The default behavior of this method is to call getAttribute(String name) on the wrapped request object.

Specified by:

[getAttribute](../../javax/servlet/ServletRequest.html#getAttribute%28java.lang.String%29) in interface [ServletRequest](../../javax/servlet/ServletRequest.html "interface in javax.servlet")

Parameters:

name - a String specifying the name of the attribute

Returns:

an Object containing the value of the attribute, or null if the attribute does not exist


getAttributeNames

public java.util.Enumeration<java.lang.String> getAttributeNames()

The default behavior of this method is to return getAttributeNames() on the wrapped request object.

Specified by:

[getAttributeNames](../../javax/servlet/ServletRequest.html#getAttributeNames%28%29) in interface [ServletRequest](../../javax/servlet/ServletRequest.html "interface in javax.servlet")

Returns:

an Enumeration of strings containing the names of the request's attributes


getCharacterEncoding

public java.lang.String getCharacterEncoding()

The default behavior of this method is to return getCharacterEncoding() on the wrapped request object.

Specified by:

[getCharacterEncoding](../../javax/servlet/ServletRequest.html#getCharacterEncoding%28%29) in interface [ServletRequest](../../javax/servlet/ServletRequest.html "interface in javax.servlet")

Returns:

a String containing the name of the character encoding, or null if the request does not specify a character encoding


setCharacterEncoding

public void setCharacterEncoding(java.lang.String enc) throws java.io.UnsupportedEncodingException

The default behavior of this method is to set the character encoding on the wrapped request object.

Specified by:

[setCharacterEncoding](../../javax/servlet/ServletRequest.html#setCharacterEncoding%28java.lang.String%29) in interface [ServletRequest](../../javax/servlet/ServletRequest.html "interface in javax.servlet")

Parameters:

enc - String containing the name of the character encoding.

Throws:

java.io.UnsupportedEncodingException - if this ServletRequest is still in a state where a character encoding may be set, but the specified encoding is invalid


getContentLength

public int getContentLength()

The default behavior of this method is to return getContentLength() on the wrapped request object.

Specified by:

[getContentLength](../../javax/servlet/ServletRequest.html#getContentLength%28%29) in interface [ServletRequest](../../javax/servlet/ServletRequest.html "interface in javax.servlet")

Returns:

an integer containing the length of the request body or -1 if the length is not known


getContentType

public java.lang.String getContentType()

The default behavior of this method is to return getContentType() on the wrapped request object.

Specified by:

[getContentType](../../javax/servlet/ServletRequest.html#getContentType%28%29) in interface [ServletRequest](../../javax/servlet/ServletRequest.html "interface in javax.servlet")

Returns:

a String containing the name of the MIME type of the request, or null if the type is not known


getInputStream

public ServletInputStream getInputStream() throws java.io.IOException

The default behavior of this method is to return getInputStream() on the wrapped request object.

Specified by:

[getInputStream](../../javax/servlet/ServletRequest.html#getInputStream%28%29) in interface [ServletRequest](../../javax/servlet/ServletRequest.html "interface in javax.servlet")

Returns:

a ServletInputStream object containing the body of the request

Throws:

java.io.IOException - if an input or output exception occurred


getParameter

public java.lang.String getParameter(java.lang.String name)

The default behavior of this method is to return getParameter(String name) on the wrapped request object.

Specified by:

[getParameter](../../javax/servlet/ServletRequest.html#getParameter%28java.lang.String%29) in interface [ServletRequest](../../javax/servlet/ServletRequest.html "interface in javax.servlet")

Parameters:

name - a String specifying the name of the parameter

Returns:

a String representing the single value of the parameter

See Also:

ServletRequest.getParameterValues(java.lang.String)


getParameterMap

public java.util.Map<java.lang.String,java.lang.String[]> getParameterMap()

The default behavior of this method is to return getParameterMap() on the wrapped request object.

Specified by:

[getParameterMap](../../javax/servlet/ServletRequest.html#getParameterMap%28%29) in interface [ServletRequest](../../javax/servlet/ServletRequest.html "interface in javax.servlet")

Returns:

an immutable java.util.Map containing parameter names as keys and parameter values as map values. The keys in the parameter map are of type String. The values in the parameter map are of type String array.


getParameterNames

public java.util.Enumeration<java.lang.String> getParameterNames()

The default behavior of this method is to return getParameterNames() on the wrapped request object.

Specified by:

[getParameterNames](../../javax/servlet/ServletRequest.html#getParameterNames%28%29) in interface [ServletRequest](../../javax/servlet/ServletRequest.html "interface in javax.servlet")

Returns:

an Enumeration of String objects, each String containing the name of a request parameter; or an empty Enumeration if the request has no parameters


getParameterValues

public java.lang.String[] getParameterValues(java.lang.String name)

The default behavior of this method is to return getParameterValues(String name) on the wrapped request object.

Specified by:

[getParameterValues](../../javax/servlet/ServletRequest.html#getParameterValues%28java.lang.String%29) in interface [ServletRequest](../../javax/servlet/ServletRequest.html "interface in javax.servlet")

Parameters:

name - a String containing the name of the parameter whose value is requested

Returns:

an array of String objects containing the parameter's values

See Also:

ServletRequest.getParameter(java.lang.String)


getProtocol

public java.lang.String getProtocol()

The default behavior of this method is to return getProtocol() on the wrapped request object.

Specified by:

[getProtocol](../../javax/servlet/ServletRequest.html#getProtocol%28%29) in interface [ServletRequest](../../javax/servlet/ServletRequest.html "interface in javax.servlet")

Returns:

a String containing the protocol name and version number


getScheme

public java.lang.String getScheme()

The default behavior of this method is to return getScheme() on the wrapped request object.

Specified by:

[getScheme](../../javax/servlet/ServletRequest.html#getScheme%28%29) in interface [ServletRequest](../../javax/servlet/ServletRequest.html "interface in javax.servlet")

Returns:

a String containing the name of the scheme used to make this request


getServerName

public java.lang.String getServerName()

The default behavior of this method is to return getServerName() on the wrapped request object.

Specified by:

[getServerName](../../javax/servlet/ServletRequest.html#getServerName%28%29) in interface [ServletRequest](../../javax/servlet/ServletRequest.html "interface in javax.servlet")

Returns:

a String containing the name of the server


getServerPort

public int getServerPort()

The default behavior of this method is to return getServerPort() on the wrapped request object.

Specified by:

[getServerPort](../../javax/servlet/ServletRequest.html#getServerPort%28%29) in interface [ServletRequest](../../javax/servlet/ServletRequest.html "interface in javax.servlet")

Returns:

an integer specifying the port number


getReader

public java.io.BufferedReader getReader() throws java.io.IOException

The default behavior of this method is to return getReader() on the wrapped request object.

Specified by:

[getReader](../../javax/servlet/ServletRequest.html#getReader%28%29) in interface [ServletRequest](../../javax/servlet/ServletRequest.html "interface in javax.servlet")

Returns:

a BufferedReader containing the body of the request

Throws:

java.io.UnsupportedEncodingException - if the character set encoding used is not supported and the text cannot be decoded

java.io.IOException - if an input or output exception occurred

See Also:

ServletRequest.getInputStream()


getRemoteAddr

public java.lang.String getRemoteAddr()

The default behavior of this method is to return getRemoteAddr() on the wrapped request object.

Specified by:

[getRemoteAddr](../../javax/servlet/ServletRequest.html#getRemoteAddr%28%29) in interface [ServletRequest](../../javax/servlet/ServletRequest.html "interface in javax.servlet")

Returns:

a String containing the IP address of the client that sent the request


getRemoteHost

public java.lang.String getRemoteHost()

The default behavior of this method is to return getRemoteHost() on the wrapped request object.

Specified by:

[getRemoteHost](../../javax/servlet/ServletRequest.html#getRemoteHost%28%29) in interface [ServletRequest](../../javax/servlet/ServletRequest.html "interface in javax.servlet")

Returns:

a String containing the fully qualified name of the client


setAttribute

public void setAttribute(java.lang.String name, java.lang.Object o)

The default behavior of this method is to return setAttribute(String name, Object o) on the wrapped request object.

Specified by:

[setAttribute](../../javax/servlet/ServletRequest.html#setAttribute%28java.lang.String, java.lang.Object%29) in interface [ServletRequest](../../javax/servlet/ServletRequest.html "interface in javax.servlet")

Parameters:

name - a String specifying the name of the attribute

o - the Object to be stored


removeAttribute

public void removeAttribute(java.lang.String name)

The default behavior of this method is to call removeAttribute(String name) on the wrapped request object.

Specified by:

[removeAttribute](../../javax/servlet/ServletRequest.html#removeAttribute%28java.lang.String%29) in interface [ServletRequest](../../javax/servlet/ServletRequest.html "interface in javax.servlet")

Parameters:

name - a String specifying the name of the attribute to remove


getLocale

public java.util.Locale getLocale()

The default behavior of this method is to return getLocale() on the wrapped request object.

Specified by:

[getLocale](../../javax/servlet/ServletRequest.html#getLocale%28%29) in interface [ServletRequest](../../javax/servlet/ServletRequest.html "interface in javax.servlet")

Returns:

the preferred Locale for the client


getLocales

public java.util.Enumeration<java.util.Locale> getLocales()

The default behavior of this method is to return getLocales() on the wrapped request object.

Specified by:

[getLocales](../../javax/servlet/ServletRequest.html#getLocales%28%29) in interface [ServletRequest](../../javax/servlet/ServletRequest.html "interface in javax.servlet")

Returns:

an Enumeration of preferred Locale objects for the client


isSecure

public boolean isSecure()

The default behavior of this method is to return isSecure() on the wrapped request object.

Specified by:

[isSecure](../../javax/servlet/ServletRequest.html#isSecure%28%29) in interface [ServletRequest](../../javax/servlet/ServletRequest.html "interface in javax.servlet")

Returns:

a boolean indicating if the request was made using a secure channel


getRequestDispatcher

public RequestDispatcher getRequestDispatcher(java.lang.String path)

The default behavior of this method is to return getRequestDispatcher(String path) on the wrapped request object.

Specified by:

[getRequestDispatcher](../../javax/servlet/ServletRequest.html#getRequestDispatcher%28java.lang.String%29) in interface [ServletRequest](../../javax/servlet/ServletRequest.html "interface in javax.servlet")

Parameters:

path - a String specifying the pathname to the resource. If it is relative, it must be relative against the current servlet.

Returns:

a RequestDispatcher object that acts as a wrapper for the resource at the specified path, or null if the servlet container cannot return aRequestDispatcher

See Also:

RequestDispatcher, ServletContext#getRequestDispatcher


getRealPath

public java.lang.String getRealPath(java.lang.String path)

Deprecated. As of Version 2.1 of the Java Servlet API, use ServletContext#getRealPath instead

The default behavior of this method is to return getRealPath(String path) on the wrapped request object.

Specified by:

[getRealPath](../../javax/servlet/ServletRequest.html#getRealPath%28java.lang.String%29) in interface [ServletRequest](../../javax/servlet/ServletRequest.html "interface in javax.servlet")


getRemotePort

public int getRemotePort()

The default behavior of this method is to return getRemotePort() on the wrapped request object.

Specified by:

[getRemotePort](../../javax/servlet/ServletRequest.html#getRemotePort%28%29) in interface [ServletRequest](../../javax/servlet/ServletRequest.html "interface in javax.servlet")

Returns:

an integer specifying the port number

Since:

Servlet 2.4


getLocalName

public java.lang.String getLocalName()

The default behavior of this method is to return getLocalName() on the wrapped request object.

Specified by:

[getLocalName](../../javax/servlet/ServletRequest.html#getLocalName%28%29) in interface [ServletRequest](../../javax/servlet/ServletRequest.html "interface in javax.servlet")

Returns:

a String containing the host name of the IP on which the request was received.

Since:

Servlet 2.4


getLocalAddr

public java.lang.String getLocalAddr()

The default behavior of this method is to return getLocalAddr() on the wrapped request object.

Specified by:

[getLocalAddr](../../javax/servlet/ServletRequest.html#getLocalAddr%28%29) in interface [ServletRequest](../../javax/servlet/ServletRequest.html "interface in javax.servlet")

Returns:

a String containing the IP address on which the request was received.

Since:

Servlet 2.4


getLocalPort

public int getLocalPort()

The default behavior of this method is to return getLocalPort() on the wrapped request object.

Specified by:

[getLocalPort](../../javax/servlet/ServletRequest.html#getLocalPort%28%29) in interface [ServletRequest](../../javax/servlet/ServletRequest.html "interface in javax.servlet")

Returns:

an integer specifying the port number

Since:

Servlet 2.4


getServletContext

public ServletContext getServletContext()

Gets the servlet context to which the wrapped servlet request was last dispatched.

Specified by:

[getServletContext](../../javax/servlet/ServletRequest.html#getServletContext%28%29) in interface [ServletRequest](../../javax/servlet/ServletRequest.html "interface in javax.servlet")

Returns:

the servlet context to which the wrapped servlet request was last dispatched

Since:

Servlet 3.0


startAsync

public AsyncContext startAsync() throws java.lang.IllegalStateException

The default behavior of this method is to invokeServletRequest#startAsync on the wrapped request object.

Specified by:

[startAsync](../../javax/servlet/ServletRequest.html#startAsync%28%29) in interface [ServletRequest](../../javax/servlet/ServletRequest.html "interface in javax.servlet")

Returns:

the (re)initialized AsyncContext

Throws:

IllegalStateException - if the request is within the scope of a filter or servlet that does not support asynchronous operations (that is, isAsyncSupported() returns false), or if this method is called again without any asynchronous dispatch (resulting from one of the AsyncContext#dispatch methods), is called outside the scope of any such dispatch, or is called again within the scope of the same dispatch, or if the response has already been closed

Since:

Servlet 3.0

See Also:

ServletRequest#startAsync


startAsync

public AsyncContext startAsync(ServletRequest servletRequest, ServletResponse servletResponse) throws java.lang.IllegalStateException

The default behavior of this method is to invokeServletRequest#startAsync(ServletRequest, ServletResponse) on the wrapped request object.

Specified by:

[startAsync](../../javax/servlet/ServletRequest.html#startAsync%28javax.servlet.ServletRequest, javax.servlet.ServletResponse%29) in interface [ServletRequest](../../javax/servlet/ServletRequest.html "interface in javax.servlet")

Parameters:

servletRequest - the ServletRequest used to initialize the AsyncContext

servletResponse - the ServletResponse used to initialize the AsyncContext

Returns:

the (re)initialized AsyncContext

Throws:

IllegalStateException - if the request is within the scope of a filter or servlet that does not support asynchronous operations (that is, isAsyncSupported() returns false), or if this method is called again without any asynchronous dispatch (resulting from one of the AsyncContext#dispatch methods), is called outside the scope of any such dispatch, or is called again within the scope of the same dispatch, or if the response has already been closed

Since:

Servlet 3.0

See Also:

ServletRequest#startAsync(ServletRequest, ServletResponse)


isAsyncStarted

public boolean isAsyncStarted()

Checks if the wrapped request has been put into asynchronous mode.

Specified by:

[isAsyncStarted](../../javax/servlet/ServletRequest.html#isAsyncStarted%28%29) in interface [ServletRequest](../../javax/servlet/ServletRequest.html "interface in javax.servlet")

Returns:

true if this request has been put into asynchronous mode, false otherwise

Since:

Servlet 3.0

See Also:

ServletRequest#isAsyncStarted


isAsyncSupported

public boolean isAsyncSupported()

Checks if the wrapped request supports asynchronous operation.

Specified by:

[isAsyncSupported](../../javax/servlet/ServletRequest.html#isAsyncSupported%28%29) in interface [ServletRequest](../../javax/servlet/ServletRequest.html "interface in javax.servlet")

Returns:

true if this request supports asynchronous operation, false otherwise

Since:

Servlet 3.0

See Also:

ServletRequest#isAsyncSupported


getAsyncContext

public AsyncContext getAsyncContext()

Gets the AsyncContext that was created or reinitialized by the most recent invocation of startAsync() or[startAsync(ServletRequest,ServletResponse)](../../javax/servlet/ServletRequestWrapper.html#startAsync%28javax.servlet.ServletRequest, javax.servlet.ServletResponse%29) on the wrapped request.

Specified by:

[getAsyncContext](../../javax/servlet/ServletRequest.html#getAsyncContext%28%29) in interface [ServletRequest](../../javax/servlet/ServletRequest.html "interface in javax.servlet")

Returns:

the AsyncContext that was created or reinitialized by the most recent invocation of startAsync() or[startAsync(ServletRequest,ServletResponse)](../../javax/servlet/ServletRequestWrapper.html#startAsync%28javax.servlet.ServletRequest, javax.servlet.ServletResponse%29) on the wrapped request

Throws:

IllegalStateException - if this request has not been put into asynchronous mode, i.e., if neither startAsync() nor[startAsync(ServletRequest,ServletResponse)](../../javax/servlet/ServletRequestWrapper.html#startAsync%28javax.servlet.ServletRequest, javax.servlet.ServletResponse%29) has been called

Since:

Servlet 3.0

See Also:

ServletRequest#getAsyncContext


isWrapperFor

public boolean isWrapperFor(ServletRequest wrapped)

Checks (recursively) if this ServletRequestWrapper wraps the givenServletRequest instance.

Parameters:

wrapped - the ServletRequest instance to search for

Returns:

true if this ServletRequestWrapper wraps the given ServletRequest instance, false otherwise

Since:

Servlet 3.0


isWrapperFor

public boolean isWrapperFor(java.lang.Class wrappedType)

Checks (recursively) if this ServletRequestWrapper wraps aServletRequest of the given class type.

Parameters:

wrappedType - the ServletRequest class type to search for

Returns:

true if this ServletRequestWrapper wraps a ServletRequest of the given class type, false otherwise

Throws:

IllegalArgumentException - if the given class does not implement ServletRequest

Since:

Servlet 3.0


getDispatcherType

public DispatcherType getDispatcherType()

Gets the dispatcher type of the wrapped request.

Specified by:

[getDispatcherType](../../javax/servlet/ServletRequest.html#getDispatcherType%28%29) in interface [ServletRequest](../../javax/servlet/ServletRequest.html "interface in javax.servlet")

Returns:

the dispatcher type of the wrapped request

Since:

Servlet 3.0

See Also:

ServletRequest#getDispatcherType



Submit a bug or feature

Copyright © 2009-2011, Oracle Corporation and/or its affiliates. All Rights Reserved. Use is subject to license terms.

Generated on 10-February-2011 12:41

Scripting on this page tracks web page traffic, but does not change the content in any way.