title: Log all network interactions of Java application
body: <p>I have a monstrous Java app (a client of little-known application server GNUEnterprise) and its source, which I can compile back after making some changes to it. The app uses network heavily and I need to monitor each request and response. I could use a sniffer like Wireshark, but the application works with its server over SSL, so not knowing SSL-certificate's private key any sniffed traffic is pretty useless.</p>
  
  <p>What can I do to make every request and response to be logged from the application itself? I need to see all sent and received headers. I don't want to alter all code responsible for network interaction. What I want is to put a code like</p>
  
  <pre><code>Network.setDefaultLogger(myCustomLoggerInstance);
  </code></pre>
  
  <p>somewhere near start of the app and then in the <code>myCustomLoggerInstance</code> do all the logging I need.</p>
  
  <p>Also, given all network operations are made with <code>URLConnection</code>s, I can get response headers with <code>con.getHeaderFields()</code> and request headers with <code>con.getRequestProperties()</code>. But why cookies aren't there? How to dump sent and received cookies in the same way?</p>
  
  <p><strong>EDIT</strong>: What I'm trying to reach is to mimic RPC-application's communication with it's server over SSL, say, using <code>curl</code>. For this I need to get detailed log of app's network traffic.</p>