Class MultipartPreservingRequest

java.lang.Object
javax.servlet.ServletRequestWrapper
javax.servlet.http.HttpServletRequestWrapper
de.xima.fc.http.MultipartPreservingRequest
All Implemented Interfaces:
javax.servlet.http.HttpServletRequest, javax.servlet.ServletRequest

public class MultipartPreservingRequest extends javax.servlet.http.HttpServletRequestWrapper
A wrapper for multipart HttpServletRequests that preserves their mulitpart parts, meaning the parts can be accessed multiple times during the entire request scope.

This wrapper also performs malware scanning immediately when the parts are parsed.

Since:
8.0.0
Author:
XIMA MEDIA GmbH, Dresden
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
     
  • Field Summary

    Fields inherited from interface javax.servlet.http.HttpServletRequest

    BASIC_AUTH, CLIENT_CERT_AUTH, DIGEST_AUTH, FORM_AUTH
  • Constructor Summary

    Constructors
    Constructor
    Description
    MultipartPreservingRequest(javax.servlet.http.HttpServletRequest request)
    Constructor for the request wrapper.
  • Method Summary

    Modifier and Type
    Method
    Description
    Gets the current instance of MultipartPreservingRequest of this request context if it exists.
    getCurrent(javax.servlet.http.HttpServletRequest request)
    Gets the current instance of MultipartPreservingRequest of this request if it exists.
    List<org.apache.commons.fileupload.FileItem>
    Returns the file items of this multipart content request.
    javax.servlet.ServletInputStream
     
     
     
     
     
    javax.servlet.http.Part
     
    Collection<javax.servlet.http.Part>
     
     
    Opens a new input stream to read the request body.
    void
     
    static javax.servlet.http.HttpServletRequest
    wrap(javax.servlet.http.HttpServletRequest request)
    Wraps the request if it is a multipart content POST request and not already a MultipartPreservingRequest.

    Methods inherited from class javax.servlet.http.HttpServletRequestWrapper

    authenticate, changeSessionId, getAuthType, getContextPath, getCookies, getDateHeader, getHeader, getHeaderNames, getHeaders, getHttpServletMapping, getIntHeader, getMethod, getPathInfo, getPathTranslated, getQueryString, getRemoteUser, getRequestedSessionId, getRequestURI, getRequestURL, getServletPath, getSession, getSession, getTrailerFields, getUserPrincipal, isRequestedSessionIdFromCookie, isRequestedSessionIdFromUrl, isRequestedSessionIdFromURL, isRequestedSessionIdValid, isTrailerFieldsReady, isUserInRole, login, logout, newPushBuilder, upgrade

    Methods inherited from class javax.servlet.ServletRequestWrapper

    getAsyncContext, getAttribute, getAttributeNames, getCharacterEncoding, getContentLength, getContentLengthLong, getContentType, getDispatcherType, getLocalAddr, getLocale, getLocales, getLocalName, getLocalPort, getProtocol, getRealPath, getRemoteAddr, getRemoteHost, getRemotePort, getRequest, getRequestDispatcher, getScheme, getServerName, getServerPort, getServletContext, isAsyncStarted, isAsyncSupported, isSecure, isWrapperFor, isWrapperFor, removeAttribute, setAttribute, setCharacterEncoding, setRequest, startAsync, startAsync

    Methods inherited from class Object

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

    Methods inherited from interface javax.servlet.ServletRequest

    getAsyncContext, getAttribute, getAttributeNames, getCharacterEncoding, getContentLength, getContentLengthLong, getContentType, getDispatcherType, getLocalAddr, getLocale, getLocales, getLocalName, getLocalPort, getProtocol, getRealPath, getRemoteAddr, getRemoteHost, getRemotePort, getRequestDispatcher, getScheme, getServerName, getServerPort, getServletContext, isAsyncStarted, isAsyncSupported, isSecure, removeAttribute, setAttribute, setCharacterEncoding, startAsync, startAsync
  • Constructor Details

    • MultipartPreservingRequest

      public MultipartPreservingRequest(javax.servlet.http.HttpServletRequest request) throws IOException
      Constructor for the request wrapper.
      Parameters:
      request - to be wrapped.
      Throws:
      IllegalArgumentException - if the request is not a multipart POST request.
      IOException
  • Method Details

    • getFileItems

      public List<org.apache.commons.fileupload.FileItem> getFileItems()
      Returns the file items of this multipart content request.
      Returns:
      parsed file items of this request.
    • getInputStream

      public javax.servlet.ServletInputStream getInputStream() throws IOException
      Specified by:
      getInputStream in interface javax.servlet.ServletRequest
      Overrides:
      getInputStream in class javax.servlet.ServletRequestWrapper
      Throws:
      IOException
    • getParameter

      public String getParameter(String name)
      Specified by:
      getParameter in interface javax.servlet.ServletRequest
      Overrides:
      getParameter in class javax.servlet.ServletRequestWrapper
    • getParameterMap

      public Map<String,String[]> getParameterMap()
      Specified by:
      getParameterMap in interface javax.servlet.ServletRequest
      Overrides:
      getParameterMap in class javax.servlet.ServletRequestWrapper
    • getParameterNames

      public Enumeration<String> getParameterNames()
      Specified by:
      getParameterNames in interface javax.servlet.ServletRequest
      Overrides:
      getParameterNames in class javax.servlet.ServletRequestWrapper
    • getParameterValues

      public String[] getParameterValues(String name)
      Specified by:
      getParameterValues in interface javax.servlet.ServletRequest
      Overrides:
      getParameterValues in class javax.servlet.ServletRequestWrapper
    • getReader

      public BufferedReader getReader() throws IOException
      Specified by:
      getReader in interface javax.servlet.ServletRequest
      Overrides:
      getReader in class javax.servlet.ServletRequestWrapper
      Throws:
      IOException
    • getParts

      public Collection<javax.servlet.http.Part> getParts() throws IOException, javax.servlet.ServletException
      Specified by:
      getParts in interface javax.servlet.http.HttpServletRequest
      Overrides:
      getParts in class javax.servlet.http.HttpServletRequestWrapper
      Throws:
      IOException
      javax.servlet.ServletException
    • getPart

      public javax.servlet.http.Part getPart(String name) throws IOException, javax.servlet.ServletException
      Specified by:
      getPart in interface javax.servlet.http.HttpServletRequest
      Overrides:
      getPart in class javax.servlet.http.HttpServletRequestWrapper
      Throws:
      IOException
      javax.servlet.ServletException
    • newInputStream

      public InputStream newInputStream() throws IOException
      Opens a new input stream to read the request body. In contrast to getInputStream(), this method always returns a new stream that starts at the beginning of the request body. The caller must ensure the input stream is closed after use. This method does not affect the state of the input stream returned by getInputStream().
      Returns:
      A new input stream to read the request body.
      Throws:
      IOException
    • reset

      public void reset()
    • getCurrent

      public static MultipartPreservingRequest getCurrent(javax.servlet.http.HttpServletRequest request)
      Gets the current instance of MultipartPreservingRequest of this request if it exists.
      Parameters:
      request - to get the current instance of MultipartPreservingRequest for.
      Returns:
      the current instance of MultipartPreservingRequest or null if it does not exist.
    • getCurrent

      public static MultipartPreservingRequest getCurrent(IRequestContext requestCtx)
      Gets the current instance of MultipartPreservingRequest of this request context if it exists.
      Parameters:
      requestCtx - to get the current instance of MultipartPreservingRequest for.
      Returns:
      the current instance of MultipartPreservingRequest or null if it does not exist.
    • wrap

      public static javax.servlet.http.HttpServletRequest wrap(javax.servlet.http.HttpServletRequest request) throws IOException
      Wraps the request if it is a multipart content POST request and not already a MultipartPreservingRequest.
      Parameters:
      request - to wrap.
      Returns:
      the wrapped request or the initial request if it is no multipart content POST request.
      Throws:
      IOException