Class HttpPostRequestDecoder
- java.lang.Object
-
- io.netty.handler.codec.http.multipart.HttpPostRequestDecoder
-
- All Implemented Interfaces:
InterfaceHttpPostRequestDecoder
public class HttpPostRequestDecoder 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 static class
HttpPostRequestDecoder.EndOfDataDecoderException
Exception when the body is fully decoded, even if there is still datastatic class
HttpPostRequestDecoder.ErrorDataDecoderException
Exception when an error occurs while decodingprotected static class
HttpPostRequestDecoder.MultiPartStatus
states follow NOTSTARTED PREAMBLE ( (HEADERDELIMITER DISPOSITION (FIELD | FILEUPLOAD))* (HEADERDELIMITER DISPOSITION MIXEDPREAMBLE (MIXEDDELIMITER MIXEDDISPOSITION MIXEDFILEUPLOAD)+ MIXEDCLOSEDELIMITER)* CLOSEDELIMITER)+ EPILOGUE First getStatus is: NOSTARTED Content-type: multipart/form-data, boundary=AaB03x => PREAMBLE in Header --AaB03x => HEADERDELIMITER content-disposition: form-data; name="field1" => DISPOSITION Joe Blow => FIELD --AaB03x => HEADERDELIMITER content-disposition: form-data; name="pics" => DISPOSITION Content-type: multipart/mixed, boundary=BbC04y --BbC04y => MIXEDDELIMITER Content-disposition: attachment; filename="file1.txt" => MIXEDDISPOSITION Content-Type: text/plain ... contents of file1.txtstatic class
HttpPostRequestDecoder.NotEnoughDataDecoderException
Exception when try reading data from request in chunked format, and not enough data are available (need more chunks)static class
HttpPostRequestDecoder.TooLongFormFieldException
Exception when a field content is too longstatic class
HttpPostRequestDecoder.TooManyFormFieldsException
Exception when the maximum number of fields for a given form is reached
-
Constructor Summary
Constructors Constructor Description HttpPostRequestDecoder(HttpRequest request)
HttpPostRequestDecoder(HttpRequest request, int maxFields, int maxBufferedBytes)
HttpPostRequestDecoder(HttpDataFactory factory, HttpRequest request)
HttpPostRequestDecoder(HttpDataFactory factory, HttpRequest request, java.nio.charset.Charset charset)
HttpPostRequestDecoder(HttpDataFactory factory, HttpRequest request, java.nio.charset.Charset charset, int maxFields, int maxBufferedBytes)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
cleanFiles()
Clean all HttpDatas (on Disk) for the current request.InterfaceHttpData
currentPartialHttpData()
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).void
destroy()
Destroy theInterfaceHttpPostRequestDecoder
and release all it resources.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.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.int
getDiscardThreshold()
Return the threshold in bytes after which read data in the buffer should be discarded.protected static java.lang.String[]
getMultipartDataBoundary(java.lang.String contentType)
Check from the request ContentType if this request is a Multipart request.boolean
hasNext()
True if at current getStatus, there is an available decoded InterfaceHttpData from the Body.boolean
isMultipart()
True if this request is a Multipart requeststatic boolean
isMultipart(HttpRequest request)
Check if the given request is a multipart requestInterfaceHttpData
next()
Returns the next available InterfaceHttpData or null if, at the time it is called, there is no more available InterfaceHttpData.InterfaceHttpPostRequestDecoder
offer(HttpContent content)
Initialized the internals from a new chunkvoid
removeHttpDataFromClean(InterfaceHttpData data)
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.
-
-
-
Constructor Detail
-
HttpPostRequestDecoder
public HttpPostRequestDecoder(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
-
HttpPostRequestDecoder
public HttpPostRequestDecoder(HttpRequest request, int maxFields, int maxBufferedBytes)
- Parameters:
request
- the request to decodemaxFields
- 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:
java.lang.NullPointerException
- for requestHttpPostRequestDecoder.ErrorDataDecoderException
- if the default charset was wrong when decoding or other errors
-
HttpPostRequestDecoder
public HttpPostRequestDecoder(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
-
HttpPostRequestDecoder
public HttpPostRequestDecoder(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
-
HttpPostRequestDecoder
public HttpPostRequestDecoder(HttpDataFactory factory, HttpRequest request, java.nio.charset.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:
java.lang.NullPointerException
- for request or charset or factoryHttpPostRequestDecoder.ErrorDataDecoderException
- if the default charset was wrong when decoding or other errors
-
-
Method Detail
-
isMultipart
public static boolean isMultipart(HttpRequest request)
Check if the given request is a multipart request- Returns:
- True if the request is a Multipart request
-
getMultipartDataBoundary
protected static java.lang.String[] getMultipartDataBoundary(java.lang.String contentType)
Check from the request ContentType if this request is a Multipart request.- Returns:
- an array of String if multipartDataBoundary exists with the multipartDataBoundary as first element, charset if any as second (missing if not set), else null
-
isMultipart
public boolean isMultipart()
Description copied from interface:InterfaceHttpPostRequestDecoder
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)
Description copied from interface:InterfaceHttpPostRequestDecoder
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()
Description copied from interface:InterfaceHttpPostRequestDecoder
Return the threshold in bytes after which read data in the buffer should be discarded.- Specified by:
getDiscardThreshold
in interfaceInterfaceHttpPostRequestDecoder
-
getBodyHttpDatas
public java.util.List<InterfaceHttpData> getBodyHttpDatas()
Description copied from interface:InterfaceHttpPostRequestDecoder
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
-
getBodyHttpDatas
public java.util.List<InterfaceHttpData> getBodyHttpDatas(java.lang.String name)
Description copied from interface:InterfaceHttpPostRequestDecoder
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)
-
getBodyHttpData
public InterfaceHttpData getBodyHttpData(java.lang.String name)
Description copied from interface:InterfaceHttpPostRequestDecoder
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)
-
offer
public InterfaceHttpPostRequestDecoder offer(HttpContent content)
Description copied from interface:InterfaceHttpPostRequestDecoder
Initialized the internals from a new chunk- Specified by:
offer
in interfaceInterfaceHttpPostRequestDecoder
- Parameters:
content
- the new received chunk
-
hasNext
public boolean hasNext()
Description copied from interface:InterfaceHttpPostRequestDecoder
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
-
next
public InterfaceHttpData next()
Description copied from interface:InterfaceHttpPostRequestDecoder
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
-
currentPartialHttpData
public InterfaceHttpData 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.
-
destroy
public void destroy()
Description copied from interface:InterfaceHttpPostRequestDecoder
Destroy theInterfaceHttpPostRequestDecoder
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()
Description copied from interface:InterfaceHttpPostRequestDecoder
Clean all HttpDatas (on Disk) for the current request.- Specified by:
cleanFiles
in interfaceInterfaceHttpPostRequestDecoder
-
removeHttpDataFromClean
public void removeHttpDataFromClean(InterfaceHttpData data)
Description copied from interface:InterfaceHttpPostRequestDecoder
Remove the given FileUpload from the list of FileUploads to clean- Specified by:
removeHttpDataFromClean
in interfaceInterfaceHttpPostRequestDecoder
-
-