IMPORTANT: No additional bug fixes or documentation updates
will be released for this version. For the latest information, see the
current release documentation.
Reading responses
edit
IMPORTANT: This documentation is no longer updated. Refer to Elastic's version policy and the latest documentation.
Reading responses
editThe Response object, either returned by the synchronous performRequest methods or
received as an argument in ResponseListener#onSuccess(Response), wraps the
response object returned by the http client and exposes the following information:
-
getRequestLine - information about the performed request
-
getHost - the host that returned the response
-
getStatusLine - the response status line
-
getHeaders -
the response headers, which can also be retrieved by name
though
getHeader(String) -
getEntity -
the response body enclosed in an
org.apache.http.HttpEntityobject
When performing a request, an exception is thrown (or received as an argument
in ResponseListener#onFailure(Exception) in the following scenarios:
-
IOException - communication problem (e.g. SocketTimeoutException etc.)
-
ResponseException -
a response was returned, but its status code indicated
an error (not
2xx). AResponseExceptionoriginates from a valid http response, hence it exposes its correspondingResponseobject which gives access to the returned response.
A ResponseException is not thrown for HEAD requests that return
a 404 status code because it is an expected HEAD response that simply
denotes that the resource is not found. All other HTTP methods (e.g., GET)
throw a ResponseException for 404 responses.