Skip to content

Java sniffer client breaks when "Accept-Encoding" is used as a default header #54865

@ollik1

Description

@ollik1

Elasticsearch version (bin/elasticsearch --version): 7.3.2

Plugins installed: []

JVM version (java -version): openjdk version "11.0.6" 2020-01-14 LTS

OS version (uname -a if on a Unix-like system):Linux 4.9.87-linuxkit-aufs #1 SMP Wed Mar 14 15:12:16 UTC 2018 x86_64 GNU/Linux

Description of the problem including expected versus actual behavior: When using the Java sniffer client with a default header Accept-Encoding: gzip, a JSON deserialization exception is thrown when parsing the response. The sniffer should either clear the header or handle the compressed response. Also throwing an exception when building the sniffer with a REST client with such a default header would be an improvement. In its current state the error message is quite confusing.

Steps to reproduce:

  1. RestClientBuilder builder = RestClient.builder(...).setDefaultHeaders(new Header[] {new BasicHeader(HttpHeaders.ACCEPT_ENCODING, "gzip")});
  2. new ElasticsearchNodesSniffer(restClient).sniff();

Provide logs (if relevant):

com.fasterxml.jackson.core.JsonParseException: Illegal character ((CTRL-CHAR, code 31)): only regular white space (\r, \n, \t) is allowed between tokens
 at [Source: (org.apache.http.nio.entity.ContentInputStream); line: 1, column: 2]

	at com.fasterxml.jackson.core.JsonParser._constructError(JsonParser.java:1840)
	at com.fasterxml.jackson.core.base.ParserMinimalBase._reportError(ParserMinimalBase.java:712)
	at com.fasterxml.jackson.core.base.ParserMinimalBase._throwInvalidSpace(ParserMinimalBase.java:690)
	at com.fasterxml.jackson.core.json.UTF8StreamJsonParser._skipWSOrEnd(UTF8StreamJsonParser.java:2976)
	at com.fasterxml.jackson.core.json.UTF8StreamJsonParser.nextToken(UTF8StreamJsonParser.java:716)
	at org.elasticsearch.client.sniff.ElasticsearchNodesSniffer.readHosts(ElasticsearchNodesSniffer.java:111)
	at org.elasticsearch.client.sniff.ElasticsearchNodesSniffer.sniff(ElasticsearchNodesSniffer.java:105)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions