rename ElasticsearchResponse to Response and ElasticsearchResponseException to ResponseException
This commit is contained in:
parent
be5e2e145b
commit
437c4f210b
|
@ -26,7 +26,7 @@ import org.apache.commons.logging.Log;
|
|||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.HttpHost;
|
||||
import org.elasticsearch.client.ElasticsearchResponse;
|
||||
import org.elasticsearch.client.Response;
|
||||
import org.elasticsearch.client.RestClient;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -62,7 +62,7 @@ public class HostsSniffer {
|
|||
* Calls the elasticsearch nodes info api, parses the response and returns all the found http hosts
|
||||
*/
|
||||
public List<HttpHost> sniffHosts() throws IOException {
|
||||
try (ElasticsearchResponse response = restClient.performRequest("get", "/_nodes/http", sniffRequestParams, null)) {
|
||||
try (Response response = restClient.performRequest("get", "/_nodes/http", sniffRequestParams, null)) {
|
||||
return readHosts(response.getEntity());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,8 +31,8 @@ import org.apache.http.Consts;
|
|||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.lucene.util.LuceneTestCase;
|
||||
import org.elasticsearch.client.ElasticsearchResponse;
|
||||
import org.elasticsearch.client.ElasticsearchResponseException;
|
||||
import org.elasticsearch.client.Response;
|
||||
import org.elasticsearch.client.ResponseException;
|
||||
import org.elasticsearch.client.RestClient;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
|
@ -93,8 +93,8 @@ public class HostsSnifferTests extends LuceneTestCase {
|
|||
for (HttpHost sniffedHost : sniffedHosts) {
|
||||
assertEquals(sniffedHost, responseHostsIterator.next());
|
||||
}
|
||||
} catch(ElasticsearchResponseException e) {
|
||||
ElasticsearchResponse response = e.getElasticsearchResponse();
|
||||
} catch(ResponseException e) {
|
||||
Response response = e.getResponse();
|
||||
if (sniffResponse.isFailure) {
|
||||
assertThat(e.getMessage(), containsString("GET " + httpHost + "/_nodes/http?timeout=" + sniffRequestTimeout + "ms"));
|
||||
assertThat(e.getMessage(), containsString(Integer.toString(sniffResponse.nodesInfoResponseCode)));
|
||||
|
|
|
@ -35,13 +35,13 @@ import java.util.Objects;
|
|||
* its corresponding {@link RequestLine} and {@link HttpHost}.
|
||||
* It must be closed to free any resource held by it, as well as the corresponding connection in the connection pool.
|
||||
*/
|
||||
public class ElasticsearchResponse implements Closeable {
|
||||
public class Response implements Closeable {
|
||||
|
||||
private final RequestLine requestLine;
|
||||
private final HttpHost host;
|
||||
private final CloseableHttpResponse response;
|
||||
|
||||
ElasticsearchResponse(RequestLine requestLine, HttpHost host, CloseableHttpResponse response) {
|
||||
Response(RequestLine requestLine, HttpHost host, CloseableHttpResponse response) {
|
||||
Objects.requireNonNull(requestLine, "requestLine cannot be null");
|
||||
Objects.requireNonNull(host, "node cannot be null");
|
||||
Objects.requireNonNull(response, "response cannot be null");
|
||||
|
@ -101,7 +101,7 @@ public class ElasticsearchResponse implements Closeable {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ElasticsearchResponse{" +
|
||||
return "Response{" +
|
||||
"requestLine=" + requestLine +
|
||||
", host=" + host +
|
||||
", response=" + response.getStatusLine() +
|
|
@ -23,21 +23,21 @@ import java.io.IOException;
|
|||
|
||||
/**
|
||||
* Exception thrown when an elasticsearch node responds to a request with a status code that indicates an error.
|
||||
* Note that the response body gets passed in as a string and read eagerly, which means that the ElasticsearchResponse object
|
||||
* Note that the response body gets passed in as a string and read eagerly, which means that the Response object
|
||||
* is expected to be closed and available only to read metadata like status line, request line, response headers.
|
||||
*/
|
||||
public class ElasticsearchResponseException extends IOException {
|
||||
public class ResponseException extends IOException {
|
||||
|
||||
private ElasticsearchResponse elasticsearchResponse;
|
||||
private Response response;
|
||||
private final String responseBody;
|
||||
|
||||
ElasticsearchResponseException(ElasticsearchResponse elasticsearchResponse, String responseBody) throws IOException {
|
||||
super(buildMessage(elasticsearchResponse,responseBody));
|
||||
this.elasticsearchResponse = elasticsearchResponse;
|
||||
ResponseException(Response response, String responseBody) throws IOException {
|
||||
super(buildMessage(response,responseBody));
|
||||
this.response = response;
|
||||
this.responseBody = responseBody;
|
||||
}
|
||||
|
||||
private static String buildMessage(ElasticsearchResponse response, String responseBody) {
|
||||
private static String buildMessage(Response response, String responseBody) {
|
||||
String message = response.getRequestLine().getMethod() + " " + response.getHost() + response.getRequestLine().getUri()
|
||||
+ ": " + response.getStatusLine().toString();
|
||||
if (responseBody != null) {
|
||||
|
@ -47,17 +47,17 @@ public class ElasticsearchResponseException extends IOException {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns the {@link ElasticsearchResponse} that caused this exception to be thrown.
|
||||
* Returns the {@link Response} that caused this exception to be thrown.
|
||||
* Expected to be used only to read metadata like status line, request line, response headers. The response body should
|
||||
* be retrieved using {@link #getResponseBody()}
|
||||
*/
|
||||
public ElasticsearchResponse getElasticsearchResponse() {
|
||||
return elasticsearchResponse;
|
||||
public Response getResponse() {
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the response body as a string or null if there wasn't any.
|
||||
* The body is eagerly consumed when an ElasticsearchResponseException gets created, and its corresponding ElasticsearchResponse
|
||||
* The body is eagerly consumed when an ResponseException gets created, and its corresponding Response
|
||||
* gets closed straightaway so this method is the only way to get back the response body that was returned.
|
||||
*/
|
||||
public String getResponseBody() {
|
|
@ -131,10 +131,10 @@ public final class RestClient implements Closeable {
|
|||
* @return the response returned by elasticsearch
|
||||
* @throws IOException in case of a problem or the connection was aborted
|
||||
* @throws ClientProtocolException in case of an http protocol error
|
||||
* @throws ElasticsearchResponseException in case elasticsearch responded with a status code that indicated an error
|
||||
* @throws ResponseException in case elasticsearch responded with a status code that indicated an error
|
||||
*/
|
||||
public ElasticsearchResponse performRequest(String method, String endpoint, Map<String, String> params,
|
||||
HttpEntity entity, Header... headers) throws IOException {
|
||||
public Response performRequest(String method, String endpoint, Map<String, String> params,
|
||||
HttpEntity entity, Header... headers) throws IOException {
|
||||
URI uri = buildUri(endpoint, params);
|
||||
HttpRequestBase request = createHttpRequest(method, uri, entity);
|
||||
setHeaders(request, headers);
|
||||
|
@ -167,7 +167,7 @@ public final class RestClient implements Closeable {
|
|||
lastSeenException = addSuppressedException(lastSeenException, e);
|
||||
continue;
|
||||
}
|
||||
ElasticsearchResponse elasticsearchResponse = new ElasticsearchResponse(request.getRequestLine(), host, response);
|
||||
Response elasticsearchResponse = new Response(request.getRequestLine(), host, response);
|
||||
int statusCode = response.getStatusLine().getStatusCode();
|
||||
if (statusCode < 300 || (request.getMethod().equals(HttpHead.METHOD_NAME) && statusCode == 404) ) {
|
||||
RequestLogger.log(logger, "request succeeded", request, host, response);
|
||||
|
@ -185,9 +185,9 @@ public final class RestClient implements Closeable {
|
|||
} finally {
|
||||
elasticsearchResponse.close();
|
||||
}
|
||||
ElasticsearchResponseException elasticsearchResponseException = new ElasticsearchResponseException(
|
||||
ResponseException responseException = new ResponseException(
|
||||
elasticsearchResponse, responseBody);
|
||||
lastSeenException = addSuppressedException(lastSeenException, elasticsearchResponseException);
|
||||
lastSeenException = addSuppressedException(lastSeenException, responseException);
|
||||
//clients don't retry on 500 because elasticsearch still misuses it instead of 400 in some places
|
||||
if (statusCode == 502 || statusCode == 503 || statusCode == 504) {
|
||||
onFailure(host);
|
||||
|
|
|
@ -144,12 +144,12 @@ public class RestClientIntegTests extends LuceneTestCase {
|
|||
}
|
||||
|
||||
int statusCode = randomStatusCode(random());
|
||||
ElasticsearchResponse esResponse;
|
||||
try (ElasticsearchResponse response = restClient.performRequest(method, "/" + statusCode,
|
||||
Response esResponse;
|
||||
try (Response response = restClient.performRequest(method, "/" + statusCode,
|
||||
Collections.<String, String>emptyMap(), null, headers)) {
|
||||
esResponse = response;
|
||||
} catch(ElasticsearchResponseException e) {
|
||||
esResponse = e.getElasticsearchResponse();
|
||||
} catch(ResponseException e) {
|
||||
esResponse = e.getResponse();
|
||||
}
|
||||
assertThat(esResponse.getStatusLine().getStatusCode(), equalTo(statusCode));
|
||||
for (Header responseHeader : esResponse.getHeaders()) {
|
||||
|
@ -187,16 +187,16 @@ public class RestClientIntegTests extends LuceneTestCase {
|
|||
private void testBody(String method) throws Exception {
|
||||
String requestBody = "{ \"field\": \"value\" }";
|
||||
StringEntity entity = new StringEntity(requestBody);
|
||||
ElasticsearchResponse esResponse;
|
||||
Response esResponse;
|
||||
String responseBody;
|
||||
int statusCode = randomStatusCode(random());
|
||||
try (ElasticsearchResponse response = restClient.performRequest(method, "/" + statusCode,
|
||||
try (Response response = restClient.performRequest(method, "/" + statusCode,
|
||||
Collections.<String, String>emptyMap(), entity)) {
|
||||
responseBody = EntityUtils.toString(response.getEntity());
|
||||
esResponse = response;
|
||||
} catch(ElasticsearchResponseException e) {
|
||||
} catch(ResponseException e) {
|
||||
responseBody = e.getResponseBody();
|
||||
esResponse = e.getElasticsearchResponse();
|
||||
esResponse = e.getResponse();
|
||||
}
|
||||
assertEquals(statusCode, esResponse.getStatusLine().getStatusCode());
|
||||
assertEquals(requestBody, responseBody);
|
||||
|
|
|
@ -102,7 +102,7 @@ public class RestClientMultipleHostsTests extends LuceneTestCase {
|
|||
Collections.addAll(hostsSet, httpHosts);
|
||||
for (int j = 0; j < httpHosts.length; j++) {
|
||||
int statusCode = randomOkStatusCode(random());
|
||||
try (ElasticsearchResponse response = restClient.performRequest(randomHttpMethod(random()), "/" + statusCode,
|
||||
try (Response response = restClient.performRequest(randomHttpMethod(random()), "/" + statusCode,
|
||||
Collections.<String, String>emptyMap(), null)) {
|
||||
assertThat(response.getStatusLine().getStatusCode(), equalTo(statusCode));
|
||||
assertTrue("host not found: " + response.getHost(), hostsSet.remove(response.getHost()));
|
||||
|
@ -121,7 +121,7 @@ public class RestClientMultipleHostsTests extends LuceneTestCase {
|
|||
for (int j = 0; j < httpHosts.length; j++) {
|
||||
String method = randomHttpMethod(random());
|
||||
int statusCode = randomErrorNoRetryStatusCode(random());
|
||||
try (ElasticsearchResponse response = restClient.performRequest(method, "/" + statusCode,
|
||||
try (Response response = restClient.performRequest(method, "/" + statusCode,
|
||||
Collections.<String, String>emptyMap(), null)) {
|
||||
if (method.equals("HEAD") && statusCode == 404) {
|
||||
//no exception gets thrown although we got a 404
|
||||
|
@ -131,11 +131,11 @@ public class RestClientMultipleHostsTests extends LuceneTestCase {
|
|||
} else {
|
||||
fail("request should have failed");
|
||||
}
|
||||
} catch(ElasticsearchResponseException e) {
|
||||
} catch(ResponseException e) {
|
||||
if (method.equals("HEAD") && statusCode == 404) {
|
||||
throw e;
|
||||
}
|
||||
ElasticsearchResponse response = e.getElasticsearchResponse();
|
||||
Response response = e.getResponse();
|
||||
assertThat(response.getStatusLine().getStatusCode(), equalTo(statusCode));
|
||||
assertTrue("host not found: " + response.getHost(), hostsSet.remove(response.getHost()));
|
||||
assertEquals(0, e.getSuppressed().length);
|
||||
|
@ -151,21 +151,21 @@ public class RestClientMultipleHostsTests extends LuceneTestCase {
|
|||
try {
|
||||
restClient.performRequest(randomHttpMethod(random()), retryEndpoint, Collections.<String, String>emptyMap(), null);
|
||||
fail("request should have failed");
|
||||
} catch(ElasticsearchResponseException e) {
|
||||
} catch(ResponseException e) {
|
||||
Set<HttpHost> hostsSet = new HashSet<>();
|
||||
Collections.addAll(hostsSet, httpHosts);
|
||||
//first request causes all the hosts to be blacklisted, the returned exception holds one suppressed exception each
|
||||
failureListener.assertCalled(httpHosts);
|
||||
do {
|
||||
ElasticsearchResponse response = e.getElasticsearchResponse();
|
||||
Response response = e.getResponse();
|
||||
assertThat(response.getStatusLine().getStatusCode(), equalTo(Integer.parseInt(retryEndpoint.substring(1))));
|
||||
assertTrue("host [" + response.getHost() + "] not found, most likely used multiple times",
|
||||
hostsSet.remove(response.getHost()));
|
||||
if (e.getSuppressed().length > 0) {
|
||||
assertEquals(1, e.getSuppressed().length);
|
||||
Throwable suppressed = e.getSuppressed()[0];
|
||||
assertThat(suppressed, instanceOf(ElasticsearchResponseException.class));
|
||||
e = (ElasticsearchResponseException)suppressed;
|
||||
assertThat(suppressed, instanceOf(ResponseException.class));
|
||||
e = (ResponseException)suppressed;
|
||||
} else {
|
||||
e = null;
|
||||
}
|
||||
|
@ -201,8 +201,8 @@ public class RestClientMultipleHostsTests extends LuceneTestCase {
|
|||
try {
|
||||
restClient.performRequest(randomHttpMethod(random()), retryEndpoint, Collections.<String, String>emptyMap(), null);
|
||||
fail("request should have failed");
|
||||
} catch(ElasticsearchResponseException e) {
|
||||
ElasticsearchResponse response = e.getElasticsearchResponse();
|
||||
} catch(ResponseException e) {
|
||||
Response response = e.getResponse();
|
||||
assertThat(response.getStatusLine().getStatusCode(), equalTo(Integer.parseInt(retryEndpoint.substring(1))));
|
||||
assertTrue("host [" + response.getHost() + "] not found, most likely used multiple times",
|
||||
hostsSet.remove(response.getHost()));
|
||||
|
@ -224,13 +224,13 @@ public class RestClientMultipleHostsTests extends LuceneTestCase {
|
|||
int iters = RandomInts.randomIntBetween(random(), 2, 10);
|
||||
for (int y = 0; y < iters; y++) {
|
||||
int statusCode = randomErrorNoRetryStatusCode(random());
|
||||
ElasticsearchResponse response;
|
||||
try (ElasticsearchResponse esResponse = restClient.performRequest(randomHttpMethod(random()), "/" + statusCode,
|
||||
Response response;
|
||||
try (Response esResponse = restClient.performRequest(randomHttpMethod(random()), "/" + statusCode,
|
||||
Collections.<String, String>emptyMap(), null)) {
|
||||
response = esResponse;
|
||||
}
|
||||
catch(ElasticsearchResponseException e) {
|
||||
response = e.getElasticsearchResponse();
|
||||
catch(ResponseException e) {
|
||||
response = e.getResponse();
|
||||
}
|
||||
assertThat(response.getStatusLine().getStatusCode(), equalTo(statusCode));
|
||||
if (selectedHost == null) {
|
||||
|
@ -248,8 +248,8 @@ public class RestClientMultipleHostsTests extends LuceneTestCase {
|
|||
restClient.performRequest(randomHttpMethod(random()), retryEndpoint,
|
||||
Collections.<String, String>emptyMap(), null);
|
||||
fail("request should have failed");
|
||||
} catch(ElasticsearchResponseException e) {
|
||||
ElasticsearchResponse response = e.getElasticsearchResponse();
|
||||
} catch(ResponseException e) {
|
||||
Response response = e.getResponse();
|
||||
assertThat(response.getStatusLine().getStatusCode(), equalTo(Integer.parseInt(retryEndpoint.substring(1))));
|
||||
assertThat(response.getHost(), equalTo(selectedHost));
|
||||
failureListener.assertCalled(selectedHost);
|
||||
|
|
|
@ -183,7 +183,7 @@ public class RestClientSingleHostTests extends LuceneTestCase {
|
|||
public void testOkStatusCodes() throws Exception {
|
||||
for (String method : getHttpMethods()) {
|
||||
for (int okStatusCode : getOkStatusCodes()) {
|
||||
ElasticsearchResponse response = restClient.performRequest(method, "/" + okStatusCode,
|
||||
Response response = restClient.performRequest(method, "/" + okStatusCode,
|
||||
Collections.<String, String>emptyMap(), null);
|
||||
assertThat(response.getStatusLine().getStatusCode(), equalTo(okStatusCode));
|
||||
}
|
||||
|
@ -198,7 +198,7 @@ public class RestClientSingleHostTests extends LuceneTestCase {
|
|||
for (String method : getHttpMethods()) {
|
||||
//error status codes should cause an exception to be thrown
|
||||
for (int errorStatusCode : getAllErrorStatusCodes()) {
|
||||
try (ElasticsearchResponse response = restClient.performRequest(method, "/" + errorStatusCode,
|
||||
try (Response response = restClient.performRequest(method, "/" + errorStatusCode,
|
||||
Collections.<String, String>emptyMap(), null)) {
|
||||
if (method.equals("HEAD") && errorStatusCode == 404) {
|
||||
//no exception gets thrown although we got a 404
|
||||
|
@ -206,11 +206,11 @@ public class RestClientSingleHostTests extends LuceneTestCase {
|
|||
} else {
|
||||
fail("request should have failed");
|
||||
}
|
||||
} catch(ElasticsearchResponseException e) {
|
||||
} catch(ResponseException e) {
|
||||
if (method.equals("HEAD") && errorStatusCode == 404) {
|
||||
throw e;
|
||||
}
|
||||
assertThat(e.getElasticsearchResponse().getStatusLine().getStatusCode(), equalTo(errorStatusCode));
|
||||
assertThat(e.getResponse().getStatusLine().getStatusCode(), equalTo(errorStatusCode));
|
||||
}
|
||||
if (errorStatusCode <= 500) {
|
||||
failureListener.assertNotCalled();
|
||||
|
@ -250,7 +250,7 @@ public class RestClientSingleHostTests extends LuceneTestCase {
|
|||
StringEntity entity = new StringEntity(body);
|
||||
for (String method : Arrays.asList("DELETE", "GET", "PATCH", "POST", "PUT")) {
|
||||
for (int okStatusCode : getOkStatusCodes()) {
|
||||
try (ElasticsearchResponse response = restClient.performRequest(method, "/" + okStatusCode,
|
||||
try (Response response = restClient.performRequest(method, "/" + okStatusCode,
|
||||
Collections.<String, String>emptyMap(), entity)) {
|
||||
assertThat(response.getStatusLine().getStatusCode(), equalTo(okStatusCode));
|
||||
assertThat(EntityUtils.toString(response.getEntity()), equalTo(body));
|
||||
|
@ -260,8 +260,8 @@ public class RestClientSingleHostTests extends LuceneTestCase {
|
|||
try {
|
||||
restClient.performRequest(method, "/" + errorStatusCode, Collections.<String, String>emptyMap(), entity);
|
||||
fail("request should have failed");
|
||||
} catch(ElasticsearchResponseException e) {
|
||||
ElasticsearchResponse response = e.getElasticsearchResponse();
|
||||
} catch(ResponseException e) {
|
||||
Response response = e.getResponse();
|
||||
assertThat(response.getStatusLine().getStatusCode(), equalTo(errorStatusCode));
|
||||
assertThat(EntityUtils.toString(response.getEntity()), equalTo(body));
|
||||
}
|
||||
|
@ -326,12 +326,12 @@ public class RestClientSingleHostTests extends LuceneTestCase {
|
|||
}
|
||||
|
||||
int statusCode = randomStatusCode(random());
|
||||
ElasticsearchResponse esResponse;
|
||||
try (ElasticsearchResponse response = restClient.performRequest(method, "/" + statusCode,
|
||||
Response esResponse;
|
||||
try (Response response = restClient.performRequest(method, "/" + statusCode,
|
||||
Collections.<String, String>emptyMap(), null, headers)) {
|
||||
esResponse = response;
|
||||
} catch(ElasticsearchResponseException e) {
|
||||
esResponse = e.getElasticsearchResponse();
|
||||
} catch(ResponseException e) {
|
||||
esResponse = e.getResponse();
|
||||
}
|
||||
assertThat(esResponse.getStatusLine().getStatusCode(), equalTo(statusCode));
|
||||
for (Header responseHeader : esResponse.getHeaders()) {
|
||||
|
@ -413,7 +413,7 @@ public class RestClientSingleHostTests extends LuceneTestCase {
|
|||
|
||||
try {
|
||||
restClient.performRequest(method, uriAsString, params, entity, headers);
|
||||
} catch(ElasticsearchResponseException e) {
|
||||
} catch(ResponseException e) {
|
||||
//all good
|
||||
}
|
||||
return request;
|
||||
|
|
|
@ -27,7 +27,7 @@ import org.apache.http.impl.client.CloseableHttpClient;
|
|||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.message.BasicHeader;
|
||||
import org.apache.http.protocol.HttpContext;
|
||||
import org.elasticsearch.client.ElasticsearchResponse;
|
||||
import org.elasticsearch.client.Response;
|
||||
import org.elasticsearch.client.RestClient;
|
||||
import org.elasticsearch.common.network.NetworkModule;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
|
@ -62,7 +62,7 @@ public class NettyHttpCompressionIT extends ESIntegTestCase {
|
|||
// we need to intercept early, otherwise internal logic in HttpClient will just remove the header and we cannot verify it
|
||||
ContentEncodingHeaderExtractor headerExtractor = new ContentEncodingHeaderExtractor();
|
||||
try (RestClient client = createRestClient(HttpClients.custom().addInterceptorFirst(headerExtractor).build())) {
|
||||
try (ElasticsearchResponse response = client.performRequest("GET", "/", Collections.emptyMap(), null,
|
||||
try (Response response = client.performRequest("GET", "/", Collections.emptyMap(), null,
|
||||
new BasicHeader(HttpHeaders.ACCEPT_ENCODING, GZIP_ENCODING))) {
|
||||
assertEquals(200, response.getStatusLine().getStatusCode());
|
||||
assertTrue(headerExtractor.hasContentEncodingHeader());
|
||||
|
@ -76,7 +76,7 @@ public class NettyHttpCompressionIT extends ESIntegTestCase {
|
|||
ContentEncodingHeaderExtractor headerExtractor = new ContentEncodingHeaderExtractor();
|
||||
CloseableHttpClient httpClient = HttpClients.custom().disableContentCompression().addInterceptorFirst(headerExtractor).build();
|
||||
try (RestClient client = createRestClient(httpClient)) {
|
||||
try (ElasticsearchResponse response = client.performRequest("GET", "/", Collections.emptyMap(), null)) {
|
||||
try (Response response = client.performRequest("GET", "/", Collections.emptyMap(), null)) {
|
||||
assertEquals(200, response.getStatusLine().getStatusCode());
|
||||
assertFalse(headerExtractor.hasContentEncodingHeader());
|
||||
}
|
||||
|
@ -89,7 +89,7 @@ public class NettyHttpCompressionIT extends ESIntegTestCase {
|
|||
// this disable content compression in both directions (request and response)
|
||||
CloseableHttpClient httpClient = HttpClients.custom().disableContentCompression().addInterceptorFirst(headerExtractor).build();
|
||||
try (RestClient client = createRestClient(httpClient)) {
|
||||
try (ElasticsearchResponse response = client.performRequest("POST", "/company/employees/1",
|
||||
try (Response response = client.performRequest("POST", "/company/employees/1",
|
||||
Collections.emptyMap(), SAMPLE_DOCUMENT)) {
|
||||
assertEquals(201, response.getStatusLine().getStatusCode());
|
||||
assertFalse(headerExtractor.hasContentEncodingHeader());
|
||||
|
@ -102,7 +102,7 @@ public class NettyHttpCompressionIT extends ESIntegTestCase {
|
|||
ContentEncodingHeaderExtractor headerExtractor = new ContentEncodingHeaderExtractor();
|
||||
// we don't call #disableContentCompression() hence the client will send the content compressed
|
||||
try (RestClient client = createRestClient(HttpClients.custom().addInterceptorFirst(headerExtractor).build())) {
|
||||
try (ElasticsearchResponse response = client.performRequest("POST", "/company/employees/2",
|
||||
try (Response response = client.performRequest("POST", "/company/employees/2",
|
||||
Collections.emptyMap(), SAMPLE_DOCUMENT)) {
|
||||
assertEquals(201, response.getStatusLine().getStatusCode());
|
||||
assertEquals(GZIP_ENCODING, headerExtractor.getContentEncodingHeader().getValue());
|
||||
|
|
|
@ -19,8 +19,8 @@
|
|||
|
||||
package org.elasticsearch.options.detailederrors;
|
||||
|
||||
import org.elasticsearch.client.ElasticsearchResponse;
|
||||
import org.elasticsearch.client.ElasticsearchResponseException;
|
||||
import org.elasticsearch.client.Response;
|
||||
import org.elasticsearch.client.ResponseException;
|
||||
import org.elasticsearch.common.network.NetworkModule;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.http.HttpTransportSettings;
|
||||
|
@ -51,8 +51,8 @@ public class DetailedErrorsDisabledIT extends ESIntegTestCase {
|
|||
try {
|
||||
getRestClient().performRequest("DELETE", "/", Collections.singletonMap("error_trace", "true"), null);
|
||||
fail("request should have failed");
|
||||
} catch(ElasticsearchResponseException e) {
|
||||
ElasticsearchResponse response = e.getElasticsearchResponse();
|
||||
} catch(ResponseException e) {
|
||||
Response response = e.getResponse();
|
||||
assertThat(response.getHeader("Content-Type"), is("application/json"));
|
||||
assertThat(e.getResponseBody(), is("{\"error\":\"error traces in responses are disabled.\"}"));
|
||||
assertThat(response.getStatusLine().getStatusCode(), is(400));
|
||||
|
|
|
@ -19,8 +19,8 @@
|
|||
|
||||
package org.elasticsearch.options.detailederrors;
|
||||
|
||||
import org.elasticsearch.client.ElasticsearchResponse;
|
||||
import org.elasticsearch.client.ElasticsearchResponseException;
|
||||
import org.elasticsearch.client.Response;
|
||||
import org.elasticsearch.client.ResponseException;
|
||||
import org.elasticsearch.common.network.NetworkModule;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.test.ESIntegTestCase;
|
||||
|
@ -49,8 +49,8 @@ public class DetailedErrorsEnabledIT extends ESIntegTestCase {
|
|||
try {
|
||||
getRestClient().performRequest("DELETE", "/", Collections.singletonMap("error_trace", "true"), null);
|
||||
fail("request should have failed");
|
||||
} catch(ElasticsearchResponseException e) {
|
||||
ElasticsearchResponse response = e.getElasticsearchResponse();
|
||||
} catch(ResponseException e) {
|
||||
Response response = e.getResponse();
|
||||
assertThat(response.getHeader("Content-Type"), containsString("application/json"));
|
||||
assertThat(e.getResponseBody(), containsString("\"stack_trace\":\"[Validation Failed: 1: index / indices is missing;]; " +
|
||||
"nested: ActionRequestValidationException[Validation Failed: 1:"));
|
||||
|
@ -59,8 +59,8 @@ public class DetailedErrorsEnabledIT extends ESIntegTestCase {
|
|||
try {
|
||||
getRestClient().performRequest("DELETE", "/", Collections.emptyMap(), null);
|
||||
fail("request should have failed");
|
||||
} catch(ElasticsearchResponseException e) {
|
||||
ElasticsearchResponse response = e.getElasticsearchResponse();
|
||||
} catch(ResponseException e) {
|
||||
Response response = e.getResponse();
|
||||
assertThat(response.getHeader("Content-Type"), containsString("application/json"));
|
||||
assertThat(e.getResponseBody(), not(containsString("\"stack_trace\":\"[Validation Failed: 1: index / indices is missing;]; "
|
||||
+ "nested: ActionRequestValidationException[Validation Failed: 1:")));
|
||||
|
|
|
@ -19,8 +19,8 @@
|
|||
package org.elasticsearch.plugins;
|
||||
|
||||
import org.apache.http.message.BasicHeader;
|
||||
import org.elasticsearch.client.ElasticsearchResponse;
|
||||
import org.elasticsearch.client.ElasticsearchResponseException;
|
||||
import org.elasticsearch.client.Response;
|
||||
import org.elasticsearch.client.ResponseException;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.plugins.responseheader.TestResponseHeaderPlugin;
|
||||
import org.elasticsearch.test.ESIntegTestCase;
|
||||
|
@ -55,13 +55,13 @@ public class ResponseHeaderPluginIT extends ESIntegTestCase {
|
|||
try {
|
||||
getRestClient().performRequest("GET", "/_protected", Collections.emptyMap(), null);
|
||||
fail("request should have failed");
|
||||
} catch(ElasticsearchResponseException e) {
|
||||
ElasticsearchResponse response = e.getElasticsearchResponse();
|
||||
} catch(ResponseException e) {
|
||||
Response response = e.getResponse();
|
||||
assertThat(response.getStatusLine().getStatusCode(), equalTo(401));
|
||||
assertThat(response.getHeader("Secret"), equalTo("required"));
|
||||
}
|
||||
|
||||
try (ElasticsearchResponse authResponse = getRestClient().performRequest("GET", "/_protected", Collections.emptyMap(), null,
|
||||
try (Response authResponse = getRestClient().performRequest("GET", "/_protected", Collections.emptyMap(), null,
|
||||
new BasicHeader("Secret", "password"))) {
|
||||
assertThat(authResponse.getStatusLine().getStatusCode(), equalTo(200));
|
||||
assertThat(authResponse.getHeader("Secret"), equalTo("granted"));
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
package org.elasticsearch.rest;
|
||||
|
||||
import org.apache.http.message.BasicHeader;
|
||||
import org.elasticsearch.client.ElasticsearchResponse;
|
||||
import org.elasticsearch.client.Response;
|
||||
import org.elasticsearch.common.network.NetworkModule;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.test.ESIntegTestCase;
|
||||
|
@ -46,7 +46,7 @@ public class CorsNotSetIT extends ESIntegTestCase {
|
|||
|
||||
public void testCorsSettingDefaultBehaviourDoesNotReturnAnything() throws Exception {
|
||||
String corsValue = "http://localhost:9200";
|
||||
try (ElasticsearchResponse response = getRestClient().performRequest("GET", "/", Collections.emptyMap(), null,
|
||||
try (Response response = getRestClient().performRequest("GET", "/", Collections.emptyMap(), null,
|
||||
new BasicHeader("User-Agent", "Mozilla Bar"), new BasicHeader("Origin", corsValue))) {
|
||||
assertThat(response.getStatusLine().getStatusCode(), is(200));
|
||||
assertThat(response.getHeader("Access-Control-Allow-Origin"), nullValue());
|
||||
|
@ -55,7 +55,7 @@ public class CorsNotSetIT extends ESIntegTestCase {
|
|||
}
|
||||
|
||||
public void testThatOmittingCorsHeaderDoesNotReturnAnything() throws Exception {
|
||||
try (ElasticsearchResponse response = getRestClient().performRequest("GET", "/", Collections.emptyMap(), null)) {
|
||||
try (Response response = getRestClient().performRequest("GET", "/", Collections.emptyMap(), null)) {
|
||||
assertThat(response.getStatusLine().getStatusCode(), is(200));
|
||||
assertThat(response.getHeader("Access-Control-Allow-Origin"), nullValue());
|
||||
assertThat(response.getHeader("Access-Control-Allow-Credentials"), nullValue());
|
||||
|
|
|
@ -19,8 +19,8 @@
|
|||
package org.elasticsearch.rest;
|
||||
|
||||
import org.apache.http.message.BasicHeader;
|
||||
import org.elasticsearch.client.ElasticsearchResponse;
|
||||
import org.elasticsearch.client.ElasticsearchResponseException;
|
||||
import org.elasticsearch.client.Response;
|
||||
import org.elasticsearch.client.ResponseException;
|
||||
import org.elasticsearch.common.logging.ESLogger;
|
||||
import org.elasticsearch.common.logging.Loggers;
|
||||
import org.elasticsearch.common.network.NetworkModule;
|
||||
|
@ -61,12 +61,12 @@ public class CorsRegexIT extends ESIntegTestCase {
|
|||
|
||||
public void testThatRegularExpressionWorksOnMatch() throws Exception {
|
||||
String corsValue = "http://localhost:9200";
|
||||
try (ElasticsearchResponse response = getRestClient().performRequest("GET", "/", Collections.emptyMap(), null,
|
||||
try (Response response = getRestClient().performRequest("GET", "/", Collections.emptyMap(), null,
|
||||
new BasicHeader("User-Agent", "Mozilla Bar"), new BasicHeader("Origin", corsValue))) {
|
||||
assertResponseWithOriginheader(response, corsValue);
|
||||
}
|
||||
corsValue = "https://localhost:9200";
|
||||
try (ElasticsearchResponse response = getRestClient().performRequest("GET", "/", Collections.emptyMap(), null,
|
||||
try (Response response = getRestClient().performRequest("GET", "/", Collections.emptyMap(), null,
|
||||
new BasicHeader("User-Agent", "Mozilla Bar"), new BasicHeader("Origin", corsValue));) {
|
||||
assertResponseWithOriginheader(response, corsValue);
|
||||
assertThat(response.getHeader("Access-Control-Allow-Credentials"), is("true"));
|
||||
|
@ -78,8 +78,8 @@ public class CorsRegexIT extends ESIntegTestCase {
|
|||
getRestClient().performRequest("GET", "/", Collections.emptyMap(), null, new BasicHeader("User-Agent", "Mozilla Bar"),
|
||||
new BasicHeader("Origin", "http://evil-host:9200"));
|
||||
fail("request should have failed");
|
||||
} catch(ElasticsearchResponseException e) {
|
||||
ElasticsearchResponse response = e.getElasticsearchResponse();
|
||||
} catch(ResponseException e) {
|
||||
Response response = e.getResponse();
|
||||
// a rejected origin gets a FORBIDDEN - 403
|
||||
assertThat(response.getStatusLine().getStatusCode(), is(403));
|
||||
assertThat(response.getHeader("Access-Control-Allow-Origin"), nullValue());
|
||||
|
@ -87,7 +87,7 @@ public class CorsRegexIT extends ESIntegTestCase {
|
|||
}
|
||||
|
||||
public void testThatSendingNoOriginHeaderReturnsNoAccessControlHeader() throws Exception {
|
||||
try (ElasticsearchResponse response = getRestClient().performRequest("GET", "/", Collections.emptyMap(), null,
|
||||
try (Response response = getRestClient().performRequest("GET", "/", Collections.emptyMap(), null,
|
||||
new BasicHeader("User-Agent", "Mozilla Bar"))) {
|
||||
assertThat(response.getStatusLine().getStatusCode(), is(200));
|
||||
assertThat(response.getHeader("Access-Control-Allow-Origin"), nullValue());
|
||||
|
@ -95,7 +95,7 @@ public class CorsRegexIT extends ESIntegTestCase {
|
|||
}
|
||||
|
||||
public void testThatRegularExpressionIsNotAppliedWithoutCorrectBrowserOnMatch() throws Exception {
|
||||
try (ElasticsearchResponse response = getRestClient().performRequest("GET", "/", Collections.emptyMap(), null)) {
|
||||
try (Response response = getRestClient().performRequest("GET", "/", Collections.emptyMap(), null)) {
|
||||
assertThat(response.getStatusLine().getStatusCode(), is(200));
|
||||
assertThat(response.getHeader("Access-Control-Allow-Origin"), nullValue());
|
||||
}
|
||||
|
@ -103,7 +103,7 @@ public class CorsRegexIT extends ESIntegTestCase {
|
|||
|
||||
public void testThatPreFlightRequestWorksOnMatch() throws Exception {
|
||||
String corsValue = "http://localhost:9200";
|
||||
try (ElasticsearchResponse response = getRestClient().performRequest("OPTIONS", "/", Collections.emptyMap(), null,
|
||||
try (Response response = getRestClient().performRequest("OPTIONS", "/", Collections.emptyMap(), null,
|
||||
new BasicHeader("User-Agent", "Mozilla Bar"), new BasicHeader("Origin", corsValue),
|
||||
new BasicHeader(HttpHeaders.Names.ACCESS_CONTROL_REQUEST_METHOD, "GET"));) {
|
||||
assertResponseWithOriginheader(response, corsValue);
|
||||
|
@ -117,8 +117,8 @@ public class CorsRegexIT extends ESIntegTestCase {
|
|||
new BasicHeader("Origin", "http://evil-host:9200"),
|
||||
new BasicHeader(HttpHeaders.Names.ACCESS_CONTROL_REQUEST_METHOD, "GET"));
|
||||
fail("request should have failed");
|
||||
} catch(ElasticsearchResponseException e) {
|
||||
ElasticsearchResponse response = e.getElasticsearchResponse();
|
||||
} catch(ResponseException e) {
|
||||
Response response = e.getResponse();
|
||||
// a rejected origin gets a FORBIDDEN - 403
|
||||
assertThat(response.getStatusLine().getStatusCode(), is(403));
|
||||
assertThat(response.getHeader("Access-Control-Allow-Origin"), nullValue());
|
||||
|
@ -126,7 +126,7 @@ public class CorsRegexIT extends ESIntegTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
protected static void assertResponseWithOriginheader(ElasticsearchResponse response, String expectedCorsHeader) {
|
||||
protected static void assertResponseWithOriginheader(Response response, String expectedCorsHeader) {
|
||||
assertThat(response.getStatusLine().getStatusCode(), is(200));
|
||||
assertThat(response.getHeader("Access-Control-Allow-Origin"), is(expectedCorsHeader));
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
package org.elasticsearch.rest.action.main;
|
||||
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.elasticsearch.client.ElasticsearchResponse;
|
||||
import org.elasticsearch.client.Response;
|
||||
import org.elasticsearch.common.network.NetworkModule;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.test.ESIntegTestCase;
|
||||
|
@ -40,14 +40,14 @@ public class RestMainActionIT extends ESIntegTestCase {
|
|||
}
|
||||
|
||||
public void testHeadRequest() throws IOException {
|
||||
try (ElasticsearchResponse response = getRestClient().performRequest("HEAD", "/", Collections.emptyMap(), null)) {
|
||||
try (Response response = getRestClient().performRequest("HEAD", "/", Collections.emptyMap(), null)) {
|
||||
assertThat(response.getStatusLine().getStatusCode(), equalTo(200));
|
||||
assertNull(response.getEntity());
|
||||
}
|
||||
}
|
||||
|
||||
public void testGetRequest() throws IOException {
|
||||
try (ElasticsearchResponse response = getRestClient().performRequest("GET", "/", Collections.emptyMap(), null)) {
|
||||
try (Response response = getRestClient().performRequest("GET", "/", Collections.emptyMap(), null)) {
|
||||
assertThat(response.getStatusLine().getStatusCode(), equalTo(200));
|
||||
assertNotNull(response.getEntity());
|
||||
assertThat(EntityUtils.toString(response.getEntity()), containsString("cluster_name"));
|
||||
|
|
|
@ -32,7 +32,7 @@ import org.elasticsearch.action.search.SearchResponse;
|
|||
import org.elasticsearch.action.support.ActionFilter;
|
||||
import org.elasticsearch.action.termvectors.MultiTermVectorsRequest;
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.client.ElasticsearchResponse;
|
||||
import org.elasticsearch.client.Response;
|
||||
import org.elasticsearch.common.inject.AbstractModule;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.inject.Module;
|
||||
|
@ -218,7 +218,7 @@ public class ContextAndHeaderTransportIT extends ESIntegTestCase {
|
|||
restController.registerRelevantHeaders(relevantHeaderName);
|
||||
}
|
||||
|
||||
try (ElasticsearchResponse response = getRestClient().performRequest(
|
||||
try (Response response = getRestClient().performRequest(
|
||||
"GET", "/" + queryIndex + "/_search", Collections.emptyMap(), null,
|
||||
new BasicHeader(randomHeaderKey, randomHeaderValue), new BasicHeader(relevantHeaderName, randomHeaderValue))) {
|
||||
assertThat(response.getStatusLine().getStatusCode(), equalTo(200));
|
||||
|
|
|
@ -22,7 +22,7 @@ package org.elasticsearch.test.rest;
|
|||
import com.carrotsearch.randomizedtesting.RandomizedTest;
|
||||
import org.apache.lucene.util.IOUtils;
|
||||
import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksAction;
|
||||
import org.elasticsearch.client.ElasticsearchResponseException;
|
||||
import org.elasticsearch.client.ResponseException;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.SuppressForbidden;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
|
@ -276,9 +276,9 @@ public abstract class ESRestTestCase extends ESTestCase {
|
|||
deleteIndicesArgs.put("index", "*");
|
||||
try {
|
||||
adminExecutionContext.callApi("indices.delete", deleteIndicesArgs, Collections.emptyList(), Collections.emptyMap());
|
||||
} catch (ElasticsearchResponseException e) {
|
||||
} catch (ResponseException e) {
|
||||
// 404 here just means we had no indexes
|
||||
if (e.getElasticsearchResponse().getStatusLine().getStatusCode() != 404) {
|
||||
if (e.getResponse().getStatusLine().getStatusCode() != 404) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
package org.elasticsearch.test.rest;
|
||||
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.client.ElasticsearchResponseException;
|
||||
import org.elasticsearch.client.ResponseException;
|
||||
import org.elasticsearch.common.logging.ESLogger;
|
||||
import org.elasticsearch.common.logging.Loggers;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
|
@ -78,7 +78,7 @@ public class RestTestExecutionContext implements Closeable {
|
|||
//we always stash the last response body
|
||||
stash.stashResponse(response);
|
||||
return response;
|
||||
} catch(ElasticsearchResponseException e) {
|
||||
} catch(ResponseException e) {
|
||||
response = new RestTestResponse(e);
|
||||
throw e;
|
||||
}
|
||||
|
|
|
@ -33,8 +33,8 @@ import org.apache.http.message.BasicHeader;
|
|||
import org.apache.http.ssl.SSLContexts;
|
||||
import org.apache.lucene.util.IOUtils;
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.client.ElasticsearchResponse;
|
||||
import org.elasticsearch.client.ElasticsearchResponseException;
|
||||
import org.elasticsearch.client.Response;
|
||||
import org.elasticsearch.client.ResponseException;
|
||||
import org.elasticsearch.client.RestClient;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.io.PathUtils;
|
||||
|
@ -106,8 +106,8 @@ public class RestTestClient implements Closeable {
|
|||
//we don't really use the urls here, we rely on the client doing round-robin to touch all the nodes in the cluster
|
||||
String method = restApi.getMethods().get(0);
|
||||
String endpoint = restApi.getPaths().get(0);
|
||||
ElasticsearchResponse elasticsearchResponse = restClient.performRequest(method, endpoint, Collections.emptyMap(), null);
|
||||
RestTestResponse restTestResponse = new RestTestResponse(elasticsearchResponse);
|
||||
Response response = restClient.performRequest(method, endpoint, Collections.emptyMap(), null);
|
||||
RestTestResponse restTestResponse = new RestTestResponse(response);
|
||||
Object latestVersion = restTestResponse.evaluate("version.number");
|
||||
if (latestVersion == null) {
|
||||
throw new RuntimeException("elasticsearch version not found in the response");
|
||||
|
@ -143,7 +143,7 @@ public class RestTestClient implements Closeable {
|
|||
entity = new StringEntity(body, RestClient.JSON_CONTENT_TYPE);
|
||||
}
|
||||
// And everything else is a url parameter!
|
||||
ElasticsearchResponse response = restClient.performRequest(method, path, queryStringParams, entity);
|
||||
Response response = restClient.performRequest(method, path, queryStringParams, entity);
|
||||
return new RestTestResponse(response);
|
||||
}
|
||||
|
||||
|
@ -247,11 +247,11 @@ public class RestTestClient implements Closeable {
|
|||
|
||||
logger.debug("calling api [{}]", apiName);
|
||||
try {
|
||||
ElasticsearchResponse response = restClient.performRequest(requestMethod, requestPath,
|
||||
Response response = restClient.performRequest(requestMethod, requestPath,
|
||||
queryStringParams, requestBody, requestHeaders);
|
||||
return new RestTestResponse(response);
|
||||
} catch(ElasticsearchResponseException e) {
|
||||
if (ignores.contains(e.getElasticsearchResponse().getStatusLine().getStatusCode())) {
|
||||
} catch(ResponseException e) {
|
||||
if (ignores.contains(e.getResponse().getStatusLine().getStatusCode())) {
|
||||
return new RestTestResponse(e);
|
||||
}
|
||||
throw e;
|
||||
|
|
|
@ -21,8 +21,8 @@ package org.elasticsearch.test.rest.client;
|
|||
import org.apache.http.client.methods.HttpHead;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.apache.lucene.util.IOUtils;
|
||||
import org.elasticsearch.client.ElasticsearchResponse;
|
||||
import org.elasticsearch.client.ElasticsearchResponseException;
|
||||
import org.elasticsearch.client.Response;
|
||||
import org.elasticsearch.client.ResponseException;
|
||||
import org.elasticsearch.test.rest.Stash;
|
||||
import org.elasticsearch.test.rest.json.JsonPath;
|
||||
|
||||
|
@ -35,11 +35,11 @@ import java.nio.charset.StandardCharsets;
|
|||
*/
|
||||
public class RestTestResponse {
|
||||
|
||||
private final ElasticsearchResponse response;
|
||||
private final Response response;
|
||||
private final String body;
|
||||
private JsonPath parsedResponse;
|
||||
|
||||
public RestTestResponse(ElasticsearchResponse response) {
|
||||
public RestTestResponse(Response response) {
|
||||
this.response = response;
|
||||
if (response.getEntity() != null) {
|
||||
try {
|
||||
|
@ -55,8 +55,8 @@ public class RestTestResponse {
|
|||
}
|
||||
}
|
||||
|
||||
public RestTestResponse(ElasticsearchResponseException responseException) {
|
||||
this.response = responseException.getElasticsearchResponse();
|
||||
public RestTestResponse(ResponseException responseException) {
|
||||
this.response = responseException.getResponse();
|
||||
this.body = responseException.getResponseBody();
|
||||
}
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
*/
|
||||
package org.elasticsearch.test.rest.section;
|
||||
|
||||
import org.elasticsearch.client.ElasticsearchResponseException;
|
||||
import org.elasticsearch.client.ResponseException;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.collect.Tuple;
|
||||
import org.elasticsearch.common.logging.ESLogger;
|
||||
|
@ -102,7 +102,7 @@ public class DoSection implements ExecutableSection {
|
|||
}
|
||||
fail(formatStatusCodeMessage(restTestResponse, catchStatusCode));
|
||||
}
|
||||
} catch(ElasticsearchResponseException e) {
|
||||
} catch(ResponseException e) {
|
||||
RestTestResponse restTestResponse = new RestTestResponse(e);
|
||||
if (!Strings.hasLength(catchParam)) {
|
||||
fail(formatStatusCodeMessage(restTestResponse, "2xx"));
|
||||
|
@ -111,7 +111,7 @@ public class DoSection implements ExecutableSection {
|
|||
} else if (catchParam.length() > 2 && catchParam.startsWith("/") && catchParam.endsWith("/")) {
|
||||
//the text of the error message matches regular expression
|
||||
assertThat(formatStatusCodeMessage(restTestResponse, "4xx|5xx"),
|
||||
e.getElasticsearchResponse().getStatusLine().getStatusCode(), greaterThanOrEqualTo(400));
|
||||
e.getResponse().getStatusLine().getStatusCode(), greaterThanOrEqualTo(400));
|
||||
Object error = executionContext.response("error");
|
||||
assertThat("error was expected in the response", error, notNullValue());
|
||||
//remove delimiters from regex
|
||||
|
|
Loading…
Reference in New Issue