Class ResponseHandler<T>

java.lang.Object
com.mastfrog.netty.http.client.ResponseHandler<T>

public abstract class ResponseHandler<T> extends Object
Processes an HTTP response - can be passed to HttpRequestBuilder.execute(). Altenately, you can listen for individual events on the ResponseFuture. Override one of the receive() methods to get responses.

Basic types and JSON unmarshalling with Jackson are supported out-of-the-box. To do anything else, override internalReceive.

In the case of a response code greater than 399, the onErrorResponse will be called with the raw bytes.

Author:
Tim Boudreau
  • Constructor Details

    • ResponseHandler

      public ResponseHandler(Class<T> type, NettyContentMarshallers marshallers)
    • ResponseHandler

      public ResponseHandler(Class<T> type, com.fasterxml.jackson.databind.ObjectMapper mapper)
    • ResponseHandler

      public ResponseHandler(Class<T> type)
  • Method Details

    • await

      public void await() throws InterruptedException
      Throws:
      InterruptedException
    • await

      public boolean await(long l, TimeUnit tu) throws InterruptedException
      Throws:
      InterruptedException
    • internalReceive

      protected void internalReceive(io.netty.handler.codec.http.HttpResponseStatus status, io.netty.handler.codec.http.HttpHeaders headers, io.netty.buffer.ByteBuf content)
    • receive

      protected void receive(io.netty.handler.codec.http.HttpResponseStatus status, T obj)
    • receive

      protected void receive(io.netty.handler.codec.http.HttpResponseStatus status, io.netty.handler.codec.http.HttpHeaders headers, T obj)
    • receive

      protected void receive(T obj)
    • onErrorResponse

      protected void onErrorResponse(String content)
    • onErrorResponse

      protected void onErrorResponse(io.netty.handler.codec.http.HttpResponseStatus status, String content)
    • onErrorResponse

      protected void onErrorResponse(io.netty.handler.codec.http.HttpResponseStatus status, io.netty.handler.codec.http.HttpHeaders headers, String content)
    • onError

      protected void onError(Throwable err)
    • type

      public Class<T> type()