use of org.elasticsearch.client.Response in project elasticsearch by elastic.
the class CreatedLocationHeaderIT method locationTestCase.
private void locationTestCase(Response response) throws IOException {
assertEquals(201, response.getStatusLine().getStatusCode());
String location = response.getHeader("Location");
assertThat(location, startsWith("/test/test/"));
Response getResponse = client().performRequest("GET", location);
assertEquals(singletonMap("test", "test"), entityAsMap(getResponse).get("_source"));
}
use of org.elasticsearch.client.Response in project elasticsearch by elastic.
the class DetailedErrorsDisabledIT method testThatErrorTraceParamReturns400.
public void testThatErrorTraceParamReturns400() throws IOException {
ResponseException e = expectThrows(ResponseException.class, () -> getRestClient().performRequest("DELETE", "/", Collections.singletonMap("error_trace", "true")));
Response response = e.getResponse();
assertThat(response.getHeader("Content-Type"), is("application/json; charset=UTF-8"));
assertThat(EntityUtils.toString(e.getResponse().getEntity()), containsString("\"error\":\"error traces in responses are disabled.\""));
assertThat(response.getStatusLine().getStatusCode(), is(400));
}
use of org.elasticsearch.client.Response in project elasticsearch by elastic.
the class HttpCompressionIT method testCompressesResponseIfRequested.
public void testCompressesResponseIfRequested() throws IOException {
RestClient client = client();
Response response = client.performRequest("GET", "/", new BasicHeader(HttpHeaders.ACCEPT_ENCODING, GZIP_ENCODING));
assertEquals(200, response.getStatusLine().getStatusCode());
assertEquals(GZIP_ENCODING, response.getHeader(HttpHeaders.CONTENT_ENCODING));
}
use of org.elasticsearch.client.Response in project elasticsearch by elastic.
the class ResponseHeaderPluginIT method testThatSettingHeadersWorks.
public void testThatSettingHeadersWorks() throws IOException {
ensureGreen();
try {
getRestClient().performRequest("GET", "/_protected");
fail("request should have failed");
} catch (ResponseException e) {
Response response = e.getResponse();
assertThat(response.getStatusLine().getStatusCode(), equalTo(401));
assertThat(response.getHeader("Secret"), equalTo("required"));
}
Response authResponse = getRestClient().performRequest("GET", "/_protected", new BasicHeader("Secret", "password"));
assertThat(authResponse.getStatusLine().getStatusCode(), equalTo(200));
assertThat(authResponse.getHeader("Secret"), equalTo("granted"));
}
use of org.elasticsearch.client.Response in project elasticsearch by elastic.
the class ContextAndHeaderTransportIT method testThatRelevantHttpHeadersBecomeRequestHeaders.
public void testThatRelevantHttpHeadersBecomeRequestHeaders() throws IOException {
final String IRRELEVANT_HEADER = "SomeIrrelevantHeader";
Response response = getRestClient().performRequest("GET", "/" + queryIndex + "/_search", new BasicHeader(CUSTOM_HEADER, randomHeaderValue), new BasicHeader(IRRELEVANT_HEADER, randomHeaderValue));
assertThat(response.getStatusLine().getStatusCode(), equalTo(200));
List<RequestAndHeaders> searchRequests = getRequests(SearchRequest.class);
assertThat(searchRequests, hasSize(greaterThan(0)));
for (RequestAndHeaders requestAndHeaders : searchRequests) {
assertThat(requestAndHeaders.headers.containsKey(CUSTOM_HEADER), is(true));
// was not specified, thus is not included
assertThat(requestAndHeaders.headers.containsKey(IRRELEVANT_HEADER), is(false));
}
}
Aggregations