Using Fiddler to Capture Http Requests of a Java Application


Task1: Using Fiddler as a Proxy to Monitor Request from a Java Application
To configure a Java application to send web traffic to Fiddler, add the following parameters to JVM:
-Dhttp.proxyHost=proxyHost -Dhttp.proxyPort=8888

The proxy - here is the Fiddler and the java application can be run in different machines. In this case, ensure allow remote clients to connect is checked by clicking "Tools" -> "Fiddler Options" -> "Connections" -> "Allow remote computers to connect". Then restart Fiddler.

Use Apache Http Client SystemDefaultHttpClient
If you are using Apache Http Client 4.2 or newer, we can use SystemDefaultHttpClient which honor standard system properties.

In 4.3 or newer, we can use HttpClientBuilder, which also honors these system properties.
HttpClient client = HttpClientBuilder.create().build();

Task2: Monitor Requests in Web Server
We want to monitor request and response in Java web server, for example: the web server is running at server1:8080.

Solution: Using Fiddler as a Reverse Proxy
We can use fiddler as a reverse proxy, first we change Fidder to listen on Port 8080 by right clicking "Tools" -> "Fiddler Options" -> "Connections": change port number and allow remote computers to connect, then restart Fiddler if prompted.

Then change web server to run at another port, for example: 9090.

Create a FiddlerScript Rule
Then write a custom rule to tell Fidder to forward requests to server1:8080(the port Fiddler is listening) to server1:9090 where the real web server is listening.

Click Rules > Customize Rules.
Inside the OnBeforeRequest handler*, add a new line of code:
if (oSession.host.toLowerCase() == "server1:8080") oSession.host = "server1:9090";

Troubleshooting: Enable "Help" -> "Troubleshooting Filters..." 
If for some reason, fiddler is not capturing the request, we can enable option: "Help" -> "Troubleshooting Filters...". This will show all traffic but strike out the requests that would be excluded by the filter.  It also provides a comment about why the request would be hidden. 

Resources
The Fiddler Proxy
Using Fiddler as a Reverse Proxy

Labels

adsense (5) Algorithm (69) Algorithm Series (35) Android (7) ANT (6) bat (8) Big Data (7) Blogger (14) Bugs (6) Cache (5) Chrome (19) Code Example (29) Code Quality (7) Coding Skills (5) Database (7) Debug (16) Design (5) Dev Tips (63) Eclipse (32) Git (5) Google (33) Guava (7) How to (9) Http Client (8) IDE (7) Interview (88) J2EE (13) J2SE (49) Java (186) JavaScript (27) JSON (7) Learning code (9) Lesson Learned (6) Linux (26) Lucene-Solr (112) Mac (10) Maven (8) Network (9) Nutch2 (18) Performance (9) PowerShell (11) Problem Solving (11) Programmer Skills (6) regex (5) Scala (6) Security (9) Soft Skills (38) Spring (22) System Design (11) Testing (7) Text Mining (14) Tips (17) Tools (24) Troubleshooting (29) UIMA (9) Web Development (19) Windows (21) xml (5)