Class HttpPostStandardRequestDecoder
java.lang.Object
io.netty.handler.codec.http.multipart.HttpPostStandardRequestDecoder
- All Implemented Interfaces:
InterfaceHttpPostRequestDecoder
public class HttpPostStandardRequestDecoder
extends Object
implements InterfaceHttpPostRequestDecoder
This decoder will decode Body and can handle POST BODY.
You MUST call
destroy()
after completion to release all resources.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final class
private static final class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final List
<InterfaceHttpData> HttpDatas from Bodyprivate int
Body HttpDatas current positionprivate final Map
<String, List<InterfaceHttpData>> HttpDatas as Map from Bodyprivate final Charset
Default charset to useprivate Attribute
The current Attribute that is currently in decode processCurrent getStatusprivate boolean
private int
private final HttpDataFactory
Factory used to create InterfaceHttpDataprivate boolean
Does the last chunk already receivedprivate final int
The maximum number of accumulated bytes when decoding a fieldprivate final int
The maximum number of fields allows by the formprivate final HttpRequest
Request to decodeprivate ByteBuf
The current channelBuffer -
Constructor Summary
ConstructorsConstructorDescriptionHttpPostStandardRequestDecoder
(HttpDataFactory factory, HttpRequest request) HttpPostStandardRequestDecoder
(HttpDataFactory factory, HttpRequest request, Charset charset) HttpPostStandardRequestDecoder
(HttpDataFactory factory, HttpRequest request, Charset charset, int maxFields, int maxBufferedBytes) -
Method Summary
Modifier and TypeMethodDescriptionprotected void
addHttpData
(InterfaceHttpData data) Utility function to add a new decoded dataprivate void
void
Clean allHttpData
s for the current request.Returns the current InterfaceHttpData if currently in decoding status, meaning all data are not yet within, or null if there is no InterfaceHttpData currently in decoding status (either because none yet decoded or none currently partially decoded).private static ByteBuf
decodeAttribute
(ByteBuf b, Charset charset) private static String
decodeAttribute
(String s, Charset charset) Decode componentvoid
destroy()
Destroy theHttpPostStandardRequestDecoder
and release all it resources.getBodyHttpData
(String name) This getMethod returns the first InterfaceHttpData with the given name from body.
If chunked, all chunks must have been offered using offer() getMethod.This getMethod returns a List of all HttpDatas from body.
If chunked, all chunks must have been offered using offer() getMethod.getBodyHttpDatas
(String name) This getMethod returns a List of all HttpDatas with the given name from body.
If chunked, all chunks must have been offered using offer() getMethod.int
Return the threshold in bytes after which read data in the buffer should be discarded.boolean
hasNext()
True if at current getStatus, there is an available decoded InterfaceHttpData from the Body.boolean
True if this request is a Multipart requestnext()
Returns the next available InterfaceHttpData or null if, at the time it is called, there is no more available InterfaceHttpData.offer
(HttpContent content) Initialized the internals from a new chunkprivate void
This getMethod will parse as much as possible data and fill the list and mapprivate void
This getMethod fill the map and list with as much Attribute as possible from Body in not Multipart mode.private void
This getMethod fill the map and list with as much Attribute as possible from Body in not Multipart mode.void
Remove the given FileUpload from the list of FileUploads to cleanvoid
setDiscardThreshold
(int discardThreshold) Set the amount of bytes after which read bytes in the buffer should be discarded.private void
setFinalBuffer
(ByteBuf buffer)
-
Field Details
-
factory
Factory used to create InterfaceHttpData -
request
Request to decode -
charset
Default charset to use -
maxFields
private final int maxFieldsThe maximum number of fields allows by the form -
maxBufferedBytes
private final int maxBufferedBytesThe maximum number of accumulated bytes when decoding a field -
isLastChunk
private boolean isLastChunkDoes the last chunk already received -
bodyListHttpData
HttpDatas from Body -
bodyMapHttpData
HttpDatas as Map from Body -
undecodedChunk
The current channelBuffer -
bodyListHttpDataRank
private int bodyListHttpDataRankBody HttpDatas current position -
currentStatus
Current getStatus -
currentAttribute
The current Attribute that is currently in decode process -
destroyed
private boolean destroyed -
discardThreshold
private int discardThreshold
-
-
Constructor Details
-
HttpPostStandardRequestDecoder
- Parameters:
request
- the request to decode- Throws:
NullPointerException
- for requestHttpPostRequestDecoder.ErrorDataDecoderException
- if the default charset was wrong when decoding or other errors
-
HttpPostStandardRequestDecoder
- Parameters:
factory
- the factory used to create InterfaceHttpDatarequest
- the request to decode- Throws:
NullPointerException
- for request or factoryHttpPostRequestDecoder.ErrorDataDecoderException
- if the default charset was wrong when decoding or other errors
-
HttpPostStandardRequestDecoder
public HttpPostStandardRequestDecoder(HttpDataFactory factory, HttpRequest request, Charset charset) - Parameters:
factory
- the factory used to create InterfaceHttpDatarequest
- the request to decodecharset
- the charset to use as default- Throws:
NullPointerException
- for request or charset or factoryHttpPostRequestDecoder.ErrorDataDecoderException
- if the default charset was wrong when decoding or other errors
-
HttpPostStandardRequestDecoder
public HttpPostStandardRequestDecoder(HttpDataFactory factory, HttpRequest request, Charset charset, int maxFields, int maxBufferedBytes) - Parameters:
factory
- the factory used to create InterfaceHttpDatarequest
- the request to decodecharset
- the charset to use as defaultmaxFields
- the maximum number of fields the form can have,-1
to disablemaxBufferedBytes
- the maximum number of bytes the decoder can buffer when decoding a field,-1
to disable- Throws:
NullPointerException
- for request or charset or factoryHttpPostRequestDecoder.ErrorDataDecoderException
- if the default charset was wrong when decoding or other errors
-
-
Method Details
-
checkDestroyed
private void checkDestroyed() -
isMultipart
public boolean isMultipart()True if this request is a Multipart request- Specified by:
isMultipart
in interfaceInterfaceHttpPostRequestDecoder
- Returns:
- True if this request is a Multipart request
-
setDiscardThreshold
public void setDiscardThreshold(int discardThreshold) Set the amount of bytes after which read bytes in the buffer should be discarded. Setting this lower gives lower memory usage but with the overhead of more memory copies. Use0
to disable it.- Specified by:
setDiscardThreshold
in interfaceInterfaceHttpPostRequestDecoder
-
getDiscardThreshold
public int getDiscardThreshold()Return the threshold in bytes after which read data in the buffer should be discarded.- Specified by:
getDiscardThreshold
in interfaceInterfaceHttpPostRequestDecoder
-
getBodyHttpDatas
This getMethod returns a List of all HttpDatas from body.
If chunked, all chunks must have been offered using offer() getMethod. If not, NotEnoughDataDecoderException will be raised.- Specified by:
getBodyHttpDatas
in interfaceInterfaceHttpPostRequestDecoder
- Returns:
- the list of HttpDatas from Body part for POST getMethod
- Throws:
HttpPostRequestDecoder.NotEnoughDataDecoderException
- Need more chunks
-
getBodyHttpDatas
This getMethod returns a List of all HttpDatas with the given name from body.
If chunked, all chunks must have been offered using offer() getMethod. If not, NotEnoughDataDecoderException will be raised.- Specified by:
getBodyHttpDatas
in interfaceInterfaceHttpPostRequestDecoder
- Returns:
- All Body HttpDatas with the given name (ignore case)
- Throws:
HttpPostRequestDecoder.NotEnoughDataDecoderException
- need more chunks
-
getBodyHttpData
This getMethod returns the first InterfaceHttpData with the given name from body.
If chunked, all chunks must have been offered using offer() getMethod. If not, NotEnoughDataDecoderException will be raised.- Specified by:
getBodyHttpData
in interfaceInterfaceHttpPostRequestDecoder
- Returns:
- The first Body InterfaceHttpData with the given name (ignore case)
- Throws:
HttpPostRequestDecoder.NotEnoughDataDecoderException
- need more chunks
-
offer
Initialized the internals from a new chunk- Specified by:
offer
in interfaceInterfaceHttpPostRequestDecoder
- Parameters:
content
- the new received chunk- Throws:
HttpPostRequestDecoder.ErrorDataDecoderException
- if there is a problem with the charset decoding or other errors
-
hasNext
public boolean hasNext()True if at current getStatus, there is an available decoded InterfaceHttpData from the Body. This getMethod works for chunked and not chunked request.- Specified by:
hasNext
in interfaceInterfaceHttpPostRequestDecoder
- Returns:
- True if at current getStatus, there is a decoded InterfaceHttpData
- Throws:
HttpPostRequestDecoder.EndOfDataDecoderException
- No more data will be available
-
next
Returns the next available InterfaceHttpData or null if, at the time it is called, there is no more available InterfaceHttpData. A subsequent call to offer(httpChunk) could enable more data. Be sure to callReferenceCounted.release()
after you are done with processing to make sure to not leak any resources- Specified by:
next
in interfaceInterfaceHttpPostRequestDecoder
- Returns:
- the next available InterfaceHttpData or null if none
- Throws:
HttpPostRequestDecoder.EndOfDataDecoderException
- No more data will be available
-
currentPartialHttpData
Description copied from interface:InterfaceHttpPostRequestDecoder
Returns the current InterfaceHttpData if currently in decoding status, meaning all data are not yet within, or null if there is no InterfaceHttpData currently in decoding status (either because none yet decoded or none currently partially decoded). Full decoded ones are accessible through hasNext() and next() methods.- Specified by:
currentPartialHttpData
in interfaceInterfaceHttpPostRequestDecoder
- Returns:
- the current InterfaceHttpData if currently in decoding status or null if none.
-
parseBody
private void parseBody()This getMethod will parse as much as possible data and fill the list and map- Throws:
HttpPostRequestDecoder.ErrorDataDecoderException
- if there is a problem with the charset decoding or other errors
-
addHttpData
Utility function to add a new decoded data -
parseBodyAttributesStandard
private void parseBodyAttributesStandard()This getMethod fill the map and list with as much Attribute as possible from Body in not Multipart mode.- Throws:
HttpPostRequestDecoder.ErrorDataDecoderException
- if there is a problem with the charset decoding or other errors
-
parseBodyAttributes
private void parseBodyAttributes()This getMethod fill the map and list with as much Attribute as possible from Body in not Multipart mode.- Throws:
HttpPostRequestDecoder.ErrorDataDecoderException
- if there is a problem with the charset decoding or other errors
-
setFinalBuffer
- Throws:
IOException
-
decodeAttribute
Decode component- Returns:
- the decoded component
-
decodeAttribute
-
destroy
public void destroy()Destroy theHttpPostStandardRequestDecoder
and release all it resources. After this method was called it is not possible to operate on it anymore.- Specified by:
destroy
in interfaceInterfaceHttpPostRequestDecoder
-
cleanFiles
public void cleanFiles()Clean allHttpData
s for the current request.- Specified by:
cleanFiles
in interfaceInterfaceHttpPostRequestDecoder
-
removeHttpDataFromClean
Remove the given FileUpload from the list of FileUploads to clean- Specified by:
removeHttpDataFromClean
in interfaceInterfaceHttpPostRequestDecoder
-