public class HttpPostRequestEncoder extends java.lang.Object implements ChunkedInput<HttpContent>
Modifier and Type | Class and Description |
---|---|
static class |
HttpPostRequestEncoder.EncoderMode
Different modes to use to encode form data.
|
static class |
HttpPostRequestEncoder.ErrorDataEncoderException
Exception when an error occurs while encoding
|
private static class |
HttpPostRequestEncoder.WrappedFullHttpRequest |
private static class |
HttpPostRequestEncoder.WrappedHttpRequest |
Modifier and Type | Field and Description |
---|---|
private java.util.List<InterfaceHttpData> |
bodyListDatas
InterfaceHttpData for Body (without encoding)
|
private java.nio.charset.Charset |
charset
Default charset to use
|
private ByteBuf |
currentBuffer
The ByteBuf currently used by the encoder
|
private InterfaceHttpData |
currentData
The current InterfaceHttpData to encode (used if more chunks are available)
|
private FileUpload |
currentFileUpload
The current FileUpload that is currently in encode process
|
private boolean |
duringMixedMode
While adding a FileUpload, is the multipart currently in Mixed Mode
|
private HttpPostRequestEncoder.EncoderMode |
encoderMode |
private HttpDataFactory |
factory
Factory used to create InterfaceHttpData
|
private long |
globalBodySize
Global Body size
|
private boolean |
headerFinalized
To check if the header has been finalized
|
private boolean |
isChunked
Chunked false by default
|
private boolean |
isKey
If not multipart, does the currentBuffer stands for the Key or for the Value
|
private boolean |
isLastChunk
Does the last non empty chunk already encoded so that next chunk will be empty (last chunk)
|
private boolean |
isLastChunkSent
Last chunk already sent
|
private boolean |
isMultipart
Does this request is a Multipart request
|
private java.util.ListIterator<InterfaceHttpData> |
iterator
Iterator to be used when encoding will be called chunk after chunk
|
(package private) java.lang.String |
multipartDataBoundary
If multipart, this is the boundary for the flobal multipart
|
(package private) java.util.List<InterfaceHttpData> |
multipartHttpDatas
The final Multipart List of InterfaceHttpData including encoding
|
(package private) java.lang.String |
multipartMixedBoundary
If multipart, there could be internal multiparts (mixed) to the global multipart.
|
private static java.util.Map<java.util.regex.Pattern,java.lang.String> |
percentEncodings |
private HttpRequest |
request
Request to encode
|
Constructor and Description |
---|
HttpPostRequestEncoder(HttpDataFactory factory,
HttpRequest request,
boolean multipart) |
HttpPostRequestEncoder(HttpDataFactory factory,
HttpRequest request,
boolean multipart,
java.nio.charset.Charset charset,
HttpPostRequestEncoder.EncoderMode encoderMode) |
HttpPostRequestEncoder(HttpRequest request,
boolean multipart) |
Modifier and Type | Method and Description |
---|---|
void |
addBodyAttribute(java.lang.String name,
java.lang.String value)
Add a simple attribute in the body as Name=Value
|
void |
addBodyFileUpload(java.lang.String name,
java.io.File file,
java.lang.String contentType,
boolean isText)
Add a file as a FileUpload
|
void |
addBodyFileUploads(java.lang.String name,
java.io.File[] file,
java.lang.String[] contentType,
boolean[] isText)
Add a series of Files associated with one File parameter (implied Mixed mode in Multipart)
|
void |
addBodyHttpData(InterfaceHttpData data)
Add the InterfaceHttpData to the Body list
|
void |
cleanFiles()
Clean all HttpDatas (on Disk) for the current request.
|
void |
close()
Releases the resources associated with the input.
|
private java.lang.String |
encodeAttribute(java.lang.String s,
java.nio.charset.Charset charset)
Encode one attribute
|
private HttpContent |
encodeNextChunkMultipart(int sizeleft)
From the current context (currentBuffer and currentData), returns the next HttpChunk (if possible) trying to get
sizeleft bytes more into the currentBuffer.
|
private HttpContent |
encodeNextChunkUrlEncoded(int sizeleft)
From the current context (currentBuffer and currentData), returns the next HttpChunk (if possible) trying to get
sizeleft bytes more into the currentBuffer.
|
private ByteBuf |
fillByteBuf() |
HttpRequest |
finalizeRequest()
Finalize the request by preparing the Header in the request and returns the request ready to be sent.
Once finalized, no data must be added. If the request does not need chunk (isChunked() == false), this request is the only object to send to the remote server. |
java.util.List<InterfaceHttpData> |
getBodyListAttributes()
This getMethod returns a List of all InterfaceHttpData from body part.
|
private static java.lang.String |
getNewMultipartDelimiter() |
private void |
initDataMultipart()
Init the delimiter for Global Part (Data).
|
private void |
initMixedMultipart()
Init the delimiter for Mixed Part (Mixed).
|
boolean |
isChunked() |
boolean |
isEndOfInput()
Return
true if and only if there is no data left in the stream
and the stream has reached at its end. |
boolean |
isMultipart()
True if this request is a Multipart request
|
private HttpContent |
nextChunk()
Returns the next available HttpChunk.
|
HttpContent |
readChunk(ChannelHandlerContext ctx)
Returns the next available HttpChunk.
|
void |
setBodyHttpDatas(java.util.List<InterfaceHttpData> datas)
Set the Body HttpDatas list
|
private static final java.util.Map<java.util.regex.Pattern,java.lang.String> percentEncodings
private final HttpDataFactory factory
private final HttpRequest request
private final java.nio.charset.Charset charset
private boolean isChunked
private final java.util.List<InterfaceHttpData> bodyListDatas
final java.util.List<InterfaceHttpData> multipartHttpDatas
private final boolean isMultipart
java.lang.String multipartDataBoundary
java.lang.String multipartMixedBoundary
private boolean headerFinalized
private final HttpPostRequestEncoder.EncoderMode encoderMode
private boolean isLastChunk
private boolean isLastChunkSent
private FileUpload currentFileUpload
private boolean duringMixedMode
private long globalBodySize
private java.util.ListIterator<InterfaceHttpData> iterator
private ByteBuf currentBuffer
private InterfaceHttpData currentData
private boolean isKey
public HttpPostRequestEncoder(HttpRequest request, boolean multipart) throws HttpPostRequestEncoder.ErrorDataEncoderException
request
- the request to encodemultipart
- True if the FORM is a ENCTYPE="multipart/form-data"java.lang.NullPointerException
- for requestHttpPostRequestEncoder.ErrorDataEncoderException
- if the request is not a POSTpublic HttpPostRequestEncoder(HttpDataFactory factory, HttpRequest request, boolean multipart) throws HttpPostRequestEncoder.ErrorDataEncoderException
factory
- the factory used to create InterfaceHttpDatarequest
- the request to encodemultipart
- True if the FORM is a ENCTYPE="multipart/form-data"java.lang.NullPointerException
- for request and factoryHttpPostRequestEncoder.ErrorDataEncoderException
- if the request is not a POSTpublic HttpPostRequestEncoder(HttpDataFactory factory, HttpRequest request, boolean multipart, java.nio.charset.Charset charset, HttpPostRequestEncoder.EncoderMode encoderMode) throws HttpPostRequestEncoder.ErrorDataEncoderException
factory
- the factory used to create InterfaceHttpDatarequest
- the request to encodemultipart
- True if the FORM is a ENCTYPE="multipart/form-data"charset
- the charset to use as defaultencoderMode
- the mode for the encoder to use. See HttpPostRequestEncoder.EncoderMode
for the details.java.lang.NullPointerException
- for request or charset or factoryHttpPostRequestEncoder.ErrorDataEncoderException
- if the request is not a POSTpublic void cleanFiles()
public boolean isMultipart()
private void initDataMultipart()
private void initMixedMultipart()
private static java.lang.String getNewMultipartDelimiter()
public java.util.List<InterfaceHttpData> getBodyListAttributes()
public void setBodyHttpDatas(java.util.List<InterfaceHttpData> datas) throws HttpPostRequestEncoder.ErrorDataEncoderException
java.lang.NullPointerException
- for datasHttpPostRequestEncoder.ErrorDataEncoderException
- if the encoding is in error or if the finalize were already donepublic void addBodyAttribute(java.lang.String name, java.lang.String value) throws HttpPostRequestEncoder.ErrorDataEncoderException
name
- name of the parametervalue
- the value of the parameterjava.lang.NullPointerException
- for nameHttpPostRequestEncoder.ErrorDataEncoderException
- if the encoding is in error or if the finalize were already donepublic void addBodyFileUpload(java.lang.String name, java.io.File file, java.lang.String contentType, boolean isText) throws HttpPostRequestEncoder.ErrorDataEncoderException
name
- the name of the parameterfile
- the file to be uploaded (if not Multipart mode, only the filename will be included)contentType
- the associated contentType for the FileisText
- True if this file should be transmitted in Text format (else binary)java.lang.NullPointerException
- for name and fileHttpPostRequestEncoder.ErrorDataEncoderException
- if the encoding is in error or if the finalize were already donepublic void addBodyFileUploads(java.lang.String name, java.io.File[] file, java.lang.String[] contentType, boolean[] isText) throws HttpPostRequestEncoder.ErrorDataEncoderException
name
- the name of the parameterfile
- the array of filescontentType
- the array of content Types associated with each fileisText
- the array of isText attribute (False meaning binary mode) for each filejava.lang.NullPointerException
- also throws if array have different sizesHttpPostRequestEncoder.ErrorDataEncoderException
- if the encoding is in error or if the finalize were already donepublic void addBodyHttpData(InterfaceHttpData data) throws HttpPostRequestEncoder.ErrorDataEncoderException
java.lang.NullPointerException
- for dataHttpPostRequestEncoder.ErrorDataEncoderException
- if the encoding is in error or if the finalize were already donepublic HttpRequest finalizeRequest() throws HttpPostRequestEncoder.ErrorDataEncoderException
HttpPostRequestEncoder.ErrorDataEncoderException
- if the encoding is in error or if the finalize were already donepublic boolean isChunked()
private java.lang.String encodeAttribute(java.lang.String s, java.nio.charset.Charset charset) throws HttpPostRequestEncoder.ErrorDataEncoderException
HttpPostRequestEncoder.ErrorDataEncoderException
- if the encoding is in errorprivate ByteBuf fillByteBuf()
private HttpContent encodeNextChunkMultipart(int sizeleft) throws HttpPostRequestEncoder.ErrorDataEncoderException
sizeleft
- the number of bytes to try to get from currentDataHttpPostRequestEncoder.ErrorDataEncoderException
- if the encoding is in errorprivate HttpContent encodeNextChunkUrlEncoded(int sizeleft) throws HttpPostRequestEncoder.ErrorDataEncoderException
sizeleft
- the number of bytes to try to get from currentDataHttpPostRequestEncoder.ErrorDataEncoderException
- if the encoding is in errorpublic void close() throws java.lang.Exception
ChunkedInput
close
in interface ChunkedInput<HttpContent>
java.lang.Exception
public HttpContent readChunk(ChannelHandlerContext ctx) throws java.lang.Exception
readChunk
in interface ChunkedInput<HttpContent>
HttpPostRequestEncoder.ErrorDataEncoderException
- if the encoding is in errorjava.lang.Exception
private HttpContent nextChunk() throws HttpPostRequestEncoder.ErrorDataEncoderException
HttpPostRequestEncoder.ErrorDataEncoderException
- if the encoding is in errorpublic boolean isEndOfInput() throws java.lang.Exception
ChunkedInput
true
if and only if there is no data left in the stream
and the stream has reached at its end.isEndOfInput
in interface ChunkedInput<HttpContent>
java.lang.Exception