public class HttpPostRequestEncoder extends Object implements ChunkedInput<HttpContent>
According to RFC 7231, POST, PUT and OPTIONS allow to have a body. This encoder will support widely all methods except TRACE since the RFC notes for GET, DELETE, HEAD and CONNECT: (replaces XXX by one of these methods)
"A payload within a XXX request message has no defined semantics; sending a payload body on a XXX request might cause some existing implementations to reject the request."
On the contrary, for TRACE method, RFC says:
"A client MUST NOT send a message body in a TRACE request."
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
|
Constructor and Description |
---|
HttpPostRequestEncoder(HttpDataFactory factory,
HttpRequest request,
boolean multipart) |
HttpPostRequestEncoder(HttpDataFactory factory,
HttpRequest request,
boolean multipart,
Charset charset,
HttpPostRequestEncoder.EncoderMode encoderMode) |
HttpPostRequestEncoder(HttpRequest request,
boolean multipart) |
Modifier and Type | Method and Description |
---|---|
void |
addBodyAttribute(String name,
String value)
Add a simple attribute in the body as Name=Value
|
void |
addBodyFileUpload(String name,
File file,
String contentType,
boolean isText)
Add a file as a FileUpload
|
void |
addBodyFileUpload(String name,
String filename,
File file,
String contentType,
boolean isText)
Add a file as a FileUpload
|
void |
addBodyFileUploads(String name,
File[] file,
String[] contentType,
boolean[] isText)
Add a series of Files associated with one File parameter
|
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.
|
HttpRequest |
finalizeRequest()
Finalize the request by preparing the Header in the request and returns the request ready to be sent.
|
List<InterfaceHttpData> |
getBodyListAttributes()
This getMethod returns a List of all InterfaceHttpData from body part.
|
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
|
long |
length()
Returns the length of the input.
|
long |
progress()
Returns current transfer progress.
|
HttpContent |
readChunk(ByteBufAllocator allocator)
Returns the next available HttpChunk.
|
HttpContent |
readChunk(ChannelHandlerContext ctx)
Deprecated.
|
void |
setBodyHttpDatas(List<InterfaceHttpData> datas)
Set the Body HttpDatas list
|
public HttpPostRequestEncoder(HttpRequest request, boolean multipart) throws HttpPostRequestEncoder.ErrorDataEncoderException
request
- the request to encodemultipart
- True if the FORM is a ENCTYPE="multipart/form-data"NullPointerException
- for requestHttpPostRequestEncoder.ErrorDataEncoderException
- if the request is a TRACEpublic 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"NullPointerException
- for request and factoryHttpPostRequestEncoder.ErrorDataEncoderException
- if the request is a TRACEpublic HttpPostRequestEncoder(HttpDataFactory factory, HttpRequest request, boolean multipart, 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.NullPointerException
- for request or charset or factoryHttpPostRequestEncoder.ErrorDataEncoderException
- if the request is a TRACEpublic void cleanFiles()
public boolean isMultipart()
public List<InterfaceHttpData> getBodyListAttributes()
public void setBodyHttpDatas(List<InterfaceHttpData> datas) throws HttpPostRequestEncoder.ErrorDataEncoderException
NullPointerException
- for datasHttpPostRequestEncoder.ErrorDataEncoderException
- if the encoding is in error or if the finalize were already donepublic void addBodyAttribute(String name, String value) throws HttpPostRequestEncoder.ErrorDataEncoderException
name
- name of the parametervalue
- the value of the parameterNullPointerException
- for nameHttpPostRequestEncoder.ErrorDataEncoderException
- if the encoding is in error or if the finalize were already donepublic void addBodyFileUpload(String name, File file, 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)NullPointerException
- for name and fileHttpPostRequestEncoder.ErrorDataEncoderException
- if the encoding is in error or if the finalize were already donepublic void addBodyFileUpload(String name, String filename, File file, 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)filename
- the filename to use for this File part, empty String will be ignored by
the encodercontentType
- the associated contentType for the FileisText
- True if this file should be transmitted in Text format (else binary)NullPointerException
- for name and fileHttpPostRequestEncoder.ErrorDataEncoderException
- if the encoding is in error or if the finalize were already donepublic void addBodyFileUploads(String name, File[] file, 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 fileIllegalArgumentException
- 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
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()
public void close() throws Exception
ChunkedInput
close
in interface ChunkedInput<HttpContent>
Exception
@Deprecated public HttpContent readChunk(ChannelHandlerContext ctx) throws Exception
readChunk
in interface ChunkedInput<HttpContent>
ctx
- The context which provides a ByteBufAllocator
if buffer allocation is necessary.null
if there is no data left in the stream.
Please note that null
does not necessarily mean that the
stream has reached at its end. In a slow stream, the next chunk
might be unavailable just momentarily.Exception
public HttpContent readChunk(ByteBufAllocator allocator) throws Exception
readChunk
in interface ChunkedInput<HttpContent>
allocator
- ByteBufAllocator
if buffer allocation is necessary.HttpPostRequestEncoder.ErrorDataEncoderException
- if the encoding is in errorException
public boolean isEndOfInput() throws 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>
Exception
public long length()
ChunkedInput
length
in interface ChunkedInput<HttpContent>
public long progress()
ChunkedInput
progress
in interface ChunkedInput<HttpContent>
Copyright © 2008–2024 The Netty Project. All rights reserved.