ServletRequestWrapper (Servlet 4.0 API Documentation - Apache Tomcat 9.0.106)
Description: declaration: package: javax.servlet, class: ServletRequestWrapper

# Class ServletRequestWrapper

java.lang.Object
javax.servlet.ServletRequestWrapper

All Implemented Interfaces:
  `ServletRequest`

Direct Known Subclasses:
  `HttpServletRequestWrapper`

public class ServletRequestWrapper extends 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

  Constructors
  Constructor
  Description
  `ServletRequestWrapper(ServletRequest request)`
  Creates a ServletRequest adaptor wrapping the given request object.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `AsyncContext`
  `getAsyncContext()`
  The default behavior of this method is to return getAsyncContext() on the wrapped request object.
  `Object`
  `getAttribute(String name)`
  The default behavior of this method is to call getAttribute(String name) on the wrapped request object.
  `Enumeration<String>`
  `getAttributeNames()`
  The default behavior of this method is to return getAttributeNames() on the wrapped request object.
  `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.
  `long`
  `getContentLengthLong()`
  The default behavior of this method is to return getContentLengthLong() on the wrapped request object.
  `String`
  `getContentType()`
  The default behavior of this method is to return getContentType() on the wrapped request object.
  `DispatcherType`
  `getDispatcherType()`
  The default behavior of this method is to call getDispatcherType() on the wrapped request object.
  `ServletInputStream`
  `getInputStream()`
  The default behavior of this method is to return getInputStream() on the wrapped request object.
  `String`
  `getLocalAddr()`
  The default behavior of this method is to return getLocalAddr() on the wrapped request object.
  `Locale`
  `getLocale()`
  The default behavior of this method is to return getLocale() on the wrapped request object.
  `Enumeration<Locale>`
  `getLocales()`
  The default behavior of this method is to return getLocales() on the wrapped request object.
  `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.
  `String`
  `getParameter(String name)`
  The default behavior of this method is to return getParameter(String name) on the wrapped request object.
  `Map<String,String[]>`
  `getParameterMap()`
  The default behavior of this method is to return getParameterMap() on the wrapped request object.
  `Enumeration<String>`
  `getParameterNames()`
  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.
  `String`
  `getProtocol()`
  The default behavior of this method is to return getProtocol() on the wrapped request object.
  `BufferedReader`
  `getReader()`
  The default behavior of this method is to return getReader() on the wrapped request object.
  `String`
  `getRealPath(String path)`
  Deprecated.
  As of Version 3.0 of the Java Servlet API
  `String`
  `getRemoteAddr()`
  The default behavior of this method is to return getRemoteAddr() on the wrapped request object.
  `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()`
  Get the wrapped request.
  `RequestDispatcher`
  `getRequestDispatcher(String path)`
  The default behavior of this method is to return getRequestDispatcher(String path) on the wrapped request object.
  `String`
  `getScheme()`
  The default behavior of this method is to return getScheme() on the wrapped request object.
  `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()`
  The default behavior of this method is to return getServletContext() on the wrapped request object.
  `boolean`
  `isAsyncStarted()`
  The default behavior of this method is to return isAsyncStarted() on the wrapped request object.
  `boolean`
  `isAsyncSupported()`
  The default behavior of this method is to return isAsyncSupported() on the wrapped request object.
  `boolean`
  `isSecure()`
  The default behavior of this method is to return isSecure() on the wrapped request object.
  `boolean`
  `isWrapperFor(Class<?> wrappedType)`
  TODO SERVLET3 - Add comments
  `boolean`
  `isWrapperFor(ServletRequest wrapped)`
  TODO SERVLET3 - Add comments
  `void`
  `removeAttribute(String name)`
  The default behavior of this method is to call removeAttribute(String name) on the wrapped request object.
  `void`
  `setAttribute(String name, Object o)`
  The default behavior of this method is to return setAttribute(String name, Object o) on the wrapped request object.
  `void`
  `setCharacterEncoding(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 return startAsync() on the wrapped request object.
  `AsyncContext`
  `startAsync(ServletRequest servletRequest, ServletResponse servletResponse)`
  The default behavior of this method is to return startAsync(Runnable) on the wrapped request object.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### ServletRequestWrapper

    public ServletRequestWrapper(ServletRequest request)
    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

    public ServletRequest getRequest()
    Get the wrapped request.
    Returns:
      the wrapped request object

  - ### setRequest

    public void setRequest(ServletRequest request)
    Sets the request object being wrapped.
    Parameters:
      `request` - The new wrapped request.
    Throws:
      `IllegalArgumentException` - if the request is null.

  - ### getAttribute

    public Object getAttribute(String name)
    The default behavior of this method is to call getAttribute(String name) on the wrapped request object.
    Specified by:
      `getAttribute` in interface `ServletRequest`
    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 Enumeration<String> getAttributeNames()
    The default behavior of this method is to return getAttributeNames() on the wrapped request object.
    Specified by:
      `getAttributeNames` in interface `ServletRequest`
    Returns:
      an `Enumeration` of strings containing the names of the request's attributes

  - ### getCharacterEncoding

    public String getCharacterEncoding()
    The default behavior of this method is to return getCharacterEncoding() on the wrapped request object.
    Specified by:
      `getCharacterEncoding` in interface `ServletRequest`
    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(String enc) throws UnsupportedEncodingException
    The default behavior of this method is to set the character encoding on the wrapped request object.
    Specified by:
      `setCharacterEncoding` in interface `ServletRequest`
    Parameters:
      `enc` - a `String` containing 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:
      `getContentLength` in 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`

  - ### getContentLengthLong

    public long getContentLengthLong()
    The default behavior of this method is to return getContentLengthLong() on the wrapped request object.
    Specified by:
      `getContentLengthLong` in 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

  - ### getContentType

    public String getContentType()
    The default behavior of this method is to return getContentType() on the wrapped request object.
    Specified by:
      `getContentType` in interface `ServletRequest`
    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 IOException
    The default behavior of this method is to return getInputStream() on the wrapped request object.
    Specified by:
      `getInputStream` in interface `ServletRequest`
    Returns:
      a `ServletInputStream` object containing the body of the request
    Throws:
      `IOException` - if an input or output exception occurred

  - ### getParameter

    public String getParameter(String name)
    The default behavior of this method is to return getParameter(String name) on the wrapped request object.
    Specified by:
      `getParameter` in interface `ServletRequest`
    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 Map<String,String[]> getParameterMap()
    The default behavior of this method is to return getParameterMap() on the wrapped request object.
    Specified by:
      `getParameterMap` in 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.

  - ### getParameterNames

    public Enumeration<String> getParameterNames()
    The default behavior of this method is to return getParameterNames() on the wrapped request object.
    Specified by:
      `getParameterNames` in interface `ServletRequest`
    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 String[] getParameterValues(String name)
    The default behavior of this method is to return getParameterValues(String name) on the wrapped request object.
    Specified by:
      `getParameterValues` in interface `ServletRequest`
    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 String getProtocol()
    The default behavior of this method is to return getProtocol() on the wrapped request object.
    Specified by:
      `getProtocol` in interface `ServletRequest`
    Returns:
      a `String` containing the protocol name and version number

  - ### getScheme

    public String getScheme()
    The default behavior of this method is to return getScheme() on the wrapped request object.
    Specified by:
      `getScheme` in interface `ServletRequest`
    Returns:
      a `String` containing the name of the scheme used to make this request

  - ### getServerName

    public String getServerName()
    The default behavior of this method is to return getServerName() on the wrapped request object.
    Specified by:
      `getServerName` in interface `ServletRequest`
    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` in interface `ServletRequest`
    Returns:
      an integer specifying the port number

  - ### getReader

    public BufferedReader getReader() throws IOException
    The default behavior of this method is to return getReader() on the wrapped request object.
    Specified by:
      `getReader` in interface `ServletRequest`
    Returns:
      a `BufferedReader` containing the body of the request
    Throws:
      `IOException` - if an input or output exception occurred
    See Also:
      - `ServletRequest.getInputStream()`

  - ### getRemoteAddr

    public String getRemoteAddr()
    The default behavior of this method is to return getRemoteAddr() on the wrapped request object.
    Specified by:
      `getRemoteAddr` in interface `ServletRequest`
    Returns:
      a `String` containing the IP address of the client that sent the request

  - ### getRemoteHost

    public String getRemoteHost()
    The default behavior of this method is to return getRemoteHost() on the wrapped request object.
    Specified by:
      `getRemoteHost` in interface `ServletRequest`
    Returns:
      a `String` containing the fully qualified name of the client

  - ### setAttribute

    public void setAttribute(String name, Object o)
    The default behavior of this method is to return setAttribute(String name, Object o) on the wrapped request object.
    Specified by:
      `setAttribute` in interface `ServletRequest`
    Parameters:
      `name` - a `String` specifying the name of the attribute
      `o` - the `Object` to be stored

  - ### removeAttribute

    public void removeAttribute(String name)
    The default behavior of this method is to call removeAttribute(String name) on the wrapped request object.
    Specified by:
      `removeAttribute` in interface `ServletRequest`
    Parameters:
      `name` - a `String` specifying the name of the attribute to remove

  - ### getLocale

    public Locale getLocale()
    The default behavior of this method is to return getLocale() on the wrapped request object.
    Specified by:
      `getLocale` in interface `ServletRequest`
    Returns:
      the preferred `Locale` for the client

  - ### getLocales

    public Enumeration<Locale> getLocales()
    The default behavior of this method is to return getLocales() on the wrapped request object.
    Specified by:
      `getLocales` in interface `ServletRequest`
    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` in interface `ServletRequest`
    Returns:
      a boolean indicating if the request was made using a secure channel

  - ### getRequestDispatcher

    public RequestDispatcher getRequestDispatcher(String path)
    The default behavior of this method is to return getRequestDispatcher(String path) on the wrapped request object.
    Specified by:
      `getRequestDispatcher` in interface `ServletRequest`
    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 a `RequestDispatcher`
    See Also:
      - `RequestDispatcher`
      - `ServletContext.getRequestDispatcher(java.lang.String)`

  - ### getRealPath

    @Deprecated public String getRealPath(String path)
    Deprecated.
    As of Version 3.0 of the Java Servlet API
    The default behavior of this method is to return getRealPath(String path) on the wrapped request object.
    Specified by:
      `getRealPath` in interface `ServletRequest`
    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:
      `getRemotePort` in interface `ServletRequest`
    Returns:
      an integer specifying the port number
    Since:
      Servlet 2.4

  - ### getLocalName

    public String getLocalName()
    The default behavior of this method is to return getLocalName() on the wrapped request object.
    Specified by:
      `getLocalName` in interface `ServletRequest`
    Returns:
      a `String` containing the host name of the IP on which the request was received.
    Since:
      Servlet 2.4

  - ### getLocalAddr

    public String getLocalAddr()
    The default behavior of this method is to return getLocalAddr() on the wrapped request object.
    Specified by:
      `getLocalAddr` in interface `ServletRequest`
    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` in interface `ServletRequest`
    Returns:
      an integer specifying the port number
    Since:
      Servlet 2.4

  - ### getServletContext

    public ServletContext getServletContext()
    The default behavior of this method is to return getServletContext() on the wrapped request object.
    Specified by:
      `getServletContext` in interface `ServletRequest`
    Returns:
      TODO
    Since:
      Servlet 3.0

  - ### startAsync

    public AsyncContext startAsync() throws IllegalStateException
    The default behavior of this method is to return startAsync() on the wrapped request object.
    Specified by:
      `startAsync` in interface `ServletRequest`
    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:
      `startAsync` in 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:
      `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:
      `isAsyncStarted` in interface `ServletRequest`
    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:
      `isAsyncSupported` in interface `ServletRequest`
    Returns:
      TODO
    Since:
      Servlet 3.0

  - ### getAsyncContext

    public AsyncContext getAsyncContext()
    The default behavior of this method is to return getAsyncContext() on the wrapped request object.
    Specified by:
      `getAsyncContext` in interface `ServletRequest`
    Returns:
      The current AsyncContext
    Since:
      Servlet 3.0

  - ### isWrapperFor

    public boolean isWrapperFor(ServletRequest wrapped)
    TODO SERVLET3 - Add comments
    Parameters:
      `wrapped` - The request to compare to the wrapped request
    Returns:
      `true` if the request wrapped by this wrapper (or series of wrappers) is the same as the supplied request, otherwise `false`
    Since:
      Servlet 3.0

  - ### isWrapperFor

    public boolean isWrapperFor(Class<?> wrappedType)
    TODO SERVLET3 - Add comments
    Parameters:
      `wrappedType` - The class to compare to the class of the wrapped request
    Returns:
      `true` if the request wrapped by this wrapper (or series of wrappers) is the same type as the supplied type, otherwise `false`
    Since:
      Servlet 3.0

  - ### getDispatcherType

    public DispatcherType getDispatcherType()
    The default behavior of this method is to call getDispatcherType() on the wrapped request object.
    Specified by:
      `getDispatcherType` in interface `ServletRequest`
    Returns:
      TODO
    Since:
      Servlet 3.0