Search code examples
javassl

How do I capture the output of the Java console in a file when debugging a failed SSL handshake?


I want to debug java.io.EOFException: SSL peer shut down incorrectly by viewing the Java debug output. I can't see the Java console when running my application, so I want to store the SSL debug logs in a file:

        System.setProperty("javax.net.ssl.trustStore", "client_truststore.ks");
        System.setProperty("javax.net.ssl.trustStorePassword", "myPass");
        System.setProperty("https.protocols", "TLSv1,TLSv1.1,TLSv1.2");
        System.setProperty("javax.net.debug", "ssl:handshake");
        
        PrintStream out = new PrintStream(new FileOutputStream("./ssl.txt"));
        System.setOut(out);

        URL url = new URL("https://myURL:8080/myService?wsdl");
        QName qname = new QName("http://mynamespace.com", "MyImplService");
        MyServiceagent service = new MyServiceagent(url, qname);
        MyPort port = service.getMyPortPort();

However, nothing is written to ssl.txt. Where is the output going and why isn't it writing to the file?

EDIT:I switched to absolute file paths and can see that the files are being created, but still have no content. javax.net.debug isn't going to either the out or error logs.


Solution

  • The solution is to set these system properties before initializing the server, instead of doing so after creating the server but before the client.