Tuesday, November 1, 2016

Debugging HTTPS webservices in Java

I recently worked on a RESTful webservice client that accessed the webservice endpoint over HTTPS. This is the preferred communication protocol to ensure that the data transferred between the client and server are encrypted and secure.


Troubleshooting

     One common issue I have seen is that debugging and trouble shooting the webservice invocations can be difficult. This because the SOAP or RESTful frameworks rely on the Java Runtime (JVM) to make the HTTPS connection. This encapsulation hides the transport layer and network layer exceptions from the webservice frameworks.

    It will help troubleshooting if the JVM runtime is configured to log all details of a network call (including HTTPS certificate lookup). 

    Enabling debugging is a simple step. Ensure that this Java runtime argument (-Djavax.net.debug=all) is added to the Java command.

    For standalone Java programs, just add this argument to the Java command.
    $java -jar -Djavax.net.debug=all <JAR file name>

    For Apache Tomcat, edit the the Tomcat/bin/catalina.sh file and append the -Djavax.net.debug=all option to the JAVA_OPTS variable.

    For Java based application servers like IBM Websphere and Oracle Weblogic this option can be added in the Admin console (please refer docs).

    Caution: Enabling debug mode generates a lot of log entries and it should be used only for trouble shooting.

    References: 

  1. This link from Oracle Java docs has more details.     http://docs.oracle.com/javase/7/docs/technotes/guides/security/jsse/ReadDebug.html
  2. This blog post has additional notes related to this post - http://karunsubramanian.com/websphere/how-to-enable-ssl-debugging-in-java/
  3. Full debugging is not the only option. The programmer can debug specific aspects of the JVM. This article shows the various other debugging options available - http://www.ibm.com/support/knowledgecenter/SSYKE2_7.1.0/com.ibm.java.security.component.71.doc/security-component/jsse2Docs/debug.html
  



No comments:

Post a Comment