Package dev.galasa.http
Class HttpClientResponse<T>
java.lang.Object
dev.galasa.http.HttpClientResponse<T>
- Type Parameters:
T- Class describing the content type of the response
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.-
Method Summary
Modifier and TypeMethodDescriptionstatic HttpClientResponse<byte[]>byteResponse(org.apache.http.client.methods.CloseableHttpResponse httpResponse) Create anHttpClientResponsewith a byte array content type from anHttpResponse.static HttpClientResponse<byte[]>byteResponse(org.apache.http.client.methods.CloseableHttpResponse httpResponse, boolean contentOnBadResponse) Create anHttpClientResponsewith a byte array content type from anHttpResponse.Get the value of a specific header as a String.Get all headers from the responseintstatic HttpClientResponse<Object>jaxbResponse(org.apache.http.client.methods.CloseableHttpResponse httpResponse, boolean contentOnBadResponse, Class<?>... responseTypes) static HttpClientResponse<Object>jaxbResponse(org.apache.http.client.methods.CloseableHttpResponse httpResponse, Class<?>... responseTypes) static HttpClientResponse<com.google.gson.JsonObject>jsonResponse(org.apache.http.client.methods.CloseableHttpResponse httpResponse) Create anHttpClientResponsewith a com.google.gson.JsonObject content type from anHttpResponse.static HttpClientResponse<com.google.gson.JsonObject>jsonResponse(org.apache.http.client.methods.CloseableHttpResponse httpResponse, boolean contentOnBadResponse) Create anHttpClientResponsewith a com.google.gson.JsonObject content type from anHttpResponse.static HttpClientResponse<String>textResponse(org.apache.http.client.methods.CloseableHttpResponse httpResponse) static HttpClientResponse<String>textResponse(org.apache.http.client.methods.CloseableHttpResponse httpResponse, boolean contentOnBadResponse) static HttpClientResponse<Document>xmlResponse(org.apache.http.client.methods.CloseableHttpResponse httpResponse) static HttpClientResponse<Document>xmlResponse(org.apache.http.client.methods.CloseableHttpResponse httpResponse, boolean contentOnBadResponse)
-
Method Details
-
getStatusCode
public int getStatusCode()- Returns:
- - status code of the response
-
getStatusMessage
- Returns:
- - reason phrase or status message of the response
-
getProtocolVersion
- Returns:
- - protocol version string of the response
-
getStatusLine
- Returns:
- - full status line
-
getContent
- Returns:
- - the content of the response
-
getHeader
Get the value of a specific header as a String. May be null- Parameters:
header-- Returns:
- - the value of the header
-
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 anHttpClientResponsewith a byte array content type from anHttpResponse.- Parameters:
httpResponse-- Returns:
- -
HttpClientResponsewith 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 anHttpClientResponsewith a byte array content type from anHttpResponse. 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:
- -
HttpClientResponsewith a byte array content type - Throws:
HttpClientException
-
textResponse
public static HttpClientResponse<String> textResponse(org.apache.http.client.methods.CloseableHttpResponse httpResponse) throws HttpClientException - Parameters:
httpResponse-- Returns:
- -
HttpClientResponsewith aStringcontent type - Throws:
HttpClientException
-
textResponse
public static HttpClientResponse<String> textResponse(org.apache.http.client.methods.CloseableHttpResponse httpResponse, boolean contentOnBadResponse) throws HttpClientException Create anHttpClientResponsewith aStringcontent type from anHttpResponse. 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:
- -
HttpClientResponsewith aStringcontent type - Throws:
HttpClientException
-
jsonResponse
public static HttpClientResponse<com.google.gson.JsonObject> jsonResponse(org.apache.http.client.methods.CloseableHttpResponse httpResponse) throws HttpClientException Create anHttpClientResponsewith a com.google.gson.JsonObject content type from anHttpResponse.- Parameters:
httpResponse-- Returns:
- -
HttpClientResponsewith a com.google.gson.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 anHttpClientResponsewith a com.google.gson.JsonObject content type from anHttpResponse. 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:
- -
HttpClientResponsewith a com.google.gson.JsonObject content type - Throws:
HttpClientException
-
xmlResponse
public static HttpClientResponse<Document> xmlResponse(org.apache.http.client.methods.CloseableHttpResponse httpResponse) throws HttpClientException - Parameters:
httpResponse-- Returns:
- -
HttpClientResponsewith aDocumentcontent type - Throws:
HttpClientException
-
xmlResponse
public static HttpClientResponse<Document> xmlResponse(org.apache.http.client.methods.CloseableHttpResponse httpResponse, boolean contentOnBadResponse) throws HttpClientException Create anHttpClientResponsewith aDocumentcontent type from anHttpResponse. 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:
- -
HttpClientResponsewith aDocumentcontent type - Throws:
HttpClientException
-
jaxbResponse
public static HttpClientResponse<Object> jaxbResponse(org.apache.http.client.methods.CloseableHttpResponse httpResponse, Class<?>... responseTypes) throws HttpClientException Create anHttpClientResponsewith anObjectcontent type from anHttpResponse. 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:
- -
HttpClientResponsewith anObjectcontent type - Throws:
HttpClientException
-
jaxbResponse
public static HttpClientResponse<Object> jaxbResponse(org.apache.http.client.methods.CloseableHttpResponse httpResponse, boolean contentOnBadResponse, Class<?>... responseTypes) throws HttpClientException Create anHttpClientResponsewith anObjectcontent type from anHttpResponse. 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:
- -
HttpClientResponsewith anObjectcontent type - Throws:
HttpClientException
-