Class HttpPostMultipartRequestDecoder
- java.lang.Object
-
- org.jboss.netty.handler.codec.http.multipart.HttpPostMultipartRequestDecoder
-
- All Implemented Interfaces:
InterfaceHttpPostRequestDecoder
public class HttpPostMultipartRequestDecoder extends java.lang.Object implements InterfaceHttpPostRequestDecoder
This decoder will decode Body and can handle POST BODY in multipart form.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<InterfaceHttpData>
bodyListHttpData
HttpDatas from Bodyprivate int
bodyListHttpDataRank
Body HttpDatas current positionprivate java.util.Map<java.lang.String,java.util.List<InterfaceHttpData>>
bodyMapHttpData
HttpDatas as Map from Bodyprivate java.nio.charset.Charset
charset
Default charset to useprivate Attribute
currentAttribute
The current Attribute that is currently in decode processprivate java.util.Map<java.lang.String,Attribute>
currentFieldAttributes
Used in Multipartprivate FileUpload
currentFileUpload
The current FileUpload that is currently in decode processprivate HttpPostRequestDecoder.MultiPartStatus
currentStatus
Current statusprivate HttpDataFactory
factory
Factory used to create InterfaceHttpDataprivate boolean
isLastChunk
Does the last chunk already receivedprivate int
maxBufferedBytes
The maximum number of accumulated bytes when decoding a fieldprivate int
maxFields
The maximum number of fields allows by the formprivate java.lang.String
multipartDataBoundary
If multipart, this is the boundary for the flobal multipartprivate java.lang.String
multipartMixedBoundary
If multipart, there could be internal multiparts (mixed) to the global multipart.private HttpRequest
request
Request to decodeprivate ChannelBuffer
undecodedChunk
The current channelBuffer
-
Constructor Summary
Constructors Constructor Description HttpPostMultipartRequestDecoder(HttpRequest request)
HttpPostMultipartRequestDecoder(HttpDataFactory factory, HttpRequest request)
HttpPostMultipartRequestDecoder(HttpDataFactory factory, HttpRequest request, java.nio.charset.Charset charset)
HttpPostMultipartRequestDecoder(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 private void
addHttpData(InterfaceHttpData data)
Utility function to add a new decoded datavoid
cleanFiles()
Clean all HttpDatas (on Disk) for the current request.private void
cleanMixedAttributes()
Remove all Attributes that should be cleaned between two FileUpload in Mixed modeprivate static java.lang.String
cleanString(java.lang.String field)
Clean the String from any unallowed characterprivate InterfaceHttpData
decodeMultipart(HttpPostRequestDecoder.MultiPartStatus state)
Decode a multipart request by pieces
NOTSTARTED PREAMBLE (
(HEADERDELIMITER DISPOSITION (FIELD | FILEUPLOAD))*
(HEADERDELIMITER DISPOSITION MIXEDPREAMBLE
(MIXEDDELIMITER MIXEDDISPOSITION MIXEDFILEUPLOAD)+
MIXEDCLOSEDELIMITER)*
CLOSEDELIMITER)+ EPILOGUE
Inspired from HttpMessageDecoderprivate InterfaceHttpData
findMultipartDelimiter(java.lang.String delimiter, HttpPostRequestDecoder.MultiPartStatus dispositionStatus, HttpPostRequestDecoder.MultiPartStatus closeDelimiterStatus)
Find the next Multipart Delimiterprivate InterfaceHttpData
findMultipartDisposition()
Find the next DispositionInterfaceHttpData
getBodyHttpData(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.private InterfaceHttpData
getFileUpload(java.lang.String delimiter)
Get the FileUpload (new one or current one)boolean
hasNext()
True if at current status, there is an available decoded InterfaceHttpData from the Body.boolean
isMultipart()
True if this request is a Multipart requestprivate void
loadFieldMultipart(java.lang.String delimiter)
Load the field value from a Multipart requestprivate void
loadFieldMultipartStandard(java.lang.String delimiter)
Load the field value from a Multipart requestInterfaceHttpData
next()
Returns the next available InterfaceHttpData or null if, at the time it is called, there is no more available InterfaceHttpData.void
offer(HttpChunk chunk)
Initialized the internals from a new chunkprivate void
parseBody()
This method will parse as much as possible data and fill the list and mapprivate void
parseBodyMultipart()
Parse the Body for multipartprivate java.lang.String
readDelimiter(java.lang.String delimiter)
Read one line up to --delimiter or --delimiter-- and if existing the CRLF or LF.private java.lang.String
readDelimiterStandard(java.lang.String delimiter)
Read one line up to --delimiter or --delimiter-- and if existing the CRLF or LF Read one line up to --delimiter or --delimiter-- and if existing the CRLF or LF.private void
readFileUploadByteMultipart(java.lang.String delimiter)
Read a FileUpload data as Byte (Binary) and add the bytes directly to the FileUpload.private void
readFileUploadByteMultipartStandard(java.lang.String delimiter)
Read a FileUpload data as Byte (Binary) and add the bytes directly to the FileUpload.private java.lang.String
readLine()
Read one line up to the CRLF or LFprivate java.lang.String
readLineStandard()
Read one line up to the CRLF or LFvoid
removeHttpDataFromClean(InterfaceHttpData data)
Remove the given FileUpload from the list of FileUploads to cleanprivate void
setMultipart(java.lang.String contentType)
Set from the request ContentType the multipartDataBoundary and the possible charset.(package private) void
skipControlCharacters()
Skip control Characters(package private) void
skipControlCharactersStandard()
private boolean
skipOneLine()
Skip one empty lineprivate static java.lang.String[]
splitMultipartHeader(java.lang.String sb)
Split one header in Multipartprivate static java.lang.String[]
splitMultipartHeaderValues(java.lang.String svalue)
Split one header value in Multipart.
-
-
-
Field Detail
-
factory
private final HttpDataFactory factory
Factory used to create InterfaceHttpData
-
request
private final HttpRequest request
Request to decode
-
maxFields
private final int maxFields
The maximum number of fields allows by the form
-
maxBufferedBytes
private final int maxBufferedBytes
The maximum number of accumulated bytes when decoding a field
-
charset
private 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 ChannelBuffer undecodedChunk
The current channelBuffer
-
bodyListHttpDataRank
private int bodyListHttpDataRank
Body HttpDatas current position
-
multipartDataBoundary
private java.lang.String multipartDataBoundary
If multipart, this is the boundary for the flobal multipart
-
multipartMixedBoundary
private java.lang.String multipartMixedBoundary
If multipart, there could be internal multiparts (mixed) to the global multipart. Only one level is allowed.
-
currentStatus
private HttpPostRequestDecoder.MultiPartStatus currentStatus
Current status
-
currentFieldAttributes
private java.util.Map<java.lang.String,Attribute> currentFieldAttributes
Used in Multipart
-
currentFileUpload
private FileUpload currentFileUpload
The current FileUpload that is currently in decode process
-
currentAttribute
private Attribute currentAttribute
The current Attribute that is currently in decode process
-
-
Constructor Detail
-
HttpPostMultipartRequestDecoder
public HttpPostMultipartRequestDecoder(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
-
HttpPostMultipartRequestDecoder
public HttpPostMultipartRequestDecoder(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
-
HttpPostMultipartRequestDecoder
public HttpPostMultipartRequestDecoder(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
-
HttpPostMultipartRequestDecoder
public HttpPostMultipartRequestDecoder(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,-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
-
setMultipart
private void setMultipart(java.lang.String contentType) throws HttpPostRequestDecoder.ErrorDataDecoderException
Set from the request ContentType the multipartDataBoundary and the possible charset.
-
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
-
getBodyHttpDatas
public java.util.List<InterfaceHttpData> getBodyHttpDatas() throws HttpPostRequestDecoder.NotEnoughDataDecoderException
Description copied from interface:InterfaceHttpPostRequestDecoder
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:
getBodyHttpDatas
in 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
Description copied from interface:InterfaceHttpPostRequestDecoder
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:
getBodyHttpDatas
in 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
Description copied from interface:InterfaceHttpPostRequestDecoder
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:
getBodyHttpData
in 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
Description copied from interface:InterfaceHttpPostRequestDecoder
Initialized the internals from a new chunk- Specified by:
offer
in 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.EndOfDataDecoderException
Description copied from interface:InterfaceHttpPostRequestDecoder
True if at current status, there is an available decoded InterfaceHttpData from the Body. This method works for chunked and not chunked request.- Specified by:
hasNext
in 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
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.- Specified by:
next
in interfaceInterfaceHttpPostRequestDecoder
- Returns:
- the next available InterfaceHttpData or null if none
- Throws:
HttpPostRequestDecoder.EndOfDataDecoderException
- No more data will be available
-
parseBody
private void parseBody() throws HttpPostRequestDecoder.ErrorDataDecoderException
This method 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
private void addHttpData(InterfaceHttpData data) throws HttpPostRequestDecoder.ErrorDataDecoderException
Utility function to add a new decoded data
-
parseBodyMultipart
private void parseBodyMultipart() throws HttpPostRequestDecoder.ErrorDataDecoderException
Parse the Body for multipart- Throws:
HttpPostRequestDecoder.ErrorDataDecoderException
- if there is a problem with the charset decoding or other errors
-
decodeMultipart
private InterfaceHttpData decodeMultipart(HttpPostRequestDecoder.MultiPartStatus state) throws HttpPostRequestDecoder.ErrorDataDecoderException
Decode a multipart request by pieces
NOTSTARTED PREAMBLE (
(HEADERDELIMITER DISPOSITION (FIELD | FILEUPLOAD))*
(HEADERDELIMITER DISPOSITION MIXEDPREAMBLE
(MIXEDDELIMITER MIXEDDISPOSITION MIXEDFILEUPLOAD)+
MIXEDCLOSEDELIMITER)*
CLOSEDELIMITER)+ EPILOGUE
Inspired from HttpMessageDecoder- Returns:
- the next decoded InterfaceHttpData or null if none until now.
- Throws:
HttpPostRequestDecoder.ErrorDataDecoderException
- if an error occurs
-
skipControlCharacters
void skipControlCharacters() throws HttpPostRequestDecoder.NotEnoughDataDecoderException
Skip control Characters
-
skipControlCharactersStandard
void skipControlCharactersStandard()
-
findMultipartDelimiter
private InterfaceHttpData findMultipartDelimiter(java.lang.String delimiter, HttpPostRequestDecoder.MultiPartStatus dispositionStatus, HttpPostRequestDecoder.MultiPartStatus closeDelimiterStatus) throws HttpPostRequestDecoder.ErrorDataDecoderException
Find the next Multipart Delimiter- Parameters:
delimiter
- delimiter to finddispositionStatus
- the next status if the delimiter is a startcloseDelimiterStatus
- the next status if the delimiter is a close delimiter- Returns:
- the next InterfaceHttpData if any
- Throws:
HttpPostRequestDecoder.ErrorDataDecoderException
-
findMultipartDisposition
private InterfaceHttpData findMultipartDisposition() throws HttpPostRequestDecoder.ErrorDataDecoderException
Find the next Disposition- Returns:
- the next InterfaceHttpData if any
- Throws:
HttpPostRequestDecoder.ErrorDataDecoderException
-
getFileUpload
private InterfaceHttpData getFileUpload(java.lang.String delimiter) throws HttpPostRequestDecoder.ErrorDataDecoderException
Get the FileUpload (new one or current one)- Parameters:
delimiter
- the delimiter to use- Returns:
- the InterfaceHttpData if any
- Throws:
HttpPostRequestDecoder.ErrorDataDecoderException
-
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
-
cleanMixedAttributes
private void cleanMixedAttributes()
Remove all Attributes that should be cleaned between two FileUpload in Mixed mode
-
readLineStandard
private java.lang.String readLineStandard() throws HttpPostRequestDecoder.NotEnoughDataDecoderException
Read one line up to the CRLF or LF- Returns:
- the String from one line
- Throws:
HttpPostRequestDecoder.NotEnoughDataDecoderException
- Need more chunks and reset the readerInder to the previous value
-
readLine
private java.lang.String readLine() throws HttpPostRequestDecoder.NotEnoughDataDecoderException
Read one line up to the CRLF or LF- Returns:
- the String from one line
- Throws:
HttpPostRequestDecoder.NotEnoughDataDecoderException
- Need more chunks and reset the readerInder to the previous value
-
readDelimiterStandard
private java.lang.String readDelimiterStandard(java.lang.String delimiter) throws HttpPostRequestDecoder.NotEnoughDataDecoderException
Read one line up to --delimiter or --delimiter-- and if existing the CRLF or LF Read one line up to --delimiter or --delimiter-- and if existing the CRLF or LF. Note that CRLF or LF are mandatory for opening delimiter (--delimiter) but not for closing delimiter (--delimiter--) since some clients does not include CRLF in this case.- Parameters:
delimiter
- of the form --string, such that '--' is already included- Returns:
- the String from one line as the delimiter searched (opening or closing)
- Throws:
HttpPostRequestDecoder.NotEnoughDataDecoderException
- Need more chunks and reset the readerInder to the previous value
-
readDelimiter
private java.lang.String readDelimiter(java.lang.String delimiter) throws HttpPostRequestDecoder.NotEnoughDataDecoderException
Read one line up to --delimiter or --delimiter-- and if existing the CRLF or LF. Note that CRLF or LF are mandatory for opening delimiter (--delimiter) but not for closing delimiter (--delimiter--) since some clients does not include CRLF in this case.- Parameters:
delimiter
- of the form --string, such that '--' is already included- Returns:
- the String from one line as the delimiter searched (opening or closing)
- Throws:
HttpPostRequestDecoder.NotEnoughDataDecoderException
- Need more chunks and reset the readerInder to the previous value
-
readFileUploadByteMultipartStandard
private void readFileUploadByteMultipartStandard(java.lang.String delimiter) throws HttpPostRequestDecoder.NotEnoughDataDecoderException, HttpPostRequestDecoder.ErrorDataDecoderException
Read a FileUpload data as Byte (Binary) and add the bytes directly to the FileUpload. If the delimiter is found, the FileUpload is completed.- Throws:
HttpPostRequestDecoder.NotEnoughDataDecoderException
- Need more chunks but do not reset the readerInder since some values will be already added to the FileOutputHttpPostRequestDecoder.ErrorDataDecoderException
- write IO error occurs with the FileUpload
-
readFileUploadByteMultipart
private void readFileUploadByteMultipart(java.lang.String delimiter) throws HttpPostRequestDecoder.NotEnoughDataDecoderException, HttpPostRequestDecoder.ErrorDataDecoderException
Read a FileUpload data as Byte (Binary) and add the bytes directly to the FileUpload. If the delimiter is found, the FileUpload is completed.- Throws:
HttpPostRequestDecoder.NotEnoughDataDecoderException
- Need more chunks but do not reset the readerInder since some values will be already added to the FileOutputHttpPostRequestDecoder.ErrorDataDecoderException
- write IO error occurs with the FileUpload
-
loadFieldMultipartStandard
private void loadFieldMultipartStandard(java.lang.String delimiter) throws HttpPostRequestDecoder.NotEnoughDataDecoderException, HttpPostRequestDecoder.ErrorDataDecoderException
Load the field value from a Multipart request- Throws:
HttpPostRequestDecoder.NotEnoughDataDecoderException
- Need more chunksHttpPostRequestDecoder.ErrorDataDecoderException
-
loadFieldMultipart
private void loadFieldMultipart(java.lang.String delimiter) throws HttpPostRequestDecoder.NotEnoughDataDecoderException, HttpPostRequestDecoder.ErrorDataDecoderException
Load the field value from a Multipart request- Throws:
HttpPostRequestDecoder.NotEnoughDataDecoderException
- Need more chunksHttpPostRequestDecoder.ErrorDataDecoderException
-
cleanString
private static java.lang.String cleanString(java.lang.String field)
Clean the String from any unallowed character- Returns:
- the cleaned String
-
skipOneLine
private boolean skipOneLine()
Skip one empty line- Returns:
- True if one empty line was skipped
-
splitMultipartHeader
private static java.lang.String[] splitMultipartHeader(java.lang.String sb)
Split one header in Multipart- Returns:
- an array of String where rank 0 is the name of the header, follows by several values that were separated by ';' or ','
-
splitMultipartHeaderValues
private static java.lang.String[] splitMultipartHeaderValues(java.lang.String svalue)
Split one header value in Multipart.- Returns:
- an array of
String
where values that were separated by ';' or ','
-
-