Module com.github.robtimus.servlet
Package com.github.robtimus.servlet.http
Class InputTransformingHttpServletRequestWrapper
- java.lang.Object
-
- jakarta.servlet.ServletRequestWrapper
-
- jakarta.servlet.http.HttpServletRequestWrapper
-
- com.github.robtimus.servlet.http.InputTransformingHttpServletRequestWrapper
-
- All Implemented Interfaces:
HttpServletRequest
,ServletRequest
- Direct Known Subclasses:
BodyCapturingFilter.BodyCapturingRequest
public class InputTransformingHttpServletRequestWrapper extends HttpServletRequestWrapper
A sub class ofHttpServletRequestWrapper
that applies a transformation on itsinput stream
and/orreader
.- Author:
- Rob Spoor
-
-
Field Summary
-
Fields inherited from interface jakarta.servlet.http.HttpServletRequest
BASIC_AUTH, CLIENT_CERT_AUTH, DIGEST_AUTH, FORM_AUTH
-
-
Constructor Summary
Constructors Constructor Description InputTransformingHttpServletRequestWrapper(HttpServletRequest request)
Creates a newHttpServletRequest
wrapper.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ServletInputStream
getInputStream()
BufferedReader
getReader()
protected InputStream
transform(ServletInputStream inputStream)
Transforms the originalServletInputStream
.protected Reader
transform(BufferedReader reader)
Transforms the originalBufferedReader
.-
Methods inherited from class jakarta.servlet.http.HttpServletRequestWrapper
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
-
Methods inherited from class jakarta.servlet.ServletRequestWrapper
getAsyncContext, getAttribute, getAttributeNames, getCharacterEncoding, getContentLength, getContentLengthLong, getContentType, getDispatcherType, getLocalAddr, getLocale, getLocales, getLocalName, getLocalPort, getParameter, getParameterMap, getParameterNames, getParameterValues, 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 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface jakarta.servlet.ServletRequest
getAsyncContext, getAttribute, getAttributeNames, getCharacterEncoding, getContentLength, getContentLengthLong, getContentType, getDispatcherType, getLocalAddr, getLocale, getLocales, getLocalName, getLocalPort, getParameter, getParameterMap, getParameterNames, getParameterValues, getProtocol, getRealPath, getRemoteAddr, getRemoteHost, getRemotePort, getRequestDispatcher, getScheme, getServerName, getServerPort, getServletContext, isAsyncStarted, isAsyncSupported, isSecure, removeAttribute, setAttribute, setCharacterEncoding, startAsync, startAsync
-
-
-
-
Constructor Detail
-
InputTransformingHttpServletRequestWrapper
public InputTransformingHttpServletRequestWrapper(HttpServletRequest request)
Creates a newHttpServletRequest
wrapper.- Parameters:
request
- The request to wrap.- Throws:
IllegalArgumentException
- If the request isnull
.
-
-
Method Detail
-
transform
protected InputStream transform(ServletInputStream inputStream) throws IOException
Transforms the originalServletInputStream
.This default implementation returns the unmodified argument.
- Parameters:
inputStream
- The originalServletInputStream
to transform.- Returns:
- An
InputStream
that is the result of transforming the givenServletInputStream
. It does not necessary have to be aServletInputStream
. - Throws:
IOException
- If an I/O error occurred during the transformation.
-
getInputStream
public ServletInputStream getInputStream() throws IOException
- Specified by:
getInputStream
in interfaceServletRequest
- Overrides:
getInputStream
in classServletRequestWrapper
- Throws:
IOException
-
transform
protected Reader transform(BufferedReader reader) throws IOException
Transforms the originalBufferedReader
.This default implementation returns the unmodified argument.
- Parameters:
reader
- The originalBufferedReader
to transform.- Returns:
- A
Reader
that is the result of transforming the givenBufferedReader
. It does not necessary have to be aBufferedReader
. - Throws:
IOException
- If an I/O error occurred during the transformation.
-
getReader
public BufferedReader getReader() throws IOException
- Specified by:
getReader
in interfaceServletRequest
- Overrides:
getReader
in classServletRequestWrapper
- Throws:
IOException
-
-