Interface HttpClientResponse


public interface HttpClientResponse
Controls how the response is processed including potential conversion into beans.
  • Method Details

    • read

      <T> T read​(BodyReader<T> reader)
      Returning the response using the given response reader.
      Type Parameters:
      T - The type that the content is converted to.
      Parameters:
      reader - The response reader.
      Returns:
      The response converted into the appropriate bean via the reader.
      Throws:
      HttpException - when the response has error status codes
    • bean

      <T> T bean​(Class<T> type)
      Return the response as a single bean.
      Type Parameters:
      T - The type that the content is converted to.
      Parameters:
      type - The type of the bean to convert the response content into.
      Returns:
      The bean the response is converted into.
      Throws:
      HttpException - when the response has error status codes
    • list

      <T> List<T> list​(Class<T> type)
      Return the response as a list of beans.
      Type Parameters:
      T - The type that the content is converted to.
      Parameters:
      type - The type of the bean to convert the response content into.
      Returns:
      The list of beans the response is converted into.
      Throws:
      HttpException - when the response has error status codes
    • stream

      <T> Stream<T> stream​(Class<T> type)
      Return the response as a stream of beans.

      Typically the response is expected to be applciation/x-json-stream newline delimited json payload.

      Type Parameters:
      T - The type that the content is converted to.
      Parameters:
      type - The type of the bean to convert the response content into.
      Returns:
      The stream of beans from the response
      Throws:
      HttpException - when the response has error status codes
    • asVoid

      HttpResponse<Void> asVoid()
      Return the response with check for 200 range status code.

      Will throw an HttpException if the status code is in the error range allowing the caller to access the error message body via HttpException.bean(Class)

      This is intended to be used for POST, PUT, DELETE requests where the caller is only interested in the response body when an error occurs (status code not in 200 range).

      Throws:
      HttpException - when the response has error status codes
    • asString

      HttpResponse<String> asString()
      Return the content as string.
    • asDiscarding

      HttpResponse<Void> asDiscarding()
      Return the response discarding the response content.
    • asInputStream

      HttpResponse<InputStream> asInputStream()
      Return the content as InputStream.
    • asLines

      Return the content as a stream of string lines.
    • asByteArray

      HttpResponse<byte[]> asByteArray()
      Return the content as byte array.
    • asFile

      HttpResponse<Path> asFile​(Path file)
      Return the content into the given file.
    • withResponseHandler

      <T> HttpResponse<T> withResponseHandler​(HttpResponse.BodyHandler<T> responseHandler)
      Return the response using the given response body handler.