Search in sources :

Example 66 with Response

use of org.graylog.shaded.elasticsearch7.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"));
}
Also used : Response(org.elasticsearch.client.Response)

Example 67 with Response

use of org.graylog.shaded.elasticsearch7.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));
}
Also used : Response(org.elasticsearch.client.Response) ResponseException(org.elasticsearch.client.ResponseException)

Example 68 with Response

use of org.graylog.shaded.elasticsearch7.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));
}
Also used : Response(org.elasticsearch.client.Response) RestClient(org.elasticsearch.client.RestClient) BasicHeader(org.apache.http.message.BasicHeader)

Example 69 with Response

use of org.graylog.shaded.elasticsearch7.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"));
}
Also used : Response(org.elasticsearch.client.Response) ResponseException(org.elasticsearch.client.ResponseException) BasicHeader(org.apache.http.message.BasicHeader)

Example 70 with Response

use of org.graylog.shaded.elasticsearch7.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));
    }
}
Also used : SearchResponse(org.elasticsearch.action.search.SearchResponse) Response(org.elasticsearch.client.Response) BasicHeader(org.apache.http.message.BasicHeader)

Aggregations

Response (org.elasticsearch.client.Response)111 Request (org.elasticsearch.client.Request)38 IOException (java.io.IOException)33 HttpEntity (org.apache.http.HttpEntity)24 NStringEntity (org.apache.http.nio.entity.NStringEntity)21 Test (org.junit.Test)20 HashMap (java.util.HashMap)17 Map (java.util.Map)14 BasicHeader (org.apache.http.message.BasicHeader)14 ResponseException (org.elasticsearch.client.ResponseException)12 JsonNode (com.fasterxml.jackson.databind.JsonNode)11 RestClient (org.elasticsearch.client.RestClient)11 ArrayList (java.util.ArrayList)10 RestBulkItemResponse (org.janusgraph.diskstorage.es.rest.RestBulkResponse.RestBulkItemResponse)10 StringEntity (org.apache.http.entity.StringEntity)9 SearchResponse (org.elasticsearch.action.search.SearchResponse)9 InputStream (java.io.InputStream)8 JSONObject (org.json.simple.JSONObject)8 MultiSearchResponse (org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.MultiSearchResponse)7 Response (org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Response)7