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
- Direct Known Subclasses:
HttpFileResponse
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.hc.core5.http.ClassicHttpResponse httpResponse) Create anHttpClientResponsewith a byte array content type from anHttpResponse.static HttpClientResponse<byte[]>byteResponse(org.apache.hc.core5.http.ClassicHttpResponse 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.hc.core5.http.ClassicHttpResponse httpResponse, boolean contentOnBadResponse, Class<?>... responseTypes) static HttpClientResponse<Object>jaxbResponse(org.apache.hc.core5.http.ClassicHttpResponse httpResponse, Class<?>... responseTypes) static HttpClientResponse<Object>jaxbResponse(org.apache.http.client.methods.CloseableHttpResponse httpResponse, boolean contentOnBadResponse, Class<?>... responseTypes) Deprecated.This method uses the deprecated Apache HttpClient 4 API (CloseableHttpResponse).static HttpClientResponse<Object>jaxbResponse(org.apache.http.client.methods.CloseableHttpResponse httpResponse, Class<?>... responseTypes) Deprecated.This method uses the deprecated Apache HttpClient 4 API (CloseableHttpResponse).static HttpClientResponse<com.google.gson.JsonObject>jsonResponse(org.apache.hc.core5.http.ClassicHttpResponse httpResponse) Create anHttpClientResponsewith a com.google.gson.JsonObject content type from anHttpResponse.static HttpClientResponse<com.google.gson.JsonObject>jsonResponse(org.apache.hc.core5.http.ClassicHttpResponse httpResponse, boolean contentOnBadResponse) 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) Deprecated.This method uses the deprecated Apache HttpClient 4 API (CloseableHttpResponse).static HttpClientResponse<com.google.gson.JsonObject>jsonResponse(org.apache.http.client.methods.CloseableHttpResponse httpResponse, boolean contentOnBadResponse) Deprecated.This method uses the deprecated Apache HttpClient 4 API (CloseableHttpResponse).protected voidpopulateGenericValues(org.apache.hc.core5.http.HttpResponse httpResponse) protected voidpopulateGenericValues(org.apache.http.client.methods.CloseableHttpResponse httpResponse) Deprecated.This method uses the deprecated Apache HttpClient 4 API.protected voidsetContent(T content) static HttpClientResponse<String>textResponse(org.apache.hc.core5.http.ClassicHttpResponse httpResponse) static HttpClientResponse<String>textResponse(org.apache.hc.core5.http.ClassicHttpResponse httpResponse, boolean contentOnBadResponse) static HttpClientResponse<Document>xmlResponse(org.apache.hc.core5.http.ClassicHttpResponse httpResponse) static HttpClientResponse<Document>xmlResponse(org.apache.hc.core5.http.ClassicHttpResponse httpResponse, boolean contentOnBadResponse) static HttpClientResponse<Document>xmlResponse(org.apache.http.client.methods.CloseableHttpResponse httpResponse) Deprecated.This method uses the deprecated Apache HttpClient 4 API (CloseableHttpResponse).static HttpClientResponse<Document>xmlResponse(org.apache.http.client.methods.CloseableHttpResponse httpResponse, boolean contentOnBadResponse) Deprecated.This method uses the deprecated Apache HttpClient 4 API (CloseableHttpResponse).
-
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
-
setContent
-
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
-
populateGenericValues
protected void populateGenericValues(org.apache.hc.core5.http.HttpResponse httpResponse) -
byteResponse
public static HttpClientResponse<byte[]> byteResponse(org.apache.hc.core5.http.ClassicHttpResponse 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.hc.core5.http.ClassicHttpResponse 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.hc.core5.http.ClassicHttpResponse httpResponse) throws HttpClientException - Parameters:
httpResponse-- Returns:
- -
HttpClientResponsewith aStringcontent type - Throws:
HttpClientException
-
textResponse
public static HttpClientResponse<String> textResponse(org.apache.hc.core5.http.ClassicHttpResponse 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.hc.core5.http.ClassicHttpResponse 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.hc.core5.http.ClassicHttpResponse 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.hc.core5.http.ClassicHttpResponse httpResponse) throws HttpClientException - Parameters:
httpResponse-- Returns:
- -
HttpClientResponsewith aDocumentcontent type - Throws:
HttpClientException
-
xmlResponse
public static HttpClientResponse<Document> xmlResponse(org.apache.hc.core5.http.ClassicHttpResponse 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.hc.core5.http.ClassicHttpResponse 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.hc.core5.http.ClassicHttpResponse 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
-
populateGenericValues
@Deprecated protected void populateGenericValues(org.apache.http.client.methods.CloseableHttpResponse httpResponse) Deprecated.This method uses the deprecated Apache HttpClient 4 API. It will be removed in a future release. Internal use only. -
jsonResponse
@Deprecated public static HttpClientResponse<com.google.gson.JsonObject> jsonResponse(org.apache.http.client.methods.CloseableHttpResponse httpResponse) throws HttpClientException Deprecated.This method uses the deprecated Apache HttpClient 4 API (CloseableHttpResponse). Use the overloaded method that accepts ClassicHttpResponse instead. This method will be removed in a future release.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
@Deprecated public static HttpClientResponse<com.google.gson.JsonObject> jsonResponse(org.apache.http.client.methods.CloseableHttpResponse httpResponse, boolean contentOnBadResponse) throws HttpClientException Deprecated.This method uses the deprecated Apache HttpClient 4 API (CloseableHttpResponse). Use the overloaded method that accepts ClassicHttpResponse instead. This method will be removed in a future release.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
@Deprecated public static HttpClientResponse<Document> xmlResponse(org.apache.http.client.methods.CloseableHttpResponse httpResponse) throws HttpClientException Deprecated.This method uses the deprecated Apache HttpClient 4 API (CloseableHttpResponse). Use the overloaded method that accepts ClassicHttpResponse instead. This method will be removed in a future release.- Parameters:
httpResponse-- Returns:
- -
HttpClientResponsewith aDocumentcontent type - Throws:
HttpClientException
-
xmlResponse
@Deprecated public static HttpClientResponse<Document> xmlResponse(org.apache.http.client.methods.CloseableHttpResponse httpResponse, boolean contentOnBadResponse) throws HttpClientException Deprecated.This method uses the deprecated Apache HttpClient 4 API (CloseableHttpResponse). Use the overloaded method that accepts ClassicHttpResponse instead. This method will be removed in a future release.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
@Deprecated public static HttpClientResponse<Object> jaxbResponse(org.apache.http.client.methods.CloseableHttpResponse httpResponse, Class<?>... responseTypes) throws HttpClientException Deprecated.This method uses the deprecated Apache HttpClient 4 API (CloseableHttpResponse). Use the overloaded method that accepts ClassicHttpResponse instead. This method will be removed in a future release.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
@Deprecated public static HttpClientResponse<Object> jaxbResponse(org.apache.http.client.methods.CloseableHttpResponse httpResponse, boolean contentOnBadResponse, Class<?>... responseTypes) throws HttpClientException Deprecated.This method uses the deprecated Apache HttpClient 4 API (CloseableHttpResponse). Use the overloaded method that accepts ClassicHttpResponse instead. This method will be removed in a future release.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
-