public class ContentCachingRequestWrapper extends HttpServletRequestWrapper
HttpServletRequest
wrapper that caches all content read from
the input stream and reader,
and allows this content to be retrieved via a byte array
.
This class acts as an interceptor that only caches content as it is being
read but otherwise does not cause content to be read. That means if the request
content is not consumed, then the content is not cached, and cannot be
retrieved via getContentAsByteArray()
.
Used e.g. by AbstractRequestLoggingFilter
.
Note: As of Spring Framework 5.0, this wrapper is built on the Servlet 3.1 API.
ContentCachingResponseWrapper
BASIC_AUTH, CLIENT_CERT_AUTH, DIGEST_AUTH, FORM_AUTH
Constructor and Description |
---|
ContentCachingRequestWrapper(HttpServletRequest request)
Create a new ContentCachingRequestWrapper for the given servlet request.
|
ContentCachingRequestWrapper(HttpServletRequest request,
int contentCacheLimit)
Create a new ContentCachingRequestWrapper for the given servlet request.
|
Modifier and Type | Method and Description |
---|---|
String |
getCharacterEncoding() |
byte[] |
getContentAsByteArray()
Return the cached request content as a byte array.
|
ServletInputStream |
getInputStream() |
String |
getParameter(String name) |
Map<String,String[]> |
getParameterMap() |
Enumeration<String> |
getParameterNames() |
String[] |
getParameterValues(String name) |
BufferedReader |
getReader() |
protected void |
handleContentOverflow(int contentCacheLimit)
Template method for handling a content overflow: specifically, a request
body being read that exceeds the specified content cache limit.
|
authenticate, changeSessionId, getAuthType, getContextPath, getCookies, getDateHeader, getHeader, getHeaderNames, getHeaders, getHttpServletMapping, getIntHeader, getMethod, getPart, getParts, getPathInfo, getPathTranslated, getQueryString, getRemoteUser, getRequestedSessionId, getRequestURI, getRequestURL, getServletPath, getSession, getSession, getTrailerFields, getUserPrincipal, isRequestedSessionIdFromCookie, isRequestedSessionIdFromUrl, isRequestedSessionIdFromURL, isRequestedSessionIdValid, isTrailerFieldsReady, isUserInRole, login, logout, newPushBuilder, upgrade
getAsyncContext, getAttribute, getAttributeNames, 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
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getAsyncContext, getAttribute, getAttributeNames, 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
public ContentCachingRequestWrapper(HttpServletRequest request)
request
- the original servlet requestpublic ContentCachingRequestWrapper(HttpServletRequest request, int contentCacheLimit)
request
- the original servlet requestcontentCacheLimit
- the maximum number of bytes to cache per requesthandleContentOverflow(int)
public ServletInputStream getInputStream() throws IOException
getInputStream
in interface ServletRequest
getInputStream
in class ServletRequestWrapper
IOException
public String getCharacterEncoding()
getCharacterEncoding
in interface ServletRequest
getCharacterEncoding
in class ServletRequestWrapper
public BufferedReader getReader() throws IOException
getReader
in interface ServletRequest
getReader
in class ServletRequestWrapper
IOException
public String getParameter(String name)
getParameter
in interface ServletRequest
getParameter
in class ServletRequestWrapper
public Map<String,String[]> getParameterMap()
getParameterMap
in interface ServletRequest
getParameterMap
in class ServletRequestWrapper
public Enumeration<String> getParameterNames()
getParameterNames
in interface ServletRequest
getParameterNames
in class ServletRequestWrapper
public String[] getParameterValues(String name)
getParameterValues
in interface ServletRequest
getParameterValues
in class ServletRequestWrapper
public byte[] getContentAsByteArray()
The returned array will never be larger than the content cache limit.
Note: The byte array returned from this method reflects the amount of content that has has been read at the time when it is called. If the application does not read the content, this method returns an empty array.
protected void handleContentOverflow(int contentCacheLimit)
The default implementation is empty. Subclasses may override this to throw a payload-too-large exception or the like.
contentCacheLimit
- the maximum number of bytes to cache per request
which has just been exceededContentCachingRequestWrapper(HttpServletRequest, int)