elasticsearch authentication with java api client

3k views Asked by At

I have an authentication issue using elasticsearch (2.3) with shield. The elasticsearch instance is hosted somewhere on a cloud and I don't have much access for tweaking.

I am using the Sense chrome-plugin to make test requests and just before sending the first request it asks for username/pwd (I assume it's some kind of Basic HTTP Auth for the REST api interface). All queries went fine with the Sense plugin.

Now, I have to use Java API to make queries against this instance in a client application. I created the TransportClient, all like in the following snippet:

String hostBasedClusterName = StatsConstants.ES_HOST.split("\\.", 2)[0];
String clusterName = System.getProperty("cluster", hostBasedClusterName);

Settings settings = Settings.settingsBuilder()
                        .put("cluster.name", clusterName)
                        .put("shield.transport.ssl", "true")
                        .put("shield.user", String.format("%s:%s", StatsConstants.ES_USERNAME, StatsConstants.ES_PASSWORD))
                        .build();

client = TransportClient.builder()
                         .addPlugin(ShieldPlugin.class)
                         .settings(settings)
                         .build()
                         .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(StatsConstants.ES_HOST), StatsConstants.ES_PORT));

Based on other samples and the docs, it seems to be fine. However, when I am trying to create the client, I am getting a StreamCorruptedException exception:

 2016-05-13 13:53:47,396  WARN netty:788 - NettyTransport.java - [Burstarr] exception caught on transport layer [[id: 0x4ac12d10, ...]], closing connection
 java.io.StreamCorruptedException: invalid internal transport message format, got (48,54,54,50)
      at org.elasticsearch.transport.netty.SizeHeaderFrameDecoder.decode(SizeHeaderFrameDecoder.java:68)
      at org.jboss.netty.handler.codec.frame.FrameDecoder.callDecode(FrameDecoder.java:425)
      at org.jboss.netty.handler.codec.frame.FrameDecoder.messageReceived(FrameDecoder.java:303)
      at org.jboss.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:70)

The client version is 2.3.2, using the shield client lib as described in the docs, compilation is fine, no warning, it's just when it tries to create that object, it throws an exception.

This might seem to be trivial for some of you - but for me it's my first dive in Java/elasticsearch world ...

Update - after I did some more digging/reading, I found a similar error/exception when someone complained about the proxy used. I do not use any proxy and it's a direct connection to the server;

1

There are 1 answers

0
dcg On BEST ANSWER

Problem solved. Adding here the response to ease the burden on some other poor soul ...

Coming from a solr background, I was trying to connect to the same port as the webservice (http/https). Well, that was totally wrong. I should have connected to port 9343.