Class ServletRequestWrapper
java.lang.Object
javax.servlet.ServletRequestWrapper
- All Implemented Interfaces:
ServletRequest
- Direct Known Subclasses:
HttpServletRequestWrapper
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:
-
Constructor Summary
ConstructorsConstructorDescriptionServletRequestWrapper(ServletRequest request) Creates a ServletRequest adaptor wrapping the given request object. -
Method Summary
Modifier and TypeMethodDescriptionThe default behavior of this method is to return getAsyncContext() on the wrapped request object.getAttribute(String name) The default behavior of this method is to call getAttribute(String name) on the wrapped request object.The default behavior of this method is to return getAttributeNames() on the wrapped request object.The default behavior of this method is to return getCharacterEncoding() on the wrapped request object.intThe default behavior of this method is to return getContentLength() on the wrapped request object.longThe default behavior of this method is to return getContentLengthLong() on the wrapped request object.The default behavior of this method is to return getContentType() on the wrapped request object.The default behavior of this method is to call getDispatcherType() on the wrapped request object.The default behavior of this method is to return getInputStream() on the wrapped request object.The default behavior of this method is to return getLocalAddr() on the wrapped request object.The default behavior of this method is to return getLocale() on the wrapped request object.The default behavior of this method is to return getLocales() on the wrapped request object.The default behavior of this method is to return getLocalName() on the wrapped request object.intThe default behavior of this method is to return getLocalPort() on the wrapped request object.getParameter(String name) The default behavior of this method is to return getParameter(String name) on the wrapped request object.The default behavior of this method is to return getParameterMap() on the wrapped request object.The default behavior of this method is to return getParameterNames() on the wrapped request object.String[]getParameterValues(String name) The default behavior of this method is to return getParameterValues(String name) on the wrapped request object.The default behavior of this method is to return getProtocol() on the wrapped request object.The default behavior of this method is to return getReader() on the wrapped request object.getRealPath(String path) Deprecated.As of Version 3.0 of the Java Servlet APIThe default behavior of this method is to return getRemoteAddr() on the wrapped request object.The default behavior of this method is to return getRemoteHost() on the wrapped request object.intThe default behavior of this method is to return getRemotePort() on the wrapped request object.Get the wrapped request.getRequestDispatcher(String path) The default behavior of this method is to return getRequestDispatcher(String path) on the wrapped request object.The default behavior of this method is to return getScheme() on the wrapped request object.The default behavior of this method is to return getServerName() on the wrapped request object.intThe default behavior of this method is to return getServerPort() on the wrapped request object.The default behavior of this method is to return getServletContext() on the wrapped request object.booleanThe default behavior of this method is to return isAsyncStarted() on the wrapped request object.booleanThe default behavior of this method is to return isAsyncSupported() on the wrapped request object.booleanisSecure()The default behavior of this method is to return isSecure() on the wrapped request object.booleanisWrapperFor(Class<?> wrappedType) TODO SERVLET3 - Add commentsbooleanisWrapperFor(ServletRequest wrapped) TODO SERVLET3 - Add commentsvoidremoveAttribute(String name) The default behavior of this method is to call removeAttribute(String name) on the wrapped request object.voidsetAttribute(String name, Object o) The default behavior of this method is to return setAttribute(String name, Object o) on the wrapped request object.voidThe default behavior of this method is to set the character encoding on the wrapped request object.voidsetRequest(ServletRequest request) Sets the request object being wrapped.The default behavior of this method is to return startAsync() on the wrapped request object.startAsync(ServletRequest servletRequest, ServletResponse servletResponse) The default behavior of this method is to return startAsync(Runnable) on the wrapped request object.
-
Constructor Details
-
ServletRequestWrapper
Creates a ServletRequest adaptor wrapping the given request object.- Parameters:
request- The request to wrap- Throws:
IllegalArgumentException- if the request is null
-
-
Method Details
-
getRequest
-
setRequest
Sets the request object being wrapped.- Parameters:
request- The new wrapped request.- Throws:
IllegalArgumentException- if the request is null.
-
getAttribute
The default behavior of this method is to call getAttribute(String name) on the wrapped request object.- Specified by:
getAttributein interfaceServletRequest- Parameters:
name- aStringspecifying the name of the attribute- Returns:
- an
Objectcontaining the value of the attribute, ornullif the attribute does not exist
-
getAttributeNames
The default behavior of this method is to return getAttributeNames() on the wrapped request object.- Specified by:
getAttributeNamesin interfaceServletRequest- Returns:
- an
Enumerationof strings containing the names of the request's attributes
-
getCharacterEncoding
The default behavior of this method is to return getCharacterEncoding() on the wrapped request object.- Specified by:
getCharacterEncodingin interfaceServletRequest- Returns:
- a
Stringcontaining the name of the character encoding, ornullif the request does not specify a character encoding
-
setCharacterEncoding
The default behavior of this method is to set the character encoding on the wrapped request object.- Specified by:
setCharacterEncodingin interfaceServletRequest- Parameters:
enc- aStringcontaining the name of the character encoding- Throws:
UnsupportedEncodingException- if this is not a valid encoding
-
getContentLength
public int getContentLength()The default behavior of this method is to return getContentLength() on the wrapped request object.- Specified by:
getContentLengthin interfaceServletRequest- Returns:
- an integer containing the length of the request body or -1 if the length is not known or is greater than
Integer.MAX_VALUE
-
getContentLengthLong
public long getContentLengthLong()The default behavior of this method is to return getContentLengthLong() on the wrapped request object.- Specified by:
getContentLengthLongin interfaceServletRequest- Returns:
- a long integer containing the length of the request body or -1 if the length is not known
- Since:
- Servlet 3.1
-
getContentType
The default behavior of this method is to return getContentType() on the wrapped request object.- Specified by:
getContentTypein interfaceServletRequest- Returns:
- a
Stringcontaining the name of the MIME type of the request, or null if the type is not known
-
getInputStream
The default behavior of this method is to return getInputStream() on the wrapped request object.- Specified by:
getInputStreamin interfaceServletRequest- Returns:
- a
ServletInputStreamobject containing the body of the request - Throws:
IOException- if an input or output exception occurred
-
getParameter
The default behavior of this method is to return getParameter(String name) on the wrapped request object.- Specified by:
getParameterin interfaceServletRequest- Parameters:
name- aStringspecifying the name of the parameter- Returns:
- a
Stringrepresenting the single value of the parameter - See Also:
-
getParameterMap
The default behavior of this method is to return getParameterMap() on the wrapped request object.- Specified by:
getParameterMapin interfaceServletRequest- 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
The default behavior of this method is to return getParameterNames() on the wrapped request object.- Specified by:
getParameterNamesin interfaceServletRequest- Returns:
- an
EnumerationofStringobjects, eachStringcontaining the name of a request parameter; or an emptyEnumerationif the request has no parameters
-
getParameterValues
The default behavior of this method is to return getParameterValues(String name) on the wrapped request object.- Specified by:
getParameterValuesin interfaceServletRequest- Parameters:
name- aStringcontaining the name of the parameter whose value is requested- Returns:
- an array of
Stringobjects containing the parameter's values - See Also:
-
getProtocol
The default behavior of this method is to return getProtocol() on the wrapped request object.- Specified by:
getProtocolin interfaceServletRequest- Returns:
- a
Stringcontaining the protocol name and version number
-
getScheme
The default behavior of this method is to return getScheme() on the wrapped request object.- Specified by:
getSchemein interfaceServletRequest- Returns:
- a
Stringcontaining the name of the scheme used to make this request
-
getServerName
The default behavior of this method is to return getServerName() on the wrapped request object.- Specified by:
getServerNamein interfaceServletRequest- Returns:
- a
Stringcontaining 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:
getServerPortin interfaceServletRequest- Returns:
- an integer specifying the port number
-
getReader
The default behavior of this method is to return getReader() on the wrapped request object.- Specified by:
getReaderin interfaceServletRequest- Returns:
- a
BufferedReadercontaining the body of the request - Throws:
IOException- if an input or output exception occurred- See Also:
-
getRemoteAddr
The default behavior of this method is to return getRemoteAddr() on the wrapped request object.- Specified by:
getRemoteAddrin interfaceServletRequest- Returns:
- a
Stringcontaining the IP address of the client that sent the request
-
getRemoteHost
The default behavior of this method is to return getRemoteHost() on the wrapped request object.- Specified by:
getRemoteHostin interfaceServletRequest- Returns:
- a
Stringcontaining the fully qualified name of the client
-
setAttribute
The default behavior of this method is to return setAttribute(String name, Object o) on the wrapped request object.- Specified by:
setAttributein interfaceServletRequest- Parameters:
name- aStringspecifying the name of the attributeo- theObjectto be stored
-
removeAttribute
The default behavior of this method is to call removeAttribute(String name) on the wrapped request object.- Specified by:
removeAttributein interfaceServletRequest- Parameters:
name- aStringspecifying the name of the attribute to remove
-
getLocale
The default behavior of this method is to return getLocale() on the wrapped request object.- Specified by:
getLocalein interfaceServletRequest- Returns:
- the preferred
Localefor the client
-
getLocales
The default behavior of this method is to return getLocales() on the wrapped request object.- Specified by:
getLocalesin interfaceServletRequest- Returns:
- an
Enumerationof preferredLocaleobjects for the client
-
isSecure
public boolean isSecure()The default behavior of this method is to return isSecure() on the wrapped request object.- Specified by:
isSecurein interfaceServletRequest- Returns:
- a boolean indicating if the request was made using a secure channel
-
getRequestDispatcher
The default behavior of this method is to return getRequestDispatcher(String path) on the wrapped request object.- Specified by:
getRequestDispatcherin interfaceServletRequest- Parameters:
path- aStringspecifying the pathname to the resource. If it is relative, it must be relative against the current servlet.- Returns:
- a
RequestDispatcherobject that acts as a wrapper for the resource at the specified path, ornullif the servlet container cannot return aRequestDispatcher - See Also:
-
getRealPath
Deprecated.As of Version 3.0 of the Java Servlet APIThe default behavior of this method is to return getRealPath(String path) on the wrapped request object.- Specified by:
getRealPathin interfaceServletRequest- Parameters:
path- The virtual path to be converted to a real path- Returns:
ServletContext.getRealPath(String)
-
getRemotePort
public int getRemotePort()The default behavior of this method is to return getRemotePort() on the wrapped request object.- Specified by:
getRemotePortin interfaceServletRequest- Returns:
- an integer specifying the port number
- Since:
- Servlet 2.4
-
getLocalName
The default behavior of this method is to return getLocalName() on the wrapped request object.- Specified by:
getLocalNamein interfaceServletRequest- Returns:
- a
Stringcontaining the host name of the IP on which the request was received. - Since:
- Servlet 2.4
-
getLocalAddr
The default behavior of this method is to return getLocalAddr() on the wrapped request object.- Specified by:
getLocalAddrin interfaceServletRequest- Returns:
- a
Stringcontaining 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:
getLocalPortin interfaceServletRequest- Returns:
- an integer specifying the port number
- Since:
- Servlet 2.4
-
getServletContext
The default behavior of this method is to return getServletContext() on the wrapped request object.- Specified by:
getServletContextin interfaceServletRequest- Returns:
- TODO
- Since:
- Servlet 3.0
-
startAsync
The default behavior of this method is to return startAsync() on the wrapped request object.- Specified by:
startAsyncin interfaceServletRequest- Returns:
- TODO
- Throws:
IllegalStateException- If asynchronous processing is not supported for this request or if the request is already in asynchronous mode- Since:
- Servlet 3.0
-
startAsync
public AsyncContext startAsync(ServletRequest servletRequest, ServletResponse servletResponse) throws IllegalStateException The default behavior of this method is to return startAsync(Runnable) on the wrapped request object.- Specified by:
startAsyncin interfaceServletRequest- Parameters:
servletRequest- The ServletRequest with which to initialise the asynchronous contextservletResponse- The ServletResponse with which to initialise the asynchronous context- Returns:
- TODO
- Throws:
IllegalStateException- If asynchronous processing is not supported for this request or if the request is already in asynchronous mode- Since:
- Servlet 3.0
-
isAsyncStarted
public boolean isAsyncStarted()The default behavior of this method is to return isAsyncStarted() on the wrapped request object.- Specified by:
isAsyncStartedin interfaceServletRequest- Returns:
- TODO
- Since:
- Servlet 3.0
-
isAsyncSupported
public boolean isAsyncSupported()The default behavior of this method is to return isAsyncSupported() on the wrapped request object.- Specified by:
isAsyncSupportedin interfaceServletRequest- Returns:
- TODO
- Since:
- Servlet 3.0
-
getAsyncContext
The default behavior of this method is to return getAsyncContext() on the wrapped request object.- Specified by:
getAsyncContextin interfaceServletRequest- Returns:
- The current AsyncContext
- Since:
- Servlet 3.0
-
isWrapperFor
TODO SERVLET3 - Add comments- Parameters:
wrapped- The request to compare to the wrapped request- Returns:
trueif the request wrapped by this wrapper (or series of wrappers) is the same as the supplied request, otherwisefalse- Since:
- Servlet 3.0
-
isWrapperFor
TODO SERVLET3 - Add comments- Parameters:
wrappedType- The class to compare to the class of the wrapped request- Returns:
trueif the request wrapped by this wrapper (or series of wrappers) is the same type as the supplied type, otherwisefalse- Since:
- Servlet 3.0
-
getDispatcherType
The default behavior of this method is to call getDispatcherType() on the wrapped request object.- Specified by:
getDispatcherTypein interfaceServletRequest- Returns:
- TODO
- Since:
- Servlet 3.0
-