jakarta.servlet.http.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 org..
ContentCachingResponseWrapper
| Modifier and Type | Class and Description |
|---|---|
| private class |
| Modifier and Type | Field and Description |
|---|---|
| private final FastByteArrayOutputStream | |
| private final Integer | |
| private ServletInputStream | |
| private BufferedReader |
| Access | Constructor and Description |
|---|---|
| public | ContentCachingRequestWrapper(HttpServletRequest
the original servlet request request)Create a new ContentCachingRequestWrapper for the given servlet request. |
| public | ContentCachingRequestWrapper(HttpServletRequest
the original servlet request request, int the maximum number of bytes to cache per request contentCacheLimit)Create a new ContentCachingRequestWrapper for the given servlet request. |
| Modifier and Type | Method and Description |
|---|---|
| public String | getCharacterEncoding()
Overrides jakarta. Implements jakarta. |
| public byte[] | |
| public String | |
| public ServletInputStream | getInputStream()
Overrides jakarta. Implements jakarta. ServletInputStream.
|
| public String | getParameter(String
a name)String specifying the name of the parameterOverrides jakarta. Implements jakarta. String, or null if the parameter does not
exist.
|
| public Map | getParameterMap()
Overrides jakarta. Implements jakarta. |
| public Enumeration | getParameterNames()
Overrides jakarta. Implements jakarta. Enumeration of String objects containing the names of the parameters
contained in this request.
|
| public String[] | getParameterValues(String
a name)String containing the name of the parameter whose value is requestedOverrides jakarta. Implements jakarta. String objects containing all of the values the given request parameter has, or
null if the parameter does not exist.
|
| public BufferedReader | getReader()
Overrides jakarta. Implements jakarta. BufferedReader.
|
| protected void | handleContentOverflow(int
the maximum number of bytes to cache per request
which has just been exceeded contentCacheLimit)Template method for handling a content overflow: specifically, a request body being read that exceeds the specified content cache limit. |
| private boolean | |
| private void |
| cachedContent | back to summary |
|---|---|
| private final FastByteArrayOutputStream cachedContent | |
| contentCacheLimit | back to summary |
|---|---|
| private final Integer contentCacheLimit
| |
| inputStream | back to summary |
|---|---|
| private ServletInputStream inputStream
| |
| reader | back to summary |
|---|---|
| private BufferedReader reader
| |
| ContentCachingRequestWrapper | back to summary |
|---|---|
| public ContentCachingRequestWrapper(HttpServletRequest request) Create a new ContentCachingRequestWrapper for the given servlet request.
| |
| ContentCachingRequestWrapper | back to summary |
|---|---|
| public ContentCachingRequestWrapper(HttpServletRequest request, int contentCacheLimit) Create a new ContentCachingRequestWrapper for the given servlet request.
| |
| getCharacterEncoding | back to summary |
|---|---|
| public String getCharacterEncoding() Overrides jakarta. Implements jakarta. Doc from jakarta. Returns the name of the character encoding used in the body of this request. This method returns
| |
| getContentAsByteArray | back to summary |
|---|---|
| public 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. | |
| getContentAsString | back to summary |
|---|---|
| public String getContentAsString() Return the cached request content as a String, using the configured
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.
| |
| getInputStream | back to summary |
|---|---|
| public ServletInputStream getInputStream() throws IOException Overrides jakarta. Implements jakarta. Doc from jakarta. Retrieves the body of the request as binary data using a
| |
| getParameter | back to summary |
|---|---|
| public String getParameter(String name) Overrides jakarta. Implements jakarta. Doc from jakarta. Returns the value of a request parameter as a
You should only use this method when you are sure the parameter has only one value. If the parameter might have
more than one value, use
If you use this method with a multivalued parameter, the value returned is equal to the first value in the array
returned by
If the parameter data was sent in the request body, such as occurs with an HTTP POST request, then reading the
body directly via | |
| getParameterMap | back to summary |
|---|---|
| public Map Overrides jakarta. Implements jakarta. Doc from jakarta. Returns a java.util.Map of the parameters of this request. Request parameters are extra information sent with the request. For HTTP servlets, parameters are contained in the query string or posted form data. | |
| getParameterNames | back to summary |
|---|---|
| public Enumeration Overrides jakarta. Implements jakarta. Doc from jakarta. Returns an
| |
| getParameterValues | back to summary |
|---|---|
| public String[] getParameterValues(String name) Overrides jakarta. Implements jakarta. Doc from jakarta. Returns an array of If the parameter has a single value, the array has a length of 1. | |
| getReader | back to summary |
|---|---|
| public BufferedReader getReader() throws IOException Overrides jakarta. Implements jakarta. Doc from jakarta. Retrieves the body of the request as character data using a
| |
| handleContentOverflow | back to summary |
|---|---|
| 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. The default implementation is empty. Subclasses may override this to throw a payload-too-large exception or the like.
| |
| isFormPost | back to summary |
|---|---|
| private boolean isFormPost() | |
| writeRequestParametersToCachedContent | back to summary |
|---|---|
| private void writeRequestParametersToCachedContent() | |
| Modifier and Type | Field and Description |
|---|---|
| private final ServletInputStream | |
| private boolean |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | isFinished()
Implements abstract jakarta. |
| public boolean | isReady()
Implements abstract jakarta. |
| public int | read()
Implements abstract java. |
| public int | read(byte[]
the buffer into which the data is read. b)Overrides java. b.
|
| public int | read(final byte[]
the buffer into which the data is read. b, final int the start offset in array off, final int b
at which the data is written.the maximum number of bytes to read. len)Overrides java. len bytes of data from the input stream into
an array of bytes.
|
| public int | readLine(final byte[]
an array of bytes into which data is read b, final int an integer specifying the character at which this method begins reading off, final int an integer specifying the maximum number of bytes to read len)Overrides jakarta. |
| public void | setReadListener(ReadListener
The non-blocking IO read listener readListener)Implements abstract jakarta. ReadListener for this ServletInputStream and thereby switches to non-blocking IO.
|
| private void |
| is | back to summary |
|---|---|
| private final ServletInputStream is | |
| overflow | back to summary |
|---|---|
| private boolean overflow | |
| ContentCachingInputStream | back to summary |
|---|---|
| public ContentCachingInputStream(ServletInputStream is) | |
| isFinished | back to summary |
|---|---|
| public boolean isFinished() Implements abstract jakarta. Doc from jakarta. Has the end of this InputStream been reached?
| |
| isReady | back to summary |
|---|---|
| public boolean isReady() Implements abstract jakarta. Doc from jakarta. Can data be read from this InputStream without blocking? Returns If this method is called and returns false, the
container will invoke
| |
| read | back to summary |
|---|---|
| public int read() throws IOException Implements abstract java. Doc from java. Reads the next byte of data from the input stream. The value byte is
returned as an
| |
| read | back to summary |
|---|---|
| public int read(byte[] b) throws IOException Overrides java. Doc from java. Reads some number of bytes from the input stream and stores them into
the buffer array If the length of The first byte read is stored into element
| |
| read | back to summary |
|---|---|
| public int read(final byte[] b, final int off, final int len) throws IOException Overrides java. Doc from java. Reads up to This method blocks until input data is available, end of file is detected, or an exception is thrown. If The first byte read is stored into element In every case, elements
| |
| readLine | back to summary |
|---|---|
| public int readLine(final byte[] b, final int off, final int len) throws IOException Overrides jakarta. Doc from jakarta. Reads the input stream, one line at a time. Starting at an offset, reads bytes into an array, until it reads a certain number of bytes or reaches a newline character, which it reads into the array as well. This method returns -1 if it reaches the end of the input stream before reading the maximum number of bytes.
| |
| setReadListener | back to summary |
|---|---|
| public void setReadListener(ReadListener readListener) Implements abstract jakarta. Doc from jakarta. Sets the
| |
| writeToCache | back to summary |
|---|---|
| private void writeToCache(final byte[] b, final int off, int count) throws IOException | |