Interface HttpResponse


public interface HttpResponse
A server's response to a HTTP request.
  • Method Details

    • statusCode

      int statusCode()
      Returns:
      the status code for this response
    • request

      HttpRequest request()
      Returns:
      the HttpRequest for this response
    • uri

      URI uri()
      Returns the URI that the response was received from. This may be different from the request URI if redirection occurred.
      Returns:
      the URI of the response
    • body

      <T> T body(HttpResponse.BodyProcessor<T> processor)
      Returns the body of this response, as processed by the passed HttpResponse.BodyProcessor.
      Type Parameters:
      T - the type of the returned body object
      Parameters:
      processor - the processor to handle the response body
      Returns:
      the body of this response, as an instance of type T
      Throws:
      UncheckedIOException - if an I/O error occurs reading the response
    • headers

      HttpHeaders headers()
      Returns:
      the received response headers
    • ignoreBody

      static HttpResponse.BodyProcessor<Void> ignoreBody()
      Returns:
      a HttpResponse.BodyProcessor<byte[]> which ignores the response body and closes the connection.
    • asByteArray

      static HttpResponse.BodyProcessor<byte[]> asByteArray()
      Returns:
      a HttpResponse.BodyProcessor<byte[]> which returns the response body as a byte array.
    • asString

      static HttpResponse.BodyProcessor<String> asString()
      Returns a response processor which decodes the body using the character set specified in the Content-Type response header. If there is no such header, or the character set is not supported, then UTF-8 is used.
      Returns:
      a HttpResponse.BodyProcessor<String> which returns the response body as a String.
    • asJsonObject

      static HttpResponse.BodyProcessor<Map<String,Object>> asJsonObject(Json jsonService)
      Returns a response processor which decodes a JSON body using the character set specified in the Content-Type response header. If there is no such header, or the character set is not supported, then UTF-8 is used. If the Content-Type response header exists and is not compatible with JSON, a RuntimeException is thrown when the response is processed.
      Parameters:
      jsonService - the Json service to use to parse the message body
      Returns:
      a HttpResponse.BodyProcessor<Map<String, Object>> which returns the response body as a Map.
      Since:
      4.0.0