Class MultipartRequestWrapper
- java.lang.Object
-
- javax.servlet.ServletRequestWrapper
-
- javax.servlet.http.HttpServletRequestWrapper
-
- edu.cornell.mannlib.vitro.webapp.controller.MultipartRequestWrapper
-
- All Implemented Interfaces:
javax.servlet.http.HttpServletRequest,javax.servlet.ServletRequest
public class MultipartRequestWrapper extends javax.servlet.http.HttpServletRequestWrapperWraps a multipart HTTP request, and pre-parses it for file uploads, without losing the request parameters. Parsing through the request with an Apache ServletFileUpload builds a list of FileItems that includes the parameters and the file parts. After that, however, the parameters are no longer accessible from the request. This wrapper will see that they don't get lost. The List of FileItems includes both "formField" items and "file" items. As with the usual parameters on a request, we can have more than one value with the same name. So this creates a map of <String, List<String>> to hold the parameters, and a map of <String, List<FileItem>> to hold the files. The parameters will be available to the wrapper through the normal methods. The files will be available as an attribute that holds the map. Also, a separate attribute will hold a Boolean to indicate that this was indeed a multipart request. Conveninence methods in VitroRequest will make these easy to handle, without actually touching the attributes.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceMultipartRequestWrapper.ParsingStrategy
-
Field Summary
Fields Modifier and Type Field Description static StringATTRIBUTE_FILE_ITEM_MAPstatic StringATTRIBUTE_FILE_SIZE_EXCEPTIONstatic StringATTRIBUTE_IS_MULTIPART
-
Constructor Summary
Constructors Constructor Description MultipartRequestWrapper(javax.servlet.http.HttpServletRequest req, edu.cornell.mannlib.vitro.webapp.controller.MultipartRequestWrapper.ListsMap<String> parameters, edu.cornell.mannlib.vitro.webapp.controller.MultipartRequestWrapper.ListsMap<org.apache.commons.fileupload.FileItem> files)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description StringgetParameter(String name)Look in the map of parsed parameters.Map<String,String[]>getParameterMap()Make a copy of the map of parsed parameters;Enumeration<String>getParameterNames()Look in the map of parsed parameters.String[]getParameterValues(String name)Look in the map of parsed parameters.static javax.servlet.http.HttpServletRequestparse(javax.servlet.http.HttpServletRequest req, MultipartRequestWrapper.ParsingStrategy strategy)If this is a multipart request, wrap it.-
Methods inherited from class javax.servlet.http.HttpServletRequestWrapper
getAuthType, getContextPath, getCookies, getDateHeader, getHeader, getHeaderNames, getHeaders, getIntHeader, getMethod, getPathInfo, getPathTranslated, getQueryString, getRemoteUser, getRequestedSessionId, getRequestURI, getRequestURL, getServletPath, getSession, getSession, getUserPrincipal, isRequestedSessionIdFromCookie, isRequestedSessionIdFromUrl, isRequestedSessionIdFromURL, isRequestedSessionIdValid, isUserInRole
-
Methods inherited from class javax.servlet.ServletRequestWrapper
getAttribute, getAttributeNames, getCharacterEncoding, getContentLength, getContentType, getInputStream, getLocalAddr, getLocale, getLocales, getLocalName, getLocalPort, getProtocol, getReader, getRealPath, getRemoteAddr, getRemoteHost, getRemotePort, getRequest, getRequestDispatcher, getScheme, getServerName, getServerPort, isSecure, removeAttribute, setAttribute, setCharacterEncoding, setRequest
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface javax.servlet.ServletRequest
getAttribute, getAttributeNames, getCharacterEncoding, getContentLength, getContentType, getInputStream, getLocalAddr, getLocale, getLocales, getLocalName, getLocalPort, getProtocol, getReader, getRealPath, getRemoteAddr, getRemoteHost, getRemotePort, getRequestDispatcher, getScheme, getServerName, getServerPort, isSecure, removeAttribute, setAttribute, setCharacterEncoding
-
-
-
-
Constructor Detail
-
MultipartRequestWrapper
public MultipartRequestWrapper(javax.servlet.http.HttpServletRequest req, edu.cornell.mannlib.vitro.webapp.controller.MultipartRequestWrapper.ListsMap<String> parameters, edu.cornell.mannlib.vitro.webapp.controller.MultipartRequestWrapper.ListsMap<org.apache.commons.fileupload.FileItem> files)
-
-
Method Detail
-
parse
public static javax.servlet.http.HttpServletRequest parse(javax.servlet.http.HttpServletRequest req, MultipartRequestWrapper.ParsingStrategy strategy) throws IOExceptionIf this is a multipart request, wrap it. Otherwise, just return the request as it is.- Throws:
IOException
-
getParameter
public String getParameter(String name)
Look in the map of parsed parameters.- Specified by:
getParameterin interfacejavax.servlet.ServletRequest- Overrides:
getParameterin classjavax.servlet.ServletRequestWrapper
-
getParameterNames
public Enumeration<String> getParameterNames()
Look in the map of parsed parameters. Make a protective copy.- Specified by:
getParameterNamesin interfacejavax.servlet.ServletRequest- Overrides:
getParameterNamesin classjavax.servlet.ServletRequestWrapper
-
getParameterValues
public String[] getParameterValues(String name)
Look in the map of parsed parameters.- Specified by:
getParameterValuesin interfacejavax.servlet.ServletRequest- Overrides:
getParameterValuesin classjavax.servlet.ServletRequestWrapper
-
-