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.
Used e.g. by AbstractRequestLoggingFilter.
Note: As of Spring Framework 5.0, this wrapper is built on the Servlet 3.1 API.
ContentCachingResponseWrapperBASIC_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()
The default behavior of this method is to return getCharacterEncoding()
on the wrapped request object.
|
byte[] |
getContentAsByteArray()
Return the cached request content as a byte array.
|
ServletInputStream |
getInputStream()
The default behavior of this method is to return getInputStream()
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.
|
BufferedReader |
getReader()
The default behavior of this method is to return getReader()
on the wrapped request object.
|
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, upgradegetAsyncContext, 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, startAsyncclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetAsyncContext, 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, startAsyncpublic 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
javax.servlet.ServletRequestWrappergetInputStream in interface ServletRequestgetInputStream in class ServletRequestWrapperServletInputStream object containing
the body of the requestIOException - if an input or output exception occurredpublic String getCharacterEncoding()
javax.servlet.ServletRequestWrappergetCharacterEncoding in interface ServletRequestgetCharacterEncoding in class ServletRequestWrapperString containing the name of the character
encoding, or null if the request does not specify a
character encodingpublic BufferedReader getReader() throws IOException
javax.servlet.ServletRequestWrappergetReader in interface ServletRequestgetReader in class ServletRequestWrapperBufferedReader containing the body of the requestUnsupportedEncodingException - if the character set encoding
used is not supported and the text cannot be decodedIOException - if an input or output exception occurredServletRequest.getInputStream()public String getParameter(String name)
javax.servlet.ServletRequestWrappergetParameter in interface ServletRequestgetParameter in class ServletRequestWrappername - a String specifying the name of the parameterString representing the single value of
the parameterServletRequest.getParameterValues(java.lang.String)public Map<String,String[]> getParameterMap()
javax.servlet.ServletRequestWrappergetParameterMap in interface ServletRequestgetParameterMap in class ServletRequestWrapperpublic Enumeration<String> getParameterNames()
javax.servlet.ServletRequestWrappergetParameterNames in interface ServletRequestgetParameterNames in class ServletRequestWrapperEnumeration of String
objects, each String containing the name of
a request parameter; or an empty Enumeration
if the request has no parameterspublic String[] getParameterValues(String name)
javax.servlet.ServletRequestWrappergetParameterValues in interface ServletRequestgetParameterValues in class ServletRequestWrappername - a String containing the name of
the parameter whose value is requestedString objects
containing the parameter's valuesServletRequest.getParameter(java.lang.String)public byte[] getContentAsByteArray()
The returned array will never be larger than the content cache limit.
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)