Class HttpPostRequestDecoder
- java.lang.Object
-
- org.jboss.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 (both multipart and standard).
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classHttpPostRequestDecoder.EndOfDataDecoderExceptionException when the body is fully decoded, even if there is still datastatic classHttpPostRequestDecoder.ErrorDataDecoderExceptionException when an error occurs while decodingprotected static classHttpPostRequestDecoder.MultiPartStatusstates follow NOTSTARTED PREAMBLE ( (HEADERDELIMITER DISPOSITION (FIELD | FILEUPLOAD))* (HEADERDELIMITER DISPOSITION MIXEDPREAMBLE (MIXEDDELIMITER MIXEDDISPOSITION MIXEDFILEUPLOAD)+ MIXEDCLOSEDELIMITER)* CLOSEDELIMITER)+ EPILOGUE First status 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 ...static classHttpPostRequestDecoder.NotEnoughDataDecoderExceptionException when try reading data from request in chunked format, and not enough data are available (need more chunks)
-
Field Summary
Fields Modifier and Type Field Description private InterfaceHttpPostRequestDecoderdecoderDoes this request is a Multipart request(package private) static intDEFAULT_MAX_BUFFERED_BYTES(package private) static intDEFAULT_MAX_FIELDS
-
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 voidcleanFiles()Clean all HttpDatas (on Disk) for the current request.InterfaceHttpDatagetBodyHttpData(java.lang.String name)This method returns the first InterfaceHttpData with the given name from body.
If chunked, all chunks must have been offered using offer() method.java.util.List<InterfaceHttpData>getBodyHttpDatas()This method returns a List of all HttpDatas from body.
If chunked, all chunks must have been offered using offer() method.java.util.List<InterfaceHttpData>getBodyHttpDatas(java.lang.String name)This method returns a List of all HttpDatas with the given name from body.
If chunked, all chunks must have been offered using offer() method.protected static java.lang.String[]getMultipartDataBoundary(java.lang.String contentType)Check from the request ContentType if this request is a Multipart request.booleanhasNext()True if at current status, there is an available decoded InterfaceHttpData from the Body.booleanisMultipart()True if this request is a Multipart requeststatic booleanisMultipart(HttpRequest request)Check if the given 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.voidoffer(HttpChunk chunk)Initialized the internals from a new chunkvoidremoveHttpDataFromClean(InterfaceHttpData data)Remove the given FileUpload from the list of FileUploads to cleanprivate static java.lang.String[]splitHeaderContentType(java.lang.String sb)Split the very first line (Content-Type value) in 3 Strings
-
-
-
Field Detail
-
DEFAULT_MAX_FIELDS
static final int DEFAULT_MAX_FIELDS
- See Also:
- Constant Field Values
-
DEFAULT_MAX_BUFFERED_BYTES
static final int DEFAULT_MAX_BUFFERED_BYTES
- See Also:
- Constant Field Values
-
decoder
private final InterfaceHttpPostRequestDecoder decoder
Does this request is a Multipart request
-
-
Constructor Detail
-
HttpPostRequestDecoder
public HttpPostRequestDecoder(HttpRequest request) throws HttpPostRequestDecoder.ErrorDataDecoderException
- 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(HttpDataFactory factory, HttpRequest request) throws HttpPostRequestDecoder.ErrorDataDecoderException
- 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(HttpRequest request, int maxFields, int maxBufferedBytes) throws HttpPostRequestDecoder.ErrorDataDecoderException
- Parameters:
request- the request to decodemaxFields- the maximum number of fields the form can have,-1to disablemaxBufferedBytes- the maximum number of bytes the decoder can buffer when decoding a field,-1to 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, java.nio.charset.Charset charset) throws HttpPostRequestDecoder.ErrorDataDecoderException
- 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) throws HttpPostRequestDecoder.ErrorDataDecoderException
- 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,-1to disablemaxBufferedBytes- the maximum number of bytes the decoder can buffer when decoding a field,-1to 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) throws HttpPostRequestDecoder.ErrorDataDecoderException
Check if the given request is a multipart request- Returns:
- True if the request is a Multipart request
- Throws:
HttpPostRequestDecoder.ErrorDataDecoderException
-
getMultipartDataBoundary
protected static java.lang.String[] getMultipartDataBoundary(java.lang.String contentType) throws HttpPostRequestDecoder.ErrorDataDecoderExceptionCheck 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
- Throws:
HttpPostRequestDecoder.ErrorDataDecoderException
-
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
-
getBodyHttpDatas
public java.util.List<InterfaceHttpData> getBodyHttpDatas() throws HttpPostRequestDecoder.NotEnoughDataDecoderException
This method returns a List of all HttpDatas from body.
If chunked, all chunks must have been offered using offer() method. If not, NotEnoughDataDecoderException will be raised.- Specified by:
getBodyHttpDatasin interfaceInterfaceHttpPostRequestDecoder- Returns:
- the list of HttpDatas from Body part for POST method
- Throws:
HttpPostRequestDecoder.NotEnoughDataDecoderException- Need more chunks
-
getBodyHttpDatas
public java.util.List<InterfaceHttpData> getBodyHttpDatas(java.lang.String name) throws HttpPostRequestDecoder.NotEnoughDataDecoderException
This method returns a List of all HttpDatas with the given name from body.
If chunked, all chunks must have been offered using offer() method. 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) throws HttpPostRequestDecoder.NotEnoughDataDecoderException
This method returns the first InterfaceHttpData with the given name from body.
If chunked, all chunks must have been offered using offer() method. 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 void offer(HttpChunk chunk) throws HttpPostRequestDecoder.ErrorDataDecoderException
Initialized the internals from a new chunk- Specified by:
offerin interfaceInterfaceHttpPostRequestDecoder- Parameters:
chunk- the new received chunk- Throws:
HttpPostRequestDecoder.ErrorDataDecoderException- if there is a problem with the charset decoding or other errors
-
hasNext
public boolean hasNext() throws HttpPostRequestDecoder.EndOfDataDecoderExceptionTrue if at current status, there is an available decoded InterfaceHttpData from the Body. This method works for chunked and not chunked request.- Specified by:
hasNextin interfaceInterfaceHttpPostRequestDecoder- Returns:
- True if at current status, there is a decoded InterfaceHttpData
- Throws:
HttpPostRequestDecoder.EndOfDataDecoderException- No more data will be available
-
next
public InterfaceHttpData next() throws HttpPostRequestDecoder.EndOfDataDecoderException
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.- Specified by:
nextin interfaceInterfaceHttpPostRequestDecoder- Returns:
- the next available InterfaceHttpData or null if none
- Throws:
HttpPostRequestDecoder.EndOfDataDecoderException- No more data will be available
-
cleanFiles
public void cleanFiles()
Clean all HttpDatas (on Disk) 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
-
splitHeaderContentType
private static java.lang.String[] splitHeaderContentType(java.lang.String sb)
Split the very first line (Content-Type value) in 3 Strings- Returns:
- the array of 3 Strings
-
-