Class HttpClientResponse<T>

java.lang.Object
dev.galasa.http.HttpClientResponse<T>
Type Parameters:
T - Class describing the content type of the response

public class HttpClientResponse<T> extends Object
Parametrisable representation of a response to an HTTP request. The parameter describes the content type of the response. Use the static methods to create instances from an HttpResponse.
Author:
James Bartlett
  • Method Details

    • getStatusCode

      public int getStatusCode()
      Returns:
      - status code of the response
    • getStatusMessage

      public String getStatusMessage()
      Returns:
      - reason phrase or status message of the response
    • getProtocolVersion

      public String getProtocolVersion()
      Returns:
      - protocol version string of the response
    • getStatusLine

      public String getStatusLine()
      Returns:
      - full status line
    • getContent

      public T getContent()
      Returns:
      - the content of the response
    • getHeader

      public Object getHeader(String header)
      Get the value of a specific header as a String. May be null
      Parameters:
      header -
      Returns:
      - the value of the header
    • getheaders

      public Map<String,String> getheaders()
      Get all headers from the response
      Returns:
      - map of headers and values
    • byteResponse

      public static HttpClientResponse<byte[]> byteResponse(org.apache.http.client.methods.CloseableHttpResponse httpResponse) throws HttpClientException
      Create an HttpClientResponse with a byte array content type from an HttpResponse.
      Parameters:
      httpResponse -
      Returns:
      - HttpClientResponse with a byte array content type
      Throws:
      HttpClientException
    • byteResponse

      public static HttpClientResponse<byte[]> byteResponse(org.apache.http.client.methods.CloseableHttpResponse httpResponse, boolean contentOnBadResponse) throws HttpClientException
      Create an HttpClientResponse with a byte array content type from an HttpResponse. If contentOnBadResponse is true, an attempt will be made to retrieve the content even on a non 200 status code, otherwise the content will be null in such an instance.
      Parameters:
      httpResponse -
      contentOnBadResponse -
      Returns:
      - HttpClientResponse with a byte array content type
      Throws:
      HttpClientException
    • textResponse

      public static HttpClientResponse<String> textResponse(org.apache.http.client.methods.CloseableHttpResponse httpResponse) throws HttpClientException
      Create an HttpClientResponse with a String content type from an HttpResponse.
      Parameters:
      httpResponse -
      Returns:
      - HttpClientResponse with a String content type
      Throws:
      HttpClientException
    • textResponse

      public static HttpClientResponse<String> textResponse(org.apache.http.client.methods.CloseableHttpResponse httpResponse, boolean contentOnBadResponse) throws HttpClientException
      Create an HttpClientResponse with a String content type from an HttpResponse. If contentOnBadResponse is true, an attempt will be made to retrieve the content even on a non 200 status code, otherwise the content will be null in such an instance.
      Parameters:
      httpResponse -
      contentOnBadResponse -
      Returns:
      - HttpClientResponse with a String content type
      Throws:
      HttpClientException
    • jsonResponse

      public static HttpClientResponse<com.google.gson.JsonObject> jsonResponse(org.apache.http.client.methods.CloseableHttpResponse httpResponse) throws HttpClientException
      Create an HttpClientResponse with a
      invalid @link
      JSONObject
      content type from an HttpResponse.
      Parameters:
      httpResponse -
      Returns:
      - HttpClientResponse with a
      invalid @link
      JSONObject
      content type
      Throws:
      HttpClientException
    • jsonResponse

      public static HttpClientResponse<com.google.gson.JsonObject> jsonResponse(org.apache.http.client.methods.CloseableHttpResponse httpResponse, boolean contentOnBadResponse) throws HttpClientException
      Create an HttpClientResponse with a
      invalid @link
      JSONObject
      content type from an HttpResponse. If contentOnBadResponse is true, an attempt will be made to retrieve the content even on a non 200 status code, otherwise the content will be null in such an instance.
      Parameters:
      httpResponse -
      contentOnBadResponse -
      Returns:
      - HttpClientResponse with a
      invalid @link
      JSONObject
      content type
      Throws:
      HttpClientException
    • xmlResponse

      public static HttpClientResponse<Document> xmlResponse(org.apache.http.client.methods.CloseableHttpResponse httpResponse) throws HttpClientException
      Create an HttpClientResponse with a Document content type from an HttpResponse.
      Parameters:
      httpResponse -
      Returns:
      - HttpClientResponse with a Document content type
      Throws:
      HttpClientException
    • xmlResponse

      public static HttpClientResponse<Document> xmlResponse(org.apache.http.client.methods.CloseableHttpResponse httpResponse, boolean contentOnBadResponse) throws HttpClientException
      Create an HttpClientResponse with a Document content type from an HttpResponse. If contentOnBadResponse is true, an attempt will be made to retrieve the content even on a non 200 status code, otherwise the content will be null in such an instance.
      Parameters:
      httpResponse -
      contentOnBadResponse -
      Returns:
      - HttpClientResponse with a Document content type
      Throws:
      HttpClientException
    • jaxbResponse

      public static HttpClientResponse<Object> jaxbResponse(org.apache.http.client.methods.CloseableHttpResponse httpResponse, Class<?>... responseTypes) throws HttpClientException
      Create an HttpClientResponse with an Object content type from an HttpResponse. The object returned will be an instance of one of the JAXB classes provided in responseTypes. If the response did not contain a status code 200 (OK), the content will be null.
      Parameters:
      httpResponse -
      responseTypes -
      Returns:
      - HttpClientResponse with an Object content type
      Throws:
      HttpClientException
    • jaxbResponse

      public static HttpClientResponse<Object> jaxbResponse(org.apache.http.client.methods.CloseableHttpResponse httpResponse, boolean contentOnBadResponse, Class<?>... responseTypes) throws HttpClientException
      Create an HttpClientResponse with an Object content type from an HttpResponse. The object returned will be an instance of one of the JAXB classes provided in responseTypes. If contentOnBadResponse is true, an attempt will be made to retrieve the content even on a non 200 status code, otherwise the content will be null in such an instance.
      Parameters:
      httpResponse -
      contentOnBadResponse -
      responseTypes -
      Returns:
      - HttpClientResponse with an Object content type
      Throws:
      HttpClientException