Interface HttpEntity

All Known Subinterfaces:
FeedableHttpEntity

@Experimental @NoImplement @MinMuleVersion("4.10.0") public interface HttpEntity
An entity that can be sent or received via an HttpRequest or HttpResponse.

There are three distinct types of entities, depending on their content:

  • streamed: The content is received from a stream.
  • composed: The content is made of several parts.
  • neither of the above: The content is in memory and whole.
These will determine how the content can be accessed, although there may overlap.
Since:
0.12.0
  • Method Details

    • isStreaming

      boolean isStreaming()
      Tells whether this entity's content is stream-based. Streamed entities can only provide their content once, regardless of the access method.
      Returns:
      true if content is streamed, false otherwise
      See Also:
    • getContent

      InputStream getContent()
      Provides the entity's content as a stream. All streaming entities should provide their stream.
      Returns:
      an InputStream representing this entity's content or null if such representation is not possible
    • getBytes

      byte[] getBytes() throws IOException
      Provides the entity's content as bytes. If the entity is stream based, then the stream will be consumed as a consequence.
      Returns:
      a byte array representing this entity's content or null if such representation is not possible
      Throws:
      IOException - if an error occurs creating the byte array
    • getBytesLength

      OptionalLong getBytesLength()
      Provides the length (in bytes) of the HttpEntity, if known. For the most part, only received entities from HTTP messages that carried a 'Content-Length' header will return a length.
      Returns:
      an Optional with the length (in bytes) or an empty one if unknown
    • onComplete

      default void onComplete(BiConsumer<? super org.mule.runtime.api.util.MultiMap<String,String>,? super Throwable> completionCallback)
      To be called when the trailers are received, or when we know that we aren't going to receive any trailers. In that case, the parameter of the consumer will be an empty MultiMap. For example, for HTTP/1 messages, we know that we will never receive trailers, so this callback will be preemptively invoked.
      Parameters:
      completionCallback - callback to be invoked.
      Since:
      0.13.0
    • onData

      default EntitySubscription onData(Consumer<ByteBuffer> dataConsumer)
      Handle each fragment of data.
      Parameters:
      dataConsumer - callback to be executed for each data fragment seen in the entity.
      Returns:
      a EntitySubscription object that can be used to cancel the reactive consumption of the entity.
      Throws:
      UnsupportedOperationException - if the implementation doesn't support reactive consumption.
      Since:
      0.13.0
    • isReactive

      default boolean isReactive()
      Returns:
      whether this entity supports consuming data fragments reactively, by using onData(Consumer)
      Since:
      0.13.0
      See Also: