java.lang.Object
net.i2p.servlet.RequestWrapper

public class RequestWrapperextends Object
Wraps an HttpServletRequest and adds multipart-aware access to the parameters and files of a multipart/form-data request, using the Servlet 3.0 Part API. Only the multipart variants of the accessors are wrapped; everything else is passed straight through. The Servlet API container already parses multipart requests, so this class deliberately does not parse them again. A part larger than the 64KB MAX_STRING_SIZE limit is not read into a String, and an IllegalStateException from the container (which signals an oversized request) is logged and rethrown.
  • Constructor Details

    • RequestWrapper

      public RequestWrapper(HttpServletRequest httpRequest)
      Wrap a servlet request, noting whether it carries multipart parts.
      Parameters:
      httpRequest - the request to wrap
  • Method Details

    • getSession

      public HttpSession getSession(boolean b)
      The session bound to this request.
      Parameters:
      b - true to create a session when the request has none
      Returns:
      the bound session, or a new one when b is true
    • getParameter

      public String getParameter(String name)
      Look up a request parameter, falling back to the multipart part of the same name.
      Parameters:
      name - Specific parameter key
      Returns:
      parameter value, or null when neither a parameter nor a part carries that name
    • getSession

      public HttpSession getSession()
      The session bound to this request, created if it has none.
      Returns:
      the bound session, created if the request has none
    • getParameterNames

      public Enumeration<String> getParameterNames()
      The names this request carries, multipart part names included.
      Returns:
      List of request parameter names
      Throws:
      IllegalStateException - if the request is too large
    • getContentLength

      public int getContentLength()
      The declared length of the request body.
      Returns:
      The total length of the content.
    • getContentType

      public String getContentType()
      The request's content type header.
      Returns:
      The content type of the request.
    • getContentType

      public String getContentType(String partName)
      The content type declared by a single multipart part.
      Parameters:
      partName - the multipart part to read the content type from
      Returns:
      the content type
      Throws:
      IllegalStateException - if the request is too large
    • getAttribute

      public Object getAttribute(String string)
      Look up a request attribute; multipart parts are not consulted.
      Parameters:
      string - the name of the request attribute to look up
      Returns:
      the attribute, or null when the request carries none of that name
    • getParameter

      public String getParameter(String name, String defaultValue)
      Look up a request parameter or multipart part, falling back to a default.
      Parameters:
      name - the request parameter or multipart part name to look up
      defaultValue - returned when the request carries no value for name; for a multipart part also returned when the part is absent
      Returns:
      the value, or defaultValue when the request carries none
      Throws:
      IllegalStateException - if the request is too large
    • getFilename

      public String getFilename(String partName)
      The filename the client submitted with a multipart part.
      Parameters:
      partName - the multipart part to read the submitted filename from
      Returns:
      the submitted filename, or null when the part is absent
      Throws:
      IllegalStateException - if the request is too large
    • getInputStream

      public InputStream getInputStream(String partName)
      Open a multipart part's body for reading.
      Parameters:
      partName - the multipart part to open the body of
      Returns:
      the input stream
      Throws:
      IllegalStateException - if the request is too large