Class HttpPostRequestEncoder
java.lang.Object
org.jboss.netty.handler.codec.http.multipart.HttpPostRequestEncoder
- All Implemented Interfaces:
ChunkedInput
This encoder will help to encode Request for a FORM as POST.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumDifferent modes to use to encode form data.static classException when an error occurs while encoding -
Constructor Summary
ConstructorsConstructorDescriptionHttpPostRequestEncoder(HttpRequest request, boolean multipart) HttpPostRequestEncoder(HttpDataFactory factory, HttpRequest request, boolean multipart) HttpPostRequestEncoder(HttpDataFactory factory, HttpRequest request, boolean multipart, Charset charset) HttpPostRequestEncoder(HttpDataFactory factory, HttpRequest request, boolean multipart, Charset charset, HttpPostRequestEncoder.EncoderMode encoderMode) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddBodyAttribute(String name, String value) Add a simple attribute in the body as Name=ValuevoidaddBodyFileUpload(String name, File file, String contentType, boolean isText) Add a file as a FileUploadvoidaddBodyFileUploads(String name, File[] file, String[] contentType, boolean[] isText) Add a series of Files associated with one File parametervoidAdd the InterfaceHttpData to the Body listvoidClean all HttpDatas (on Disk) for the current request.voidclose()Releases the resources associated with the stream.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.This method returns a List of all InterfaceHttpData from body part.booleanReturnstrueif and only if there is any data left in the stream.booleanbooleanReturntrueif and only if there is no data left in the stream and the stream has reached at its end.booleanTrue if this request is a Multipart requestReturns the next available HttpChunk.voidsetBodyHttpDatas(List<InterfaceHttpData> datas) Set the Body HttpDatas list
-
Constructor Details
-
HttpPostRequestEncoder
public HttpPostRequestEncoder(HttpRequest request, boolean multipart) throws HttpPostRequestEncoder.ErrorDataEncoderException - Parameters:
request- the request to encodemultipart- True if the FORM is a ENCTYPE="multipart/form-data"- Throws:
NullPointerException- for requestHttpPostRequestEncoder.ErrorDataEncoderException- if the request is not a POST
-
HttpPostRequestEncoder
public HttpPostRequestEncoder(HttpDataFactory factory, HttpRequest request, boolean multipart) throws HttpPostRequestEncoder.ErrorDataEncoderException - Parameters:
factory- the factory used to create InterfaceHttpDatarequest- the request to encodemultipart- True if the FORM is a ENCTYPE="multipart/form-data"- Throws:
NullPointerException- for request and factoryHttpPostRequestEncoder.ErrorDataEncoderException- if the request is not a POST
-
HttpPostRequestEncoder
public HttpPostRequestEncoder(HttpDataFactory factory, HttpRequest request, boolean multipart, Charset charset) throws HttpPostRequestEncoder.ErrorDataEncoderException - Parameters:
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 default- Throws:
NullPointerException- for request or charset or factoryHttpPostRequestEncoder.ErrorDataEncoderException- if the request is not a POST
-
HttpPostRequestEncoder
public HttpPostRequestEncoder(HttpDataFactory factory, HttpRequest request, boolean multipart, Charset charset, HttpPostRequestEncoder.EncoderMode encoderMode) throws HttpPostRequestEncoder.ErrorDataEncoderException - Parameters:
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 default + @param encoderMode the mode for the encoder to use. SeeHttpPostRequestEncoder.EncoderModefor the details.- Throws:
NullPointerException- for request or charset or factoryHttpPostRequestEncoder.ErrorDataEncoderException- if the request is not a POST
-
-
Method Details
-
cleanFiles
public void cleanFiles()Clean all HttpDatas (on Disk) for the current request. -
isMultipart
public boolean isMultipart()True if this request is a Multipart request- Returns:
- True if this request is a Multipart request
-
getBodyListAttributes
This method returns a List of all InterfaceHttpData from body part.- Returns:
- the list of InterfaceHttpData from Body part
-
setBodyHttpDatas
public void setBodyHttpDatas(List<InterfaceHttpData> datas) throws HttpPostRequestEncoder.ErrorDataEncoderException Set the Body HttpDatas list- Throws:
NullPointerException- for datasHttpPostRequestEncoder.ErrorDataEncoderException- if the encoding is in error or if the finalize were already done
-
addBodyAttribute
public void addBodyAttribute(String name, String value) throws HttpPostRequestEncoder.ErrorDataEncoderException Add a simple attribute in the body as Name=Value- Parameters:
name- name of the parametervalue- the value of the parameter- Throws:
NullPointerException- for nameHttpPostRequestEncoder.ErrorDataEncoderException- if the encoding is in error or if the finalize were already done
-
addBodyFileUpload
public void addBodyFileUpload(String name, File file, String contentType, boolean isText) throws HttpPostRequestEncoder.ErrorDataEncoderException Add a file as a FileUpload- Parameters:
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)- Throws:
NullPointerException- for name and fileHttpPostRequestEncoder.ErrorDataEncoderException- if the encoding is in error or if the finalize were already done
-
addBodyFileUploads
public void addBodyFileUploads(String name, File[] file, String[] contentType, boolean[] isText) throws HttpPostRequestEncoder.ErrorDataEncoderException Add a series of Files associated with one File parameter- Parameters:
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 file- Throws:
NullPointerException- also throws if array have different sizesHttpPostRequestEncoder.ErrorDataEncoderException- if the encoding is in error or if the finalize were already done
-
addBodyHttpData
public void addBodyHttpData(InterfaceHttpData data) throws HttpPostRequestEncoder.ErrorDataEncoderException Add the InterfaceHttpData to the Body list- Throws:
NullPointerException- for dataHttpPostRequestEncoder.ErrorDataEncoderException- if the encoding is in error or if the finalize were already done
-
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.- Returns:
- the request object (chunked or not according to size of body)
- Throws:
HttpPostRequestEncoder.ErrorDataEncoderException- if the encoding is in error or if the finalize were already done
-
isChunked
public boolean isChunked()- Returns:
- True if the request is by Chunk
-
close
Description copied from interface:ChunkedInputReleases the resources associated with the stream.- Specified by:
closein interfaceChunkedInput- Throws:
Exception
-
nextChunk
Returns the next available HttpChunk. The caller is responsible to test if this chunk is the last one (isLast()), in order to stop calling this method.- Specified by:
nextChunkin interfaceChunkedInput- Returns:
- the next available HttpChunk
- Throws:
HttpPostRequestEncoder.ErrorDataEncoderException- if the encoding is in error
-
isEndOfInput
Description copied from interface:ChunkedInputReturntrueif and only if there is no data left in the stream and the stream has reached at its end.- Specified by:
isEndOfInputin interfaceChunkedInput- Throws:
Exception
-
hasNextChunk
Description copied from interface:ChunkedInputReturnstrueif and only if there is any data left in the stream. Please note thatfalsedoes not necessarily mean that the stream has reached at its end. In a slow stream, the next chunk might be unavailable just momentarily.- Specified by:
hasNextChunkin interfaceChunkedInput- Throws:
Exception
-