title: Getting "javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake" on Glassfish, not using java
body: <p>I am getting the <code>javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake error</code> when I lauch my code in glassfish, It runs well with java ... </p>
  
  <p>Full stack trace:</p>
  
  <pre><code>2016-01-27T17:26:47.078+0100|Avertissement: Caught exception executing step: com.ibm.jbatch.container.exception.BatchContainerRuntimeException: javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake
  
  at com.ibm.jbatch.container.artifact.proxy.BatchletProxy.process(BatchletProxy.java:36)
  at com.ibm.jbatch.container.impl.BatchletStepControllerImpl.invokeBatchlet(BatchletStepControllerImpl.java:79)
  at com.ibm.jbatch.container.impl.BatchletStepControllerImpl.invokeCoreStep(BatchletStepControllerImpl.java:107)
  at com.ibm.jbatch.container.impl.BaseStepControllerImpl.execute(BaseStepControllerImpl.java:144)
  at com.ibm.jbatch.container.impl.ExecutionTransitioner.doExecutionLoop(ExecutionTransitioner.java:112)
  at com.ibm.jbatch.container.impl.JobThreadRootControllerImpl.originateExecutionOnThread(JobThreadRootControllerImpl.java:110)
  at com.ibm.jbatch.container.util.BatchWorkUnit.run(BatchWorkUnit.java:80)
  at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
  at java.util.concurrent.FutureTask.run(FutureTask.java:262)
  at org.glassfish.enterprise.concurrent.internal.ManagedFutureTask.run(ManagedFutureTask.java:141)
  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
  at java.lang.Thread.run(Thread.java:724)
  at org.glassfish.enterprise.concurrent.ManagedThreadFactoryImpl$ManagedThread.run(ManagedThreadFactoryImpl.java:250)
  
  Caused by: javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake
  at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:946)
  at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1312)
  at sun.security.ssl.SSLSocketImpl.writeRecord(SSLSocketImpl.java:702)
  at sun.security.ssl.AppOutputStream.write(AppOutputStream.java:122)
  at sun.nio.cs.StreamEncoder.writeBytes(StreamEncoder.java:221)
  at sun.nio.cs.StreamEncoder.implFlushBuffer(StreamEncoder.java:291)
  at sun.nio.cs.StreamEncoder.implFlush(StreamEncoder.java:295)
  at sun.nio.cs.StreamEncoder.flush(StreamEncoder.java:141)
  at java.io.OutputStreamWriter.flush(OutputStreamWriter.java:229)
  at javaeetutorial.batch.webserverlog.---
  at com.ibm.jbatch.container.artifact.proxy.BatchletProxy.process(BatchletProxy.java:33)
  ... 13 more
  
  Caused by: java.io.EOFException: SSL peer shut down incorrectly
  at sun.security.ssl.InputRecord.read(InputRecord.java:482)
  at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:927)
  ... 23 more
  </code></pre>
  
  <p>I already spent 3 days reading all the posts. Is there something to do with that: <a href="https://java.net/jira/browse/GLASSFISH-21416" rel="nofollow">https://java.net/jira/browse/GLASSFISH-21416</a> ?</p>
  
  <p><strong>EDIT</strong>
  That's the code: (it crashes in glassfish at <code>writer.flush</code>)</p>
  
  <pre><code>import java.io.BufferedReader;
  import java.io.IOException;
  import java.io.InputStreamReader;
  import java.io.OutputStreamWriter;
  import javax.net.ssl.*;
  
  public class Test {
  
      // substitute your own username and password
      private static final String initiation_command = "live username ***** password *******" + "\n";
  
      public static void main(String[] args) {
          String machineName = "firehose.flightaware.com";
          int port = 1501;
          RunClient(machineName, port);
          System.out.println(" Thank you for using FlightAware ... bye now");
      }
  
      public static void RunClient(String machineName, int port) {
          System.out.println(" Running Client");
          try {
              SSLSocket ssl_socket;
              ssl_socket = (SSLSocket) SSLSocketFactory.getDefault().createSocket(machineName, port);
              // enable certifcate validation:
              SSLParameters sslParams = new SSLParameters();
              sslParams.setEndpointIdentificationAlgorithm("HTTPS");
              ssl_socket.setSSLParameters(sslParams);
  
              //send your initiantion command
              OutputStreamWriter writer = new OutputStreamWriter(ssl_socket.getOutputStream(), "UTF8");
              writer.write(initiation_command);
              writer.flush();
  
              // read messages from FlightAware
              BufferedReader reader = new BufferedReader(new InputStreamReader(ssl_socket.getInputStream()));
  
              String message = null;
              int limit = 10; //limit number messages for testing
              while (limit &gt; 0 &amp;&amp; (message = reader.readLine()) != null) {
                  System.out.println("msg: " + message);
              }
  
              //done, close everything
              writer.close();
              reader.close();
              ssl_socket.close();
  
          } catch (IOException e) {
              e.printStackTrace();
          }
      }
  }
  </code></pre>