Class HttpResponseResult

java.lang.Object
org.apache.pekko.http.javadsl.HttpResponseResult

public final class HttpResponseResult extends Object
The outcome of sending a request through a connection pool flow: either the HttpResponse or the failure that prevented one from being received.

Emitted by the *WithResult connection pool flows of Http as a Java-friendly alternative to scala.util.Try.

Since:
2.0.0
  • Constructor Details

    • HttpResponseResult

      public HttpResponseResult()
  • Method Details

    • success

      public static HttpResponseResult success(HttpResponse response)
      Creates a successful result holding the given response.
    • failure

      public static HttpResponseResult failure(Throwable failure)
      Creates a failed result holding the given failure.
    • fromTry

      public static HttpResponseResult fromTry(scala.util.Try<HttpResponse> result)
      INTERNAL API
    • isSuccess

      public boolean isSuccess()
      Returns `true` if a response was received.
    • isFailure

      public boolean isFailure()
      Returns `true` if no response was received because of a failure.
    • getResponse

      public HttpResponse getResponse()
      Returns the response.

      Returns:
      (undocumented)
      Throws:
      IllegalStateException - if this result is a failure; the failure is attached as the cause
    • getFailure

      public Throwable getFailure()
      Returns the failure.

      Returns:
      (undocumented)
      Throws:
      IllegalStateException - if this result is a success
    • fold

      public <R> R fold(org.apache.pekko.japi.function.Function<HttpResponse,R> onSuccess, org.apache.pekko.japi.function.Function<Throwable,R> onFailure)
      Applies onSuccess to the response if this result is a success, otherwise applies onFailure to the failure. Exceptions thrown by either function are rethrown to the caller.
      Parameters:
      onSuccess - (undocumented)
      onFailure - (undocumented)
      Returns:
      (undocumented)
    • handle

      public <R> R handle(org.apache.pekko.japi.function.Function2<HttpResponse,Throwable,R> f)
      Like CompletionStage.handle, applies f to the response and a null failure if this result is a success, or to a null response and the failure otherwise. Exceptions thrown by f are rethrown to the caller.
      Parameters:
      f - (undocumented)
      Returns:
      (undocumented)
    • equals

      public boolean equals(Object other)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object