Class ContentCachingRequestWrapper
- All Implemented Interfaces:
- HttpServletRequest,- ServletRequest
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.
- Since:
- 4.1.3
- Author:
- Juergen Hoeller, Brian Clozel
- See Also:
- 
Field SummaryFields inherited from interface jakarta.servlet.http.HttpServletRequestBASIC_AUTH, CLIENT_CERT_AUTH, DIGEST_AUTH, FORM_AUTH
- 
Constructor SummaryConstructorsConstructorDescriptionCreate a new ContentCachingRequestWrapper for the given servlet request.ContentCachingRequestWrapper(HttpServletRequest request, int contentCacheLimit) Create a new ContentCachingRequestWrapper for the given servlet request.
- 
Method SummaryModifier and TypeMethodDescriptionbyte[]Return the cached request content as a byte array.Return the cached request content as a String, using the configuredCharset.getParameter(String name) String[]getParameterValues(String name) protected voidhandleContentOverflow(int contentCacheLimit) Template method for handling a content overflow: specifically, a request body being read that exceeds the specified content cache limit.Methods inherited from class jakarta.servlet.http.HttpServletRequestWrapperauthenticate, 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, isRequestedSessionIdValid, isTrailerFieldsReady, isUserInRole, login, logout, newPushBuilder, upgradeMethods inherited from class jakarta.servlet.ServletRequestWrappergetAsyncContext, getAttribute, getAttributeNames, getContentLength, getContentLengthLong, getContentType, getDispatcherType, getLocalAddr, getLocale, getLocales, getLocalName, getLocalPort, getProtocol, getProtocolRequestId, getRemoteAddr, getRemoteHost, getRemotePort, getRequest, getRequestDispatcher, getRequestId, getScheme, getServerName, getServerPort, getServletConnection, getServletContext, isAsyncStarted, isAsyncSupported, isSecure, isWrapperFor, isWrapperFor, removeAttribute, setAttribute, setCharacterEncoding, setRequest, startAsync, startAsyncMethods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface jakarta.servlet.ServletRequestgetAsyncContext, getAttribute, getAttributeNames, getContentLength, getContentLengthLong, getContentType, getDispatcherType, getLocalAddr, getLocale, getLocales, getLocalName, getLocalPort, getProtocol, getProtocolRequestId, getRemoteAddr, getRemoteHost, getRemotePort, getRequestDispatcher, getRequestId, getScheme, getServerName, getServerPort, getServletConnection, getServletContext, isAsyncStarted, isAsyncSupported, isSecure, removeAttribute, setAttribute, setCharacterEncoding, startAsync, startAsync
- 
Constructor Details- 
ContentCachingRequestWrapperCreate a new ContentCachingRequestWrapper for the given servlet request.- Parameters:
- request- the original servlet request
 
- 
ContentCachingRequestWrapperCreate a new ContentCachingRequestWrapper for the given servlet request.- Parameters:
- request- the original servlet request
- contentCacheLimit- the maximum number of bytes to cache per request
- Since:
- 4.3.6
- See Also:
 
 
- 
- 
Method Details- 
getInputStream- Specified by:
- getInputStreamin interface- ServletRequest
- Overrides:
- getInputStreamin class- ServletRequestWrapper
- Throws:
- IOException
 
- 
getCharacterEncoding- Specified by:
- getCharacterEncodingin interface- ServletRequest
- Overrides:
- getCharacterEncodingin class- ServletRequestWrapper
 
- 
getReader- Specified by:
- getReaderin interface- ServletRequest
- Overrides:
- getReaderin class- ServletRequestWrapper
- Throws:
- IOException
 
- 
getParameter- Specified by:
- getParameterin interface- ServletRequest
- Overrides:
- getParameterin class- ServletRequestWrapper
 
- 
getParameterMap- Specified by:
- getParameterMapin interface- ServletRequest
- Overrides:
- getParameterMapin class- ServletRequestWrapper
 
- 
getParameterNames- Specified by:
- getParameterNamesin interface- ServletRequest
- Overrides:
- getParameterNamesin class- ServletRequestWrapper
 
- 
getParameterValues- Specified by:
- getParameterValuesin interface- ServletRequest
- Overrides:
- getParameterValuesin class- ServletRequestWrapper
 
- 
getContentAsByteArraypublic byte[] getContentAsByteArray()Return the cached request content as a byte array.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 been read at the time when it is called. If the application does not read the content, this method returns an empty array. 
- 
getContentAsStringReturn the cached request content as a String, using the configuredCharset.Note: The String returned from this method reflects the amount of content that has been read at the time when it is called. If the application does not read the content, this method returns an empty String. - Since:
- 6.1
- See Also:
 
- 
handleContentOverflowprotected void handleContentOverflow(int contentCacheLimit) Template method for handling a content overflow: specifically, a request body being read that exceeds the specified content cache limit.The default implementation is empty. Subclasses may override this to throw a payload-too-large exception or the like. - Parameters:
- contentCacheLimit- the maximum number of bytes to cache per request which has just been exceeded
- Since:
- 4.3.6
- See Also:
 
 
-