Class HttpPostMultipartRequestDecoder
java.lang.Object
org.jboss.netty.handler.codec.http.multipart.HttpPostMultipartRequestDecoder
- All Implemented Interfaces:
InterfaceHttpPostRequestDecoder
public class HttpPostMultipartRequestDecoder
extends Object
implements InterfaceHttpPostRequestDecoder
This decoder will decode Body and can handle POST BODY in multipart form.
-
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 Charset
Default charset to useprivate Attribute
The current Attribute that is currently in decode processUsed in Multipartprivate FileUpload
The current FileUpload that is currently in decode processCurrent statusprivate final HttpDataFactory
Factory used to create InterfaceHttpDataprivate boolean
Does the last chunk already receivedprivate String
If multipart, this is the boundary for the flobal multipartprivate String
If multipart, there could be internal multiparts (mixed) to the global multipart.private final HttpRequest
Request to decodeprivate ChannelBuffer
The current channelBuffer -
Constructor Summary
ConstructorsConstructorDescriptionHttpPostMultipartRequestDecoder
(HttpDataFactory factory, HttpRequest request) HttpPostMultipartRequestDecoder
(HttpDataFactory factory, HttpRequest request, Charset charset) -
Method Summary
Modifier and TypeMethodDescriptionprivate void
addHttpData
(InterfaceHttpData data) Utility function to add a new decoded datavoid
Clean all HttpDatas (on Disk) for the current request.private void
Remove all Attributes that should be cleaned between two FileUpload in Mixed modeprivate static String
cleanString
(String field) Clean the String from any unallowed characterprivate InterfaceHttpData
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
(String delimiter, HttpPostRequestDecoder.MultiPartStatus dispositionStatus, HttpPostRequestDecoder.MultiPartStatus closeDelimiterStatus) Find the next Multipart Delimiterprivate InterfaceHttpData
Find the next DispositiongetBodyHttpData
(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.This method returns a List of all HttpDatas from body.
If chunked, all chunks must have been offered using offer() method.getBodyHttpDatas
(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
(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
True if this request is a Multipart requestprivate void
loadFieldMultipart
(String delimiter) Load the field value from a Multipart requestprivate void
loadFieldMultipartStandard
(String delimiter) Load the field value from a Multipart requestnext()
Returns the next available InterfaceHttpData or null if, at the time it is called, there is no more available InterfaceHttpData.void
Initialized the internals from a new chunkprivate void
This method will parse as much as possible data and fill the list and mapprivate void
Parse the Body for multipartprivate String
readDelimiter
(String delimiter) Read one line up to --delimiter or --delimiter-- and if existing the CRLF or LF.private String
readDelimiterStandard
(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
(String delimiter) Read a FileUpload data as Byte (Binary) and add the bytes directly to the FileUpload.private void
readFileUploadByteMultipartStandard
(String delimiter) Read a FileUpload data as Byte (Binary) and add the bytes directly to the FileUpload.private String
readLine()
Read one line up to the CRLF or LFprivate String
Read one line up to the CRLF or LFvoid
Remove the given FileUpload from the list of FileUploads to cleanprivate void
setMultipart
(String contentType) Set from the request ContentType the multipartDataBoundary and the possible charset.(package private) void
Skip control Characters(package private) void
private boolean
Skip one empty lineprivate static String[]
Split one header in Multipartprivate static String[]
splitMultipartHeaderValues
(String svalue) Split one header value in Multipart.
-
Field Details
-
factory
Factory used to create InterfaceHttpData -
request
Request to decode -
charset
Default charset to use -
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 -
multipartDataBoundary
If multipart, this is the boundary for the flobal multipart -
multipartMixedBoundary
If multipart, there could be internal multiparts (mixed) to the global multipart. Only one level is allowed. -
currentStatus
Current status -
currentFieldAttributes
Used in Multipart -
currentFileUpload
The current FileUpload that is currently in decode process -
currentAttribute
The current Attribute that is currently in decode process
-
-
Constructor Details
-
HttpPostMultipartRequestDecoder
public HttpPostMultipartRequestDecoder(HttpRequest request) throws HttpPostRequestDecoder.ErrorDataDecoderException - Parameters:
request
- the request to decode- Throws:
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:
NullPointerException
- for request or factoryHttpPostRequestDecoder.ErrorDataDecoderException
- if the default charset was wrong when decoding or other errors
-
HttpPostMultipartRequestDecoder
public HttpPostMultipartRequestDecoder(HttpDataFactory factory, HttpRequest request, Charset charset) throws HttpPostRequestDecoder.ErrorDataDecoderException - 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
-
-
Method Details
-
setMultipart
private void setMultipart(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 List<InterfaceHttpData> getBodyHttpDatas() throws HttpPostRequestDecoder.NotEnoughDataDecoderExceptionDescription 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 List<InterfaceHttpData> getBodyHttpDatas(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(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
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
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
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
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
Utility function to add a new decoded data -
parseBodyMultipart
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
Skip control Characters -
skipControlCharactersStandard
void skipControlCharactersStandard() -
findMultipartDelimiter
private InterfaceHttpData findMultipartDelimiter(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.ErrorDataDecoderExceptionFind the next Disposition- Returns:
- the next InterfaceHttpData if any
- Throws:
HttpPostRequestDecoder.ErrorDataDecoderException
-
getFileUpload
private InterfaceHttpData getFileUpload(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
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
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
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 String readDelimiterStandard(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 String readDelimiter(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(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(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(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(String delimiter) throws HttpPostRequestDecoder.NotEnoughDataDecoderException, HttpPostRequestDecoder.ErrorDataDecoderException Load the field value from a Multipart request- Throws:
HttpPostRequestDecoder.NotEnoughDataDecoderException
- Need more chunksHttpPostRequestDecoder.ErrorDataDecoderException
-
cleanString
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
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
Split one header value in Multipart.- Returns:
- an array of
String
where values that were separated by ';' or ','
-