Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I've been able to log all SSL traffic implementing my own <a href="http://java.sun.com/javase/6/docs/api/javax/net/ssl/SSLSocketFactory.html" rel="nofollow noreferrer">SSLSocketFactory</a> on top of the default one. </p> <p>This worked for me because all of our connections are using HTTPS and we can set the socket factory with the method <a href="http://java.sun.com/javase/6/docs/api/javax/net/ssl/HttpsURLConnection.html#setSSLSocketFactory(javax.net.ssl.SSLSocketFactory)" rel="nofollow noreferrer">HttpsURLConnection.setSSLSocketFactory</a>. </p> <p>A more complete solution that enables monitoring on all sockets can be found at <a href="http://www.javaspecialists.eu/archive/Issue169.html" rel="nofollow noreferrer">http://www.javaspecialists.eu/archive/Issue169.html</a> Thanks to <a href="https://stackoverflow.com/users/8946">Lawrence Dol</a> for pointing in the right direction of using <a href="http://java.sun.com/javase/6/docs/api/java/net/Socket.html#setSocketImplFactory(java.net.SocketImplFactory)" rel="nofollow noreferrer">Socket.setSocketImplFactory</a></p> <p>Here is my not ready for production code:</p> <pre><code>public class WireLogSSLSocketFactory extends SSLSocketFactory { private SSLSocketFactory delegate; public WireLogSSLSocketFactory(SSLSocketFactory sf0) { this.delegate = sf0; } public Socket createSocket(Socket s, String host, int port, boolean autoClose) throws IOException { return new WireLogSocket((SSLSocket) delegate.createSocket(s, host, port, autoClose)); } /* ... */ private static class WireLogSocket extends SSLSocket { private SSLSocket delegate; public WireLogSocket(SSLSocket s) { this.delegate = s; } public OutputStream getOutputStream() throws IOException { return new LoggingOutputStream(delegate.getOutputStream()); } /* ... */ private static class LoggingOutputStream extends FilterOutputStream { private static final Logger logger = Logger.getLogger(WireLogSocket.LoggingOutputStream.class); //I'm using a fixed charset because my app always uses the same. private static final String CHARSET = "ISO-8859-1"; private StringBuffer sb = new StringBuffer(); public LoggingOutputStream(OutputStream out) { super(out); } public void write(byte[] b, int off, int len) throws IOException { sb.append(new String(b, off, len, CHARSET)); logger.info("\n" + sb.toString()); out.write(b, off, len); } public void write(int b) throws IOException { sb.append(b); logger.info("\n" + sb.toString()); out.write(b); } public void close() throws IOException { logger.info("\n" + sb.toString()); super.close(); } } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload