Package jakarta.servlet
Class ServletRequestWrapper
java.lang.Object
jakarta.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 SummaryConstructorsConstructorDescriptionServletRequestWrapper(ServletRequest request) Creates a ServletRequest adaptor wrapping the given request object.
- 
Method SummaryModifier and TypeMethodDescriptionGets the AsyncContext that was created or reinitialized by the most recent invocation ofstartAsync()orstartAsync(ServletRequest,ServletResponse)on the wrapped request.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.Gets the dispatcher type of the wrapped request.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.Gets the protocol defined request ID, if any, for the wrapped request.The default behavior of this method is to return getReader() on the wrapped request object.The 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.Return the wrapped request object.getRequestDispatcher(String path) The default behavior of this method is to return getRequestDispatcher(String path) on the wrapped request object.Gets the request ID for the wrapped request.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.Gets the connection information for the wrapped request.Gets the servlet context to which the wrapped servlet request was last dispatched.booleanChecks if the wrapped request has been put into asynchronous mode.booleanChecks if the wrapped request supports asynchronous operation.booleanisSecure()The default behavior of this method is to return isSecure() on the wrapped request object.booleanisWrapperFor(ServletRequest wrapped) Checks (recursively) if this ServletRequestWrapper wraps the givenServletRequestinstance.booleanisWrapperFor(Class<?> wrappedType) Checks (recursively) if this ServletRequestWrapper wraps aServletRequestof the given class type.voidremoveAttribute(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.voidsetCharacterEncoding(String encoding) The default behavior of this method is to set the character encoding on the wrapped request object.voidsetCharacterEncoding(Charset encoding) 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.The default behavior of this method is to invokeServletRequest.startAsync()on the wrapped request object.startAsync(ServletRequest servletRequest, ServletResponse servletResponse) The default behavior of this method is to invokeServletRequest.startAsync(ServletRequest, ServletResponse)on the wrapped request object.
- 
Constructor Details- 
ServletRequestWrapperCreates a ServletRequest adaptor wrapping the given request object.- Parameters:
- request- the- ServletRequestto be wrapped
- Throws:
- IllegalArgumentException- if the request is null
 
 
- 
- 
Method Details- 
getRequestReturn the wrapped request object.- Returns:
- the wrapped ServletRequest
 
- 
setRequestSets the request object being wrapped.- Parameters:
- request- the- ServletRequestto be installed
- Throws:
- IllegalArgumentException- if the request is null.
 
- 
getAttributeThe 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
 
- 
getAttributeNamesThe 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
 
- 
getCharacterEncodingThe 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
 
- 
setCharacterEncodingThe default behavior of this method is to set the character encoding on the wrapped request object.- Specified by:
- setCharacterEncodingin interface- ServletRequest
- Parameters:
- encoding-- Stringcontaining the name of the character encoding.
- Throws:
- UnsupportedEncodingException- if this ServletRequest is still in a state where a character encoding may be set, but the specified encoding is invalid
 
- 
setCharacterEncodingThe default behavior of this method is to set the character encoding on the wrapped request object.- Specified by:
- setCharacterEncodingin interface- ServletRequest
- Parameters:
- encoding-- Charsetrepresenting the character encoding.
- Since:
- Servlet 6.1
 
- 
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 containing the length of the request body or -1L if the length is not known
- Since:
- Servlet 3.1
 
- 
getContentTypeThe 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
 
- 
getInputStreamThe 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:
- IOException- if an input or output exception occurred
 
- 
getParameterThe 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:
 
- 
getParameterMapThe 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.
 
- 
getParameterNamesThe 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
 
- 
getParameterValuesThe 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:
 
- 
getProtocolThe 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
 
- 
getSchemeThe 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
 
- 
getServerNameThe 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
 
- 
getReaderThe 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:
- IOException- if an input or output exception occurred
- See Also:
 
- 
getRemoteAddrThe default behavior of this method is to return getRemoteAddr() on the wrapped request object.- Specified by:
- getRemoteAddrin interface- ServletRequest
- Returns:
- a Stringcontaining an IP address
 
- 
getRemoteHostThe default behavior of this method is to return getRemoteHost() on the wrapped request object.- Specified by:
- getRemoteHostin interface- ServletRequest
- Returns:
- a Stringcontaining a fully qualified name or IP address.
 
- 
setAttributeThe 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
 
- 
removeAttributeThe 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
 
- 
getLocaleThe 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
 
- 
getLocalesThe 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
 
- 
getRequestDispatcherThe 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:
 
- 
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
 
- 
getLocalNameThe 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
 
- 
getLocalAddrThe default behavior of this method is to return getLocalAddr() on the wrapped request object.- Specified by:
- getLocalAddrin interface- ServletRequest
- Returns:
- a Stringcontaining an IP address.
- 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 a port number
- Since:
- Servlet 2.4
 
- 
getServletContextGets the servlet context to which the wrapped servlet request was last dispatched.- Specified by:
- getServletContextin interface- ServletRequest
- Returns:
- the servlet context to which the wrapped servlet request was last dispatched
- Since:
- Servlet 3.0
 
- 
startAsyncThe default behavior of this method is to invokeServletRequest.startAsync()on the wrapped request object.- Specified by:
- startAsyncin interface- ServletRequest
- 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:
 
- 
startAsyncpublic AsyncContext startAsync(ServletRequest servletRequest, ServletResponse servletResponse) throws IllegalStateException The default behavior of this method is to invokeServletRequest.startAsync(ServletRequest, ServletResponse)on the wrapped request object.- Specified by:
- startAsyncin interface- ServletRequest
- 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:
 
- 
isAsyncStartedpublic boolean isAsyncStarted()Checks if the wrapped request has been put into asynchronous mode.- Specified by:
- isAsyncStartedin interface- ServletRequest
- Returns:
- true if this request has been put into asynchronous mode, false otherwise
- Since:
- Servlet 3.0
- See Also:
 
- 
isAsyncSupportedpublic boolean isAsyncSupported()Checks if the wrapped request supports asynchronous operation.- Specified by:
- isAsyncSupportedin interface- ServletRequest
- Returns:
- true if this request supports asynchronous operation, false otherwise
- Since:
- Servlet 3.0
- See Also:
 
- 
getAsyncContextGets the AsyncContext that was created or reinitialized by the most recent invocation ofstartAsync()orstartAsync(ServletRequest,ServletResponse)on the wrapped request.- Specified by:
- getAsyncContextin interface- ServletRequest
- Returns:
- the AsyncContext that was created or reinitialized by the most recent invocation of startAsync()orstartAsync(ServletRequest,ServletResponse)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)has been called
- Since:
- Servlet 3.0
- See Also:
 
- 
isWrapperForChecks (recursively) if this ServletRequestWrapper wraps the givenServletRequestinstance.- Parameters:
- wrapped- the ServletRequest instance to search for
- Returns:
- true if this ServletRequestWrapper wraps the given ServletRequest instance, false otherwise
- Since:
- Servlet 3.0
 
- 
isWrapperForChecks (recursively) if this ServletRequestWrapper wraps aServletRequestof 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
 
- 
getDispatcherTypeGets the dispatcher type of the wrapped request.- Specified by:
- getDispatcherTypein interface- ServletRequest
- Returns:
- the dispatcher type of the wrapped request
- Since:
- Servlet 3.0
- See Also:
 
- 
getRequestIdGets the request ID for the wrapped request.- Specified by:
- getRequestIdin interface- ServletRequest
- Returns:
- the request ID for the wrapped request
- Since:
- Servlet 6.0
 
- 
getProtocolRequestIdGets the protocol defined request ID, if any, for the wrapped request.- Specified by:
- getProtocolRequestIdin interface- ServletRequest
- Returns:
- the protocol defined request ID, if any, for the wrapped request
- Since:
- Servlet 6.0
 
- 
getServletConnectionGets the connection information for the wrapped request.- Specified by:
- getServletConnectionin interface- ServletRequest
- Returns:
- the connection information for the wrapped request
- Since:
- Servlet 6.0
 
 
-