Class HttpResponse
-
- All Implemented Interfaces:
-
java.io.Closeable,java.lang.AutoCloseable
public abstract class HttpResponse implements Closeable
The type representing response of HttpRequest.
The body of the HttpResponse is backed by an HTTP connection, the Http connections are limited resources. It is important to close the response body to avoid leaking of backing connection and associated resource, such leaking may ultimately cause the application to slow down or crash.
HttpResponse implements Closeable, invoking Closeable.close will close the response body. The body must be closed by calling one of the following methods:
HttpResponse::close()
HttpResponse::getBodyAsByteArray()
HttpResponse::getBodyAsString()
HttpResponse::getBodyAsString(Charset)
-
-
Field Summary
Fields Modifier and Type Field Description private final HttpRequestrequestprivate final IntegerstatusCodeprivate final HttpHeadersheaders
-
Constructor Summary
Constructors Constructor Description HttpResponse(HttpRequest request, Integer statusCode, HttpHeaders headers)Constructs a new HttpResponse instance.
-
Method Summary
Modifier and Type Method Description HttpRequestgetRequest()the http request. IntegergetStatusCode()the HTTP response status code. HttpHeadersgetHeaders()the headers of HTTP response. abstract ByteArraygetBodyAsByteArray()Returns the response content as a ByteArray final StringgetBodyAsString(Charset charset)Returns the response content as a String final StringgetHeaderValue(String name)Lookups a response header with the provided name. final BooleanisSuccessful()Gets whether response was successful. -
-
Constructor Detail
-
HttpResponse
HttpResponse(HttpRequest request, Integer statusCode, HttpHeaders headers)
Constructs a new HttpResponse instance.
-
-
Method Detail
-
getRequest
HttpRequest getRequest()
the http request.
-
getStatusCode
Integer getStatusCode()
the HTTP response status code.
-
getHeaders
HttpHeaders getHeaders()
the headers of HTTP response.
-
getBodyAsByteArray
abstract ByteArray getBodyAsByteArray()
Returns the response content as a ByteArray
-
getBodyAsString
final String getBodyAsString(Charset charset)
Returns the response content as a String
-
getHeaderValue
final String getHeaderValue(String name)
Lookups a response header with the provided name.
- Parameters:
name- The name of the header to lookup- Returns:
The value of the header, or {@code null} if the header doesn't exist in the response
-
isSuccessful
final Boolean isSuccessful()
Gets whether response was successful.
- Returns:
{@code true} if response was successful, {@code false} otherwise
-
-
-
-