use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Response in project graylog2-server by Graylog2.
the class ElasticsearchFilterDeprecationWarningsInterceptorTest method testInterceptorMultipleHeaderIgnoredWarning.
@Test
public void testInterceptorMultipleHeaderIgnoredWarning() throws IOException, HttpException {
ElasticsearchFilterDeprecationWarningsInterceptor interceptor = new ElasticsearchFilterDeprecationWarningsInterceptor();
HttpResponse response = new BasicHttpResponse(new BasicStatusLine(new ProtocolVersion("HTTP", 0, 0), 0, null));
response.addHeader("Test", "This header should not trigger the interceptor.");
response.addHeader("Warning", "This warning should not trigger the interceptor.");
interceptor.process(response, null);
assertThat(response.getAllHeaders()).as("Number of Headers should be unchanged.").hasSize(2);
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Response in project graylog2-server by Graylog2.
the class ElasticsearchFilterDeprecationWarningsInterceptorTest method testInterceptorMultipleHeaderFilteredWarning.
@Test
public void testInterceptorMultipleHeaderFilteredWarning() throws IOException, HttpException {
ElasticsearchFilterDeprecationWarningsInterceptor interceptor = new ElasticsearchFilterDeprecationWarningsInterceptor();
HttpResponse response = new BasicHttpResponse(new BasicStatusLine(new ProtocolVersion("HTTP", 0, 0), 0, null));
response.addHeader("Test", "This header should not trigger the interceptor.");
response.addHeader("Warning", "This warning should not trigger the interceptor.");
response.addHeader("Warning", "This text contains the trigger: setting was deprecated in Elasticsearch - and should be filtered out");
assertThat(response.getAllHeaders()).as("Number of Headers should be 3 before start.").hasSize(3);
interceptor.process(response, null);
assertThat(response.getAllHeaders()).as("Number of Headers should be 1 less after running the interceptor.").hasSize(2);
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Response in project incubator-gobblin by apache.
the class RestWriterVariant method getTestClient.
@Override
public TestClient getTestClient(Config config) throws IOException {
final ElasticsearchRestWriter restWriter = new ElasticsearchRestWriter(config);
final RestHighLevelClient highLevelClient = restWriter.getRestHighLevelClient();
return new TestClient() {
@Override
public GetResponse get(GetRequest getRequest) throws IOException {
return highLevelClient.get(getRequest);
}
@Override
public void recreateIndex(String indexName) throws IOException {
RestClient restClient = restWriter.getRestLowLevelClient();
try {
restClient.performRequest("DELETE", "/" + indexName);
} catch (Exception e) {
// ok since index may not exist
}
String indexSettings = "{\"settings\" : {\"index\":{\"number_of_shards\":1,\"number_of_replicas\":1}}}";
HttpEntity entity = new StringEntity(indexSettings, ContentType.APPLICATION_JSON);
Response putResponse = restClient.performRequest("PUT", "/" + indexName, Collections.emptyMap(), entity);
Assert.assertEquals(putResponse.getStatusLine().getStatusCode(), 200, "Recreate index succeeded");
}
@Override
public void close() throws IOException {
restWriter.close();
}
};
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Response in project elasticsearch by elastic.
the class ElasticsearchHostsSnifferTests method testSniffNodes.
public void testSniffNodes() throws IOException {
HttpHost httpHost = new HttpHost(httpServer.getAddress().getHostString(), httpServer.getAddress().getPort());
try (RestClient restClient = RestClient.builder(httpHost).build()) {
ElasticsearchHostsSniffer sniffer = new ElasticsearchHostsSniffer(restClient, sniffRequestTimeout, scheme);
try {
List<HttpHost> sniffedHosts = sniffer.sniffHosts();
if (sniffResponse.isFailure) {
fail("sniffNodes should have failed");
}
assertThat(sniffedHosts.size(), equalTo(sniffResponse.hosts.size()));
Iterator<HttpHost> responseHostsIterator = sniffResponse.hosts.iterator();
for (HttpHost sniffedHost : sniffedHosts) {
assertEquals(sniffedHost, responseHostsIterator.next());
}
} 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)));
assertThat(response.getHost(), equalTo(httpHost));
assertThat(response.getStatusLine().getStatusCode(), equalTo(sniffResponse.nodesInfoResponseCode));
assertThat(response.getRequestLine().toString(), equalTo("GET /_nodes/http?timeout=" + sniffRequestTimeout + "ms HTTP/1.1"));
} else {
fail("sniffNodes should have succeeded: " + response.getStatusLine());
}
}
}
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Response in project elasticsearch by elastic.
the class Netty4BadRequestIT method testBadRequest.
public void testBadRequest() throws IOException {
final Response response = client().performRequest("GET", "/_nodes/settings", Collections.emptyMap());
final ObjectPath objectPath = ObjectPath.createFromResponse(response);
final Map<String, Object> map = objectPath.evaluate("nodes");
int maxMaxInitialLineLength = Integer.MIN_VALUE;
final Setting<ByteSizeValue> httpMaxInitialLineLength = HttpTransportSettings.SETTING_HTTP_MAX_INITIAL_LINE_LENGTH;
final String key = httpMaxInitialLineLength.getKey().substring("http.".length());
for (Map.Entry<String, Object> entry : map.entrySet()) {
@SuppressWarnings("unchecked") final Map<String, Object> settings = (Map<String, Object>) ((Map<String, Object>) entry.getValue()).get("settings");
final int maxIntialLineLength;
if (settings.containsKey("http")) {
@SuppressWarnings("unchecked") final Map<String, Object> httpSettings = (Map<String, Object>) settings.get("http");
if (httpSettings.containsKey(key)) {
maxIntialLineLength = ByteSizeValue.parseBytesSizeValue((String) httpSettings.get(key), key).bytesAsInt();
} else {
maxIntialLineLength = httpMaxInitialLineLength.getDefault(Settings.EMPTY).bytesAsInt();
}
} else {
maxIntialLineLength = httpMaxInitialLineLength.getDefault(Settings.EMPTY).bytesAsInt();
}
maxMaxInitialLineLength = Math.max(maxMaxInitialLineLength, maxIntialLineLength);
}
final String path = "/" + new String(new byte[maxMaxInitialLineLength], Charset.forName("UTF-8")).replace('\0', 'a');
final ResponseException e = expectThrows(ResponseException.class, () -> client().performRequest(randomFrom("GET", "POST", "PUT"), path, Collections.emptyMap()));
assertThat(e.getResponse().getStatusLine().getStatusCode(), equalTo(BAD_REQUEST.getStatus()));
assertThat(e, hasToString(containsString("too_long_frame_exception")));
assertThat(e, hasToString(matches("An HTTP line is larger than \\d+ bytes")));
}
Aggregations