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 of HttpPostRequestEncoder that 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."

  • Field Details

    • WAIT_MARKER

      public static final io.netty.handler.codec.http.HttpContent WAIT_MARKER
  • Constructor Details

  • 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

      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 datas
      PausableHttpPostRequestEncoder.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 parameter
      value - the value of the parameter
      Throws:
      NullPointerException - for name
      PausableHttpPostRequestEncoder.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 parameter
      file - the file to be uploaded (if not Multipart mode, only the filename will be included)
      contentType - the associated contentType for the File
      isText - True if this file should be transmitted in Text format (else binary)
      Throws:
      NullPointerException - for name and file
      PausableHttpPostRequestEncoder.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 parameter
      file - 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 encoder
      contentType - the associated contentType for the File
      isText - True if this file should be transmitted in Text format (else binary)
      Throws:
      NullPointerException - for name and file
      PausableHttpPostRequestEncoder.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 parameter
      file - the array of files
      contentType - the array of content Types associated with each file
      isText - the array of isText attribute (False meaning binary mode) for each file
      Throws:
      IllegalArgumentException - also throws if array have different sizes
      PausableHttpPostRequestEncoder.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.ErrorDataEncoderException
      Add the InterfaceHttpData to the Body list
      Throws:
      NullPointerException - for data
      PausableHttpPostRequestEncoder.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.ErrorDataEncoderException
      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:
      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:
      close in interface io.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:
      readChunk in interface io.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 Exception
      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 getMethod.
      Specified by:
      readChunk in interface io.netty.handler.stream.ChunkedInput<io.netty.handler.codec.http.HttpContent>
      Returns:
      the next available HttpChunk
      Throws:
      PausableHttpPostRequestEncoder.ErrorDataEncoderException - if the encoding is in error
      Exception
    • isEndOfInput

      public boolean isEndOfInput()
      Specified by:
      isEndOfInput in interface io.netty.handler.stream.ChunkedInput<io.netty.handler.codec.http.HttpContent>
    • length

      public long length()
      Specified by:
      length in interface io.netty.handler.stream.ChunkedInput<io.netty.handler.codec.http.HttpContent>
    • progress

      public long progress()
      Specified by:
      progress in interface io.netty.handler.stream.ChunkedInput<io.netty.handler.codec.http.HttpContent>