Class RequestContentAdapter

All Implemented Interfaces:
EventListener, Request.Content, Request.Content.Subscription, AsyncContentProvider.Listener, Callback, Invocable

public class RequestContentAdapter extends Object implements Request.Content, Request.Content.Subscription, AsyncContentProvider.Listener, Callback

Implements the conversion from ContentProvider to Request.Content.

  • Constructor Details

    • RequestContentAdapter

      public RequestContentAdapter(ContentProvider provider)
  • Method Details

    • getContentProvider

      public ContentProvider getContentProvider()
    • getContentType

      public String getContentType()
      Specified by:
      getContentType in interface Request.Content
      the content type string such as "application/octet-stream" or "application/json;charset=UTF8", or null if no content type must be set
    • getLength

      public long getLength()
      Specified by:
      getLength in interface Request.Content
      the content length, if known, or -1 if the content length is unknown
    • isReproducible

      public boolean isReproducible()
      Description copied from interface: Request.Content

      Whether this content producer can produce exactly the same content more than once.

      Implementations should return true only if the content can be produced more than once, which means that Request.Content.subscribe(Consumer, boolean) may be called again.

      The HttpClient implementation may use this method in particular cases where it detects that it is safe to retry a request that failed.

      Specified by:
      isReproducible in interface Request.Content
      whether the content can be produced more than once
    • subscribe

      public Request.Content.Subscription subscribe(Request.Content.Consumer consumer, boolean emitInitialContent)
      Description copied from interface: Request.Content

      Initializes this content producer with the content consumer, and with the indication of whether initial content, if present, must be emitted upon the initial demand of content (to support delaying the send of the request content in case of Expect: 100-Continue when emitInitialContent is false).

      Specified by:
      subscribe in interface Request.Content
      consumer - the content consumer to invoke when there is demand for content
      emitInitialContent - whether to emit initial content, if present
      the Subscription that links this producer to the consumer
    • demand

      public void demand()
      Description copied from interface: Request.Content.Subscription

      Demands more content, which eventually results in Request.Content.Consumer.onContent(ByteBuffer, boolean, Callback) to be invoked.

      Specified by:
      demand in interface Request.Content.Subscription
    • fail

      public void fail(Throwable failure)
      Description copied from interface: Request.Content

      Fails this request content, possibly failing and discarding accumulated content that was not demanded.

      The failure may be notified to the consumer at a later time, when the consumer demands for content.

      Typical failure: the request being aborted by user code, or idle timeouts.

      Specified by:
      fail in interface Request.Content
      Specified by:
      fail in interface Request.Content.Subscription
      failure - the reason of the failure
    • onContent

      public void onContent()
      Description copied from interface: AsyncContentProvider.Listener
      Callback method invoked when content is available
      Specified by:
      onContent in interface AsyncContentProvider.Listener
    • succeeded

      public void succeeded()
      Description copied from interface: Callback

      Callback invoked when the operation completes.

      Specified by:
      succeeded in interface Callback
      See Also:
    • failed

      public void failed(Throwable x)
      Description copied from interface: Callback

      Callback invoked when the operation fails.

      Specified by:
      failed in interface Callback
      x - the reason for the operation failure
    • getInvocationType

      public Invocable.InvocationType getInvocationType()
      Specified by:
      getInvocationType in interface Invocable
      The InvocationType of this object
    • toString

      public String toString()
      toString in class Object