local host network monitor and httpservlet request
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
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));
}
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.
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
I just used
http://socketsniff.nirsoft-freeware.qarchive.org/_download2.html
and it worked flawlessly for what I wanted.
Shamelessly copied from this question:
Sniffer for localhost (Windows OS)
精彩评论