views:

291

answers:

3

I have two Tomcat servers on my machine that communicate with one another.

1) Can someone recommend on a good (free) network sniffer so I'll be able to monitor the requests/ response that being sent between them?

2) How can I inspect the request in java code? to see what the header and the body consists and their structures?

thanks a lot, from some reason #2 is not as straight forward as i thought it would be.

Me

+2  A: 

I like Wireshark.

If you're on Windows, you can't directly monitor the 127.0.0.1 loopback. You will need to set up an alternate loopback adapter (the same functionality on another address). This is detailed in the Wireshark docs:

http://wiki.wireshark.org/CaptureSetup/Loopback

I'm not sure what you mean by your second question, can you go into more detail?

If all your requests are HTTP-based, then Wireshark will be able to show the headers and body data, but it's outside the context of the Java code.

Tim Sylvester
+2  A: 

1) Wireshark is "the" network sniffer.But if your on windows and want a quick and easy way to see http traffic have a look at Fiddler.Its an IE plugin but can monitor all http traffic from your machine.

2) In the servlet or better yet the servlet filter add the following.

Enumeration headerNames = request.getHeaderNames();
    while(headerNames.hasMoreElements()) {
      String headerName = (String)headerNames.nextElement();
      out.println("<TR><TD>" + headerName);
      out.println("    <TD>" + request.getHeader(headerName));
    }
Jimmy
FWIW, Fiddler isn't really an IE Plugin. It's a standalone proxy debugger. The only IE Integration it has is that it adds a button to IE's toolbar to launch it, but it does the same for Firefox.
EricLaw -MSFT-
A: 

How about setting up the Tomcat servers for remote debugging for number 2? Add a break point so you can inspect the objects? http://wiki.apache.org/tomcat/FAQ/Developing

MikeJ
i have done it but i had troubles inspecting the request, that's what question number 2 about...
special0ne