Class PausableHttpPostRequestEncoder
- java.lang.Object
-
- org.jboss.resteasy.reactive.client.impl.multipart.PausableHttpPostRequestEncoder
-
- All Implemented Interfaces:
io.netty.handler.stream.ChunkedInput<io.netty.handler.codec.http.HttpContent>
public class PausableHttpPostRequestEncoder extends Object implements io.netty.handler.stream.ChunkedInput<io.netty.handler.codec.http.HttpContent>
A copy ofHttpPostRequestEncoderthat supports pause/resume This encoder will help to encode Request for a FORM as POST.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."
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classPausableHttpPostRequestEncoder.EncoderModeDifferent modes to use to encode form data.static classPausableHttpPostRequestEncoder.ErrorDataEncoderExceptionException when an error occurs while encoding
-
Field Summary
Fields Modifier and Type Field Description static io.netty.handler.codec.http.HttpContentWAIT_MARKER
-
Constructor Summary
Constructors Constructor Description PausableHttpPostRequestEncoder(io.netty.handler.codec.http.multipart.HttpDataFactory factory, io.netty.handler.codec.http.HttpRequest request, boolean multipart, Charset charset, PausableHttpPostRequestEncoder.EncoderMode encoderMode)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddBodyAttribute(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 FileUploadvoidaddBodyFileUpload(String name, String filename, 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 parametervoidaddBodyHttpData(io.netty.handler.codec.http.multipart.InterfaceHttpData data)Add the InterfaceHttpData to the Body listvoidcleanFiles()Clean all HttpDatas (on Disk) for the current request.voidclose()io.netty.handler.codec.http.HttpRequestfinalizeRequest()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.List<io.netty.handler.codec.http.multipart.InterfaceHttpData>getBodyListAttributes()This getMethod returns a List of all InterfaceHttpData from body part.booleanisChunked()booleanisEndOfInput()booleanisMultipart()True if this request is a Multipart requestlonglength()longprogress()io.netty.handler.codec.http.HttpContentreadChunk(io.netty.buffer.ByteBufAllocator allocator)Returns the next available HttpChunk.io.netty.handler.codec.http.HttpContentreadChunk(io.netty.channel.ChannelHandlerContext ctx)Deprecated.voidsetBodyHttpDatas(List<io.netty.handler.codec.http.multipart.InterfaceHttpData> datas)Set the Body HttpDatas list
-
-
-
Constructor Detail
-
PausableHttpPostRequestEncoder
public PausableHttpPostRequestEncoder(io.netty.handler.codec.http.multipart.HttpDataFactory factory, io.netty.handler.codec.http.HttpRequest request, boolean multipart, Charset charset, PausableHttpPostRequestEncoder.EncoderMode encoderMode) throws PausableHttpPostRequestEncoder.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 defaultencoderMode- the mode for the encoder to use. SeePausableHttpPostRequestEncoder.EncoderModefor the details.- Throws:
NullPointerException- for request or charset or factoryPausableHttpPostRequestEncoder.ErrorDataEncoderException- if the request is a TRACE
-
-
Method Detail
-
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
public List<io.netty.handler.codec.http.multipart.InterfaceHttpData> getBodyListAttributes()
This getMethod returns a List of all InterfaceHttpData from body part.- Returns:
- the list of InterfaceHttpData from Body part
-
setBodyHttpDatas
public void setBodyHttpDatas(List<io.netty.handler.codec.http.multipart.InterfaceHttpData> datas) throws PausableHttpPostRequestEncoder.ErrorDataEncoderException
Set the Body HttpDatas list- Throws:
NullPointerException- for datasPausableHttpPostRequestEncoder.ErrorDataEncoderException- if the encoding is in error or if the finalize were already done
-
addBodyAttribute
public void addBodyAttribute(String name, String value) throws PausableHttpPostRequestEncoder.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 namePausableHttpPostRequestEncoder.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 PausableHttpPostRequestEncoder.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 filePausableHttpPostRequestEncoder.ErrorDataEncoderException- if the encoding is in error or if the finalize were already done
-
addBodyFileUpload
public void addBodyFileUpload(String name, String filename, File file, String contentType, boolean isText) throws PausableHttpPostRequestEncoder.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)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)- Throws:
NullPointerException- for name and filePausableHttpPostRequestEncoder.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 PausableHttpPostRequestEncoder.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:
IllegalArgumentException- also throws if array have different sizesPausableHttpPostRequestEncoder.ErrorDataEncoderException- if the encoding is in error or if the finalize were already done
-
addBodyHttpData
public void addBodyHttpData(io.netty.handler.codec.http.multipart.InterfaceHttpData data) throws PausableHttpPostRequestEncoder.ErrorDataEncoderExceptionAdd the InterfaceHttpData to the Body list- Throws:
NullPointerException- for dataPausableHttpPostRequestEncoder.ErrorDataEncoderException- if the encoding is in error or if the finalize were already done
-
finalizeRequest
public io.netty.handler.codec.http.HttpRequest finalizeRequest() throws PausableHttpPostRequestEncoder.ErrorDataEncoderExceptionFinalize 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:
PausableHttpPostRequestEncoder.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
public void close() throws Exception- Specified by:
closein interfaceio.netty.handler.stream.ChunkedInput<io.netty.handler.codec.http.HttpContent>- Throws:
Exception
-
readChunk
@Deprecated public io.netty.handler.codec.http.HttpContent readChunk(io.netty.channel.ChannelHandlerContext ctx) throws Exception
Deprecated.- Specified by:
readChunkin interfaceio.netty.handler.stream.ChunkedInput<io.netty.handler.codec.http.HttpContent>- Throws:
Exception
-
readChunk
public io.netty.handler.codec.http.HttpContent readChunk(io.netty.buffer.ByteBufAllocator allocator) throws ExceptionReturns the next available HttpChunk. The caller is responsible to test if this chunk is the last one (isLast()), in order to stop calling this getMethod.- Specified by:
readChunkin interfaceio.netty.handler.stream.ChunkedInput<io.netty.handler.codec.http.HttpContent>- Returns:
- the next available HttpChunk
- Throws:
PausableHttpPostRequestEncoder.ErrorDataEncoderException- if the encoding is in errorException
-
isEndOfInput
public boolean isEndOfInput()
- Specified by:
isEndOfInputin interfaceio.netty.handler.stream.ChunkedInput<io.netty.handler.codec.http.HttpContent>
-
length
public long length()
- Specified by:
lengthin interfaceio.netty.handler.stream.ChunkedInput<io.netty.handler.codec.http.HttpContent>
-
progress
public long progress()
- Specified by:
progressin interfaceio.netty.handler.stream.ChunkedInput<io.netty.handler.codec.http.HttpContent>
-
-