title: elasticsearch authentication with java api client
body: <p>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.</p>
  
  <p>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.</p>
  
  <p>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:</p>
  
  <pre><code>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));
  </code></pre>
  
  <p>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:</p>
  
  <pre><code> 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)
  </code></pre>
  
  <p>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.</p>
  
  <p>This might seem to be trivial for some of you - but for me it's my first dive in Java/elasticsearch world ... </p>
  
  <p><strong>Update</strong> - 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;</p>