Class HttpPostStandardRequestDecoder
- java.lang.Object
-
- io.netty.handler.codec.http.multipart.HttpPostStandardRequestDecoder
-
- All Implemented Interfaces:
InterfaceHttpPostRequestDecoder
public class HttpPostStandardRequestDecoder extends java.lang.Object implements InterfaceHttpPostRequestDecoder
This decoder will decode Body and can handle POST BODY. You MUST calldestroy()after completion to release all resources.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classHttpPostStandardRequestDecoder.UrlDecoderprivate static classHttpPostStandardRequestDecoder.UrlEncodedDetector
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<InterfaceHttpData>bodyListHttpDataHttpDatas from Bodyprivate intbodyListHttpDataRankBody HttpDatas current positionprivate java.util.Map<java.lang.String,java.util.List<InterfaceHttpData>>bodyMapHttpDataHttpDatas as Map from Bodyprivate java.nio.charset.CharsetcharsetDefault charset to useprivate AttributecurrentAttributeThe current Attribute that is currently in decode processprivate HttpPostRequestDecoder.MultiPartStatuscurrentStatusCurrent getStatusprivate booleandestroyedprivate intdiscardThresholdprivate HttpDataFactoryfactoryFactory used to create InterfaceHttpDataprivate booleanisLastChunkDoes the last chunk already receivedprivate HttpRequestrequestRequest to decodeprivate ByteBufundecodedChunkThe current channelBuffer
-
Constructor Summary
Constructors Constructor Description HttpPostStandardRequestDecoder(HttpRequest request)HttpPostStandardRequestDecoder(HttpDataFactory factory, HttpRequest request)HttpPostStandardRequestDecoder(HttpDataFactory factory, HttpRequest request, java.nio.charset.Charset charset)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddHttpData(InterfaceHttpData data)Utility function to add a new decoded dataprivate voidcheckDestroyed()voidcleanFiles()Clean allHttpDatas for the current request.InterfaceHttpDatacurrentPartialHttpData()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 ByteBufdecodeAttribute(ByteBuf b, java.nio.charset.Charset charset)private static java.lang.StringdecodeAttribute(java.lang.String s, java.nio.charset.Charset charset)Decode componentvoiddestroy()Destroy theHttpPostStandardRequestDecoderand release all it resources.InterfaceHttpDatagetBodyHttpData(java.lang.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.java.util.List<InterfaceHttpData>getBodyHttpDatas()This getMethod returns a List of all HttpDatas from body.
If chunked, all chunks must have been offered using offer() getMethod.java.util.List<InterfaceHttpData>getBodyHttpDatas(java.lang.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.intgetDiscardThreshold()Return the threshold in bytes after which read data in the buffer should be discarded.booleanhasNext()True if at current getStatus, there is an available decoded InterfaceHttpData from the Body.booleanisMultipart()True if this request is a Multipart requestInterfaceHttpDatanext()Returns the next available InterfaceHttpData or null if, at the time it is called, there is no more available InterfaceHttpData.HttpPostStandardRequestDecoderoffer(HttpContent content)Initialized the internals from a new chunkprivate voidparseBody()This getMethod will parse as much as possible data and fill the list and mapprivate voidparseBodyAttributes()This getMethod fill the map and list with as much Attribute as possible from Body in not Multipart mode.private voidparseBodyAttributesStandard()This getMethod fill the map and list with as much Attribute as possible from Body in not Multipart mode.voidremoveHttpDataFromClean(InterfaceHttpData data)Remove the given FileUpload from the list of FileUploads to cleanvoidsetDiscardThreshold(int discardThreshold)Set the amount of bytes after which read bytes in the buffer should be discarded.private voidsetFinalBuffer(ByteBuf buffer)
-
-
-
Field Detail
-
factory
private final HttpDataFactory factory
Factory used to create InterfaceHttpData
-
request
private final HttpRequest request
Request to decode
-
charset
private final java.nio.charset.Charset charset
Default charset to use
-
isLastChunk
private boolean isLastChunk
Does the last chunk already received
-
bodyListHttpData
private final java.util.List<InterfaceHttpData> bodyListHttpData
HttpDatas from Body
-
bodyMapHttpData
private final java.util.Map<java.lang.String,java.util.List<InterfaceHttpData>> bodyMapHttpData
HttpDatas as Map from Body
-
undecodedChunk
private ByteBuf undecodedChunk
The current channelBuffer
-
bodyListHttpDataRank
private int bodyListHttpDataRank
Body HttpDatas current position
-
currentStatus
private HttpPostRequestDecoder.MultiPartStatus currentStatus
Current getStatus
-
currentAttribute
private Attribute currentAttribute
The current Attribute that is currently in decode process
-
destroyed
private boolean destroyed
-
discardThreshold
private int discardThreshold
-
-
Constructor Detail
-
HttpPostStandardRequestDecoder
public HttpPostStandardRequestDecoder(HttpRequest request)
- Parameters:
request- the request to decode- Throws:
java.lang.NullPointerException- for requestHttpPostRequestDecoder.ErrorDataDecoderException- if the default charset was wrong when decoding or other errors
-
HttpPostStandardRequestDecoder
public HttpPostStandardRequestDecoder(HttpDataFactory factory, HttpRequest request)
- Parameters:
factory- the factory used to create InterfaceHttpDatarequest- the request to decode- Throws:
java.lang.NullPointerException- for request or factoryHttpPostRequestDecoder.ErrorDataDecoderException- if the default charset was wrong when decoding or other errors
-
HttpPostStandardRequestDecoder
public HttpPostStandardRequestDecoder(HttpDataFactory factory, HttpRequest request, java.nio.charset.Charset charset)
- Parameters:
factory- the factory used to create InterfaceHttpDatarequest- the request to decodecharset- the charset to use as default- Throws:
java.lang.NullPointerException- for request or charset or factoryHttpPostRequestDecoder.ErrorDataDecoderException- if the default charset was wrong when decoding or other errors
-
-
Method Detail
-
checkDestroyed
private void checkDestroyed()
-
isMultipart
public boolean isMultipart()
True if this request is a Multipart request- Specified by:
isMultipartin 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. Use0to disable it.- Specified by:
setDiscardThresholdin interfaceInterfaceHttpPostRequestDecoder
-
getDiscardThreshold
public int getDiscardThreshold()
Return the threshold in bytes after which read data in the buffer should be discarded.- Specified by:
getDiscardThresholdin interfaceInterfaceHttpPostRequestDecoder
-
getBodyHttpDatas
public java.util.List<InterfaceHttpData> 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:
getBodyHttpDatasin interfaceInterfaceHttpPostRequestDecoder- Returns:
- the list of HttpDatas from Body part for POST getMethod
- Throws:
HttpPostRequestDecoder.NotEnoughDataDecoderException- Need more chunks
-
getBodyHttpDatas
public java.util.List<InterfaceHttpData> getBodyHttpDatas(java.lang.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. If not, NotEnoughDataDecoderException will be raised.- Specified by:
getBodyHttpDatasin interfaceInterfaceHttpPostRequestDecoder- Returns:
- All Body HttpDatas with the given name (ignore case)
- Throws:
HttpPostRequestDecoder.NotEnoughDataDecoderException- need more chunks
-
getBodyHttpData
public InterfaceHttpData getBodyHttpData(java.lang.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. If not, NotEnoughDataDecoderException will be raised.- Specified by:
getBodyHttpDatain interfaceInterfaceHttpPostRequestDecoder- Returns:
- The first Body InterfaceHttpData with the given name (ignore case)
- Throws:
HttpPostRequestDecoder.NotEnoughDataDecoderException- need more chunks
-
offer
public HttpPostStandardRequestDecoder offer(HttpContent content)
Initialized the internals from a new chunk- Specified by:
offerin 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:
hasNextin interfaceInterfaceHttpPostRequestDecoder- Returns:
- True if at current getStatus, there is a decoded InterfaceHttpData
- Throws:
HttpPostRequestDecoder.EndOfDataDecoderException- No more data will be available
-
next
public InterfaceHttpData 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:
nextin interfaceInterfaceHttpPostRequestDecoder- Returns:
- the next available InterfaceHttpData or null if none
- Throws:
HttpPostRequestDecoder.EndOfDataDecoderException- No more data will be available
-
currentPartialHttpData
public InterfaceHttpData currentPartialHttpData()
Description copied from interface:InterfaceHttpPostRequestDecoderReturns 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:
currentPartialHttpDatain 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
protected void addHttpData(InterfaceHttpData data)
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
private void setFinalBuffer(ByteBuf buffer) throws java.io.IOException
- Throws:
java.io.IOException
-
decodeAttribute
private static java.lang.String decodeAttribute(java.lang.String s, java.nio.charset.Charset charset)Decode component- Returns:
- the decoded component
-
decodeAttribute
private static ByteBuf decodeAttribute(ByteBuf b, java.nio.charset.Charset charset)
-
destroy
public void destroy()
Destroy theHttpPostStandardRequestDecoderand release all it resources. After this method was called it is not possible to operate on it anymore.- Specified by:
destroyin interfaceInterfaceHttpPostRequestDecoder
-
cleanFiles
public void cleanFiles()
Clean allHttpDatas for the current request.- Specified by:
cleanFilesin interfaceInterfaceHttpPostRequestDecoder
-
removeHttpDataFromClean
public void removeHttpDataFromClean(InterfaceHttpData data)
Remove the given FileUpload from the list of FileUploads to clean- Specified by:
removeHttpDataFromCleanin interfaceInterfaceHttpPostRequestDecoder
-
-