Package javax.servlet
Class ServletRequestWrapper
- java.lang.Object
- 
- 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 SummaryConstructors Constructor Description ServletRequestWrapper(ServletRequest request)Creates a ServletRequest adaptor wrapping the given request object.
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description AsyncContextgetAsyncContext()The default behavior of this method is to return getAsyncContext() on the wrapped request object.java.lang.ObjectgetAttribute(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.StringgetCharacterEncoding()The default behavior of this method is to return getCharacterEncoding() on the wrapped request object.intgetContentLength()The default behavior of this method is to return getContentLength() on the wrapped request object.longgetContentLengthLong()The default behavior of this method is to return getContentLengthLong() on the wrapped request object.java.lang.StringgetContentType()The default behavior of this method is to return getContentType() on the wrapped request object.DispatcherTypegetDispatcherType()The default behavior of this method is to call getDispatcherType() on the wrapped request object.ServletInputStreamgetInputStream()The default behavior of this method is to return getInputStream() on the wrapped request object.java.lang.StringgetLocalAddr()The default behavior of this method is to return getLocalAddr() on the wrapped request object.java.util.LocalegetLocale()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.StringgetLocalName()The default behavior of this method is to return getLocalName() on the wrapped request object.intgetLocalPort()The default behavior of this method is to return getLocalPort() on the wrapped request object.java.lang.StringgetParameter(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.StringgetProtocol()The default behavior of this method is to return getProtocol() on the wrapped request object.java.io.BufferedReadergetReader()The default behavior of this method is to return getReader() on the wrapped request object.java.lang.StringgetRealPath(java.lang.String path)Deprecated.As of Version 3.0 of the Java Servlet APIjava.lang.StringgetRemoteAddr()The default behavior of this method is to return getRemoteAddr() on the wrapped request object.java.lang.StringgetRemoteHost()The default behavior of this method is to return getRemoteHost() on the wrapped request object.intgetRemotePort()The default behavior of this method is to return getRemotePort() on the wrapped request object.ServletRequestgetRequest()Get the wrapped request.RequestDispatchergetRequestDispatcher(java.lang.String path)The default behavior of this method is to return getRequestDispatcher(String path) on the wrapped request object.java.lang.StringgetScheme()The default behavior of this method is to return getScheme() on the wrapped request object.java.lang.StringgetServerName()The default behavior of this method is to return getServerName() on the wrapped request object.intgetServerPort()The default behavior of this method is to return getServerPort() on the wrapped request object.ServletContextgetServletContext()The default behavior of this method is to return getServletContext() on the wrapped request object.booleanisAsyncStarted()The default behavior of this method is to return isAsyncStarted() on the wrapped request object.booleanisAsyncSupported()The 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(java.lang.Class<?> wrappedType)TODO SERVLET3 - Add commentsbooleanisWrapperFor(ServletRequest wrapped)TODO SERVLET3 - Add commentsvoidremoveAttribute(java.lang.String name)The default behavior of this method is to call removeAttribute(String name) on the wrapped request object.voidsetAttribute(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.voidsetCharacterEncoding(java.lang.String enc)The 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.AsyncContextstartAsync()The default behavior of this method is to return startAsync() on the wrapped request object.AsyncContextstartAsync(ServletRequest servletRequest, ServletResponse servletResponse)The default behavior of this method is to return startAsync(Runnable) on the wrapped request object.
 
- 
- 
- 
Constructor Detail- 
ServletRequestWrapperpublic ServletRequestWrapper(ServletRequest request) Creates a ServletRequest adaptor wrapping the given request object.- Parameters:
- request- The request to wrap
- Throws:
- java.lang.IllegalArgumentException- if the request is null
 
 
- 
 - 
Method Detail- 
getRequestpublic ServletRequest getRequest() Get the wrapped request.- Returns:
- the wrapped request object
 
 - 
setRequestpublic void setRequest(ServletRequest request) Sets the request object being wrapped.- Parameters:
- request- The new wrapped request.
- Throws:
- java.lang.IllegalArgumentException- if the request is null.
 
 - 
getAttributepublic 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:
- getAttributein interface- ServletRequest
- Parameters:
- name- a- Stringspecifying the name of the attribute
- Returns:
- an Objectcontaining the value of the attribute, ornullif the attribute does not exist
 
 - 
getAttributeNamespublic java.util.Enumeration<java.lang.String> getAttributeNames() The default behavior of this method is to return getAttributeNames() on the wrapped request object.- Specified by:
- getAttributeNamesin interface- ServletRequest
- Returns:
- an Enumerationof strings containing the names of the request's attributes
 
 - 
getCharacterEncodingpublic java.lang.String getCharacterEncoding() The default behavior of this method is to return getCharacterEncoding() on the wrapped request object.- Specified by:
- getCharacterEncodingin interface- ServletRequest
- Returns:
- a Stringcontaining the name of the character encoding, ornullif the request does not specify a character encoding
 
 - 
setCharacterEncodingpublic void setCharacterEncoding(java.lang.String enc) throws java.io.UnsupportedEncodingExceptionThe default behavior of this method is to set the character encoding on the wrapped request object.- Specified by:
- setCharacterEncodingin interface- ServletRequest
- Parameters:
- enc- a- Stringcontaining the name of the character encoding
- Throws:
- java.io.UnsupportedEncodingException- if this is not a valid encoding
 
 - 
getContentLengthpublic int getContentLength() The default behavior of this method is to return getContentLength() on the wrapped request object.- Specified by:
- getContentLengthin interface- ServletRequest
- 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
 
 - 
getContentLengthLongpublic long getContentLengthLong() The default behavior of this method is to return getContentLengthLong() on the wrapped request object.- Specified by:
- getContentLengthLongin interface- ServletRequest
- Returns:
- a long integer containing the length of the request body or -1 if the length is not known
- Since:
- Servlet 3.1
 
 - 
getContentTypepublic java.lang.String getContentType() The default behavior of this method is to return getContentType() on the wrapped request object.- Specified by:
- getContentTypein interface- ServletRequest
- Returns:
- a Stringcontaining the name of the MIME type of the request, or null if the type is not known
 
 - 
getInputStreampublic ServletInputStream getInputStream() throws java.io.IOException The default behavior of this method is to return getInputStream() on the wrapped request object.- Specified by:
- getInputStreamin interface- ServletRequest
- Returns:
- a ServletInputStreamobject containing the body of the request
- Throws:
- java.io.IOException- if an input or output exception occurred
 
 - 
getParameterpublic 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:
- getParameterin interface- ServletRequest
- Parameters:
- name- a- Stringspecifying the name of the parameter
- Returns:
- a Stringrepresenting the single value of the parameter
- See Also:
- ServletRequest.getParameterValues(java.lang.String)
 
 - 
getParameterMappublic 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:
- getParameterMapin interface- ServletRequest
- 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.
 
 - 
getParameterNamespublic java.util.Enumeration<java.lang.String> getParameterNames() The default behavior of this method is to return getParameterNames() on the wrapped request object.- Specified by:
- getParameterNamesin interface- ServletRequest
- Returns:
- an EnumerationofStringobjects, eachStringcontaining the name of a request parameter; or an emptyEnumerationif the request has no parameters
 
 - 
getParameterValuespublic 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:
- getParameterValuesin interface- ServletRequest
- Parameters:
- name- a- Stringcontaining the name of the parameter whose value is requested
- Returns:
- an array of Stringobjects containing the parameter's values
- See Also:
- ServletRequest.getParameter(java.lang.String)
 
 - 
getProtocolpublic java.lang.String getProtocol() The default behavior of this method is to return getProtocol() on the wrapped request object.- Specified by:
- getProtocolin interface- ServletRequest
- Returns:
- a Stringcontaining the protocol name and version number
 
 - 
getSchemepublic java.lang.String getScheme() The default behavior of this method is to return getScheme() on the wrapped request object.- Specified by:
- getSchemein interface- ServletRequest
- Returns:
- a Stringcontaining the name of the scheme used to make this request
 
 - 
getServerNamepublic java.lang.String getServerName() The default behavior of this method is to return getServerName() on the wrapped request object.- Specified by:
- getServerNamein interface- ServletRequest
- Returns:
- a Stringcontaining the name of the server
 
 - 
getServerPortpublic int getServerPort() The default behavior of this method is to return getServerPort() on the wrapped request object.- Specified by:
- getServerPortin interface- ServletRequest
- Returns:
- an integer specifying the port number
 
 - 
getReaderpublic java.io.BufferedReader getReader() throws java.io.IOExceptionThe default behavior of this method is to return getReader() on the wrapped request object.- Specified by:
- getReaderin interface- ServletRequest
- Returns:
- a BufferedReadercontaining 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()
 
 - 
getRemoteAddrpublic java.lang.String getRemoteAddr() The default behavior of this method is to return getRemoteAddr() on the wrapped request object.- Specified by:
- getRemoteAddrin interface- ServletRequest
- Returns:
- a Stringcontaining the IP address of the client that sent the request
 
 - 
getRemoteHostpublic java.lang.String getRemoteHost() The default behavior of this method is to return getRemoteHost() on the wrapped request object.- Specified by:
- getRemoteHostin interface- ServletRequest
- Returns:
- a Stringcontaining the fully qualified name of the client
 
 - 
setAttributepublic 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:
- setAttributein interface- ServletRequest
- Parameters:
- name- a- Stringspecifying the name of the attribute
- o- the- Objectto be stored
 
 - 
removeAttributepublic 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:
- removeAttributein interface- ServletRequest
- Parameters:
- name- a- Stringspecifying the name of the attribute to remove
 
 - 
getLocalepublic java.util.Locale getLocale() The default behavior of this method is to return getLocale() on the wrapped request object.- Specified by:
- getLocalein interface- ServletRequest
- Returns:
- the preferred Localefor the client
 
 - 
getLocalespublic java.util.Enumeration<java.util.Locale> getLocales() The default behavior of this method is to return getLocales() on the wrapped request object.- Specified by:
- getLocalesin interface- ServletRequest
- Returns:
- an Enumerationof preferredLocaleobjects for the client
 
 - 
isSecurepublic boolean isSecure() The default behavior of this method is to return isSecure() on the wrapped request object.- Specified by:
- isSecurein interface- ServletRequest
- Returns:
- a boolean indicating if the request was made using a secure channel
 
 - 
getRequestDispatcherpublic 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:
- getRequestDispatcherin interface- ServletRequest
- Parameters:
- path- a- Stringspecifying 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:
- RequestDispatcher,- ServletContext.getRequestDispatcher(java.lang.String)
 
 - 
getRealPath@Deprecated public java.lang.String getRealPath(java.lang.String path) 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 interface- ServletRequest
- Parameters:
- path- The virtual path to be converted to a real path
- Returns:
- ServletContext.getRealPath(String)
 
 - 
getRemotePortpublic int getRemotePort() The default behavior of this method is to return getRemotePort() on the wrapped request object.- Specified by:
- getRemotePortin interface- ServletRequest
- Returns:
- an integer specifying the port number
- Since:
- Servlet 2.4
 
 - 
getLocalNamepublic java.lang.String getLocalName() The default behavior of this method is to return getLocalName() on the wrapped request object.- Specified by:
- getLocalNamein interface- ServletRequest
- Returns:
- a Stringcontaining the host name of the IP on which the request was received.
- Since:
- Servlet 2.4
 
 - 
getLocalAddrpublic java.lang.String getLocalAddr() The default behavior of this method is to return getLocalAddr() on the wrapped request object.- Specified by:
- getLocalAddrin interface- ServletRequest
- Returns:
- a Stringcontaining the IP address on which the request was received.
- Since:
- Servlet 2.4
 
 - 
getLocalPortpublic int getLocalPort() The default behavior of this method is to return getLocalPort() on the wrapped request object.- Specified by:
- getLocalPortin interface- ServletRequest
- Returns:
- an integer specifying the port number
- Since:
- Servlet 2.4
 
 - 
getServletContextpublic ServletContext getServletContext() The default behavior of this method is to return getServletContext() on the wrapped request object.- Specified by:
- getServletContextin interface- ServletRequest
- Returns:
- TODO
- Since:
- Servlet 3.0
 
 - 
startAsyncpublic AsyncContext startAsync() throws java.lang.IllegalStateException The default behavior of this method is to return startAsync() on the wrapped request object.- Specified by:
- startAsyncin interface- ServletRequest
- Returns:
- TODO
- Throws:
- java.lang.IllegalStateException- If asynchronous processing is not supported for this request or if the request is already in asynchronous mode
- Since:
- Servlet 3.0
 
 - 
startAsyncpublic AsyncContext startAsync(ServletRequest servletRequest, ServletResponse servletResponse) throws java.lang.IllegalStateException The default behavior of this method is to return startAsync(Runnable) on the wrapped request object.- Specified by:
- startAsyncin interface- ServletRequest
- Parameters:
- servletRequest- The ServletRequest with which to initialise the asynchronous context
- servletResponse- The ServletResponse with which to initialise the asynchronous context
- Returns:
- TODO
- Throws:
- java.lang.IllegalStateException- If asynchronous processing is not supported for this request or if the request is already in asynchronous mode
- Since:
- Servlet 3.0
 
 - 
isAsyncStartedpublic boolean isAsyncStarted() The default behavior of this method is to return isAsyncStarted() on the wrapped request object.- Specified by:
- isAsyncStartedin interface- ServletRequest
- Returns:
- TODO
- Since:
- Servlet 3.0
 
 - 
isAsyncSupportedpublic boolean isAsyncSupported() The default behavior of this method is to return isAsyncSupported() on the wrapped request object.- Specified by:
- isAsyncSupportedin interface- ServletRequest
- Returns:
- TODO
- Since:
- Servlet 3.0
 
 - 
getAsyncContextpublic AsyncContext getAsyncContext() The default behavior of this method is to return getAsyncContext() on the wrapped request object.- Specified by:
- getAsyncContextin interface- ServletRequest
- Returns:
- The current AsyncContext
- Since:
- Servlet 3.0
 
 - 
isWrapperForpublic boolean isWrapperFor(ServletRequest wrapped) 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, otherwise- false
- Since:
- Servlet 3.0
 
 - 
isWrapperForpublic boolean isWrapperFor(java.lang.Class<?> wrappedType) 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, otherwise- false
- Since:
- Servlet 3.0
 
 - 
getDispatcherTypepublic DispatcherType getDispatcherType() The default behavior of this method is to call getDispatcherType() on the wrapped request object.- Specified by:
- getDispatcherTypein interface- ServletRequest
- Returns:
- TODO
- Since:
- Servlet 3.0
 
 
- 
 
-