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 use
If you want to log network traffic & you have URLConnection objects then the problem is already solved!
If you want to log at stream level, you need to write a little wrapper on top of your I/O streams & log all data before transfer them to lower network layers, otherwise you can use connection objects directly to get required info & log them.
For managing cookies, you should use java.net.HttpCookie
which is introduced in java 6. Only thing you have to do is to create an instance of CookieManager & set it as default cookie manager:
CookieManager cookieManager = new CookieManager();
CookieHandler.setDefault(cookieManager);
& you can use it for managing connection cookies!