Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Log all network interactions of Java application

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.

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

Network.setDefaultLogger(myCustomLoggerInstance); 

somewhere near start of the app and then in the myCustomLoggerInstance do all the logging I need.

Also, given all network operations are made with URLConnections, I can get response headers with con.getHeaderFields() and request headers with con.getRequestProperties(). But why cookies aren't there? How to dump sent and received cookies in the same way?

EDIT: What I'm trying to reach is to mimic RPC-application's communication with it's server over SSL, say, using curl. For this I need to get detailed log of app's network traffic.

like image 571
Hnatt Avatar asked Aug 29 '13 13:08

Hnatt


People also ask

Which logging framework is best for Java?

One of the most popular solutions for the Java world is the Apache Log4j 2 framework. Maintained by the Apache Foundation, Log4j 2 is an improvement on the original Log4j, which was the most popular logging framework in Java for many years.

What is a logger Java?

A Logger object is used to log messages for a specific system or application component. Loggers are normally named, using a hierarchical dot-separated namespace. Logger names can be arbitrary strings, but they should normally be based on the package name or class name of the logged component, such as java.net or javax.

What is logging in Java?

Logging in Java. Java provides the ability to capture the log files. The need for Log capture. There are multiple reasons why we may need to capture the application activity. Recording unusual circumstances or errors that may be happening in the program. Getting the info about whats going in the application.

How is the log system managed?

The log system is centrally managed. There is only one application wide log manager which manages both the configuration of the log system and the objects that do the actual logging. The Log Manager Class provides a single global instance to interact with log files.

What is a network log?

In an application, a network log is typically a file that contains a record of events that occurred in the application. It contains the record of user and process access calls to objects, attempts at authentication, and other activity. Generally, an event is categorized as an error, a warning, or an informational activity.

How to log i/o and cookies in Java?

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.


1 Answers

A quick way to log all SSL traffic is to startup java with:

-Djavax.net.debug=all 

Or set it as a system property:

System.setProperty("javax.net.debug","all"); 

Brace yourself. Standard out gets NOISY if you do this!

(*Note: only logs SSL traffic and SSL debug info (handshakes, etc). Regular sockets are not logged.)

like image 124
Julius Musseau Avatar answered Sep 22 '22 07:09

Julius Musseau