Condividi tramite


Capture Java VM Traffic using Fiddler

Customer's using the Azure SDK for Java may need to capture network traffic for the REST API requests to troubleshoot issues. Below are the steps to configure Fiddler and Eclipse to capture the API requests. Telerik provides documentation for configuring your Java app to send traffic to Fiddler available here, however, additional steps will be need to capture secure traffic which is provided in this article. Other development tools can be used but this article covers Eclipse and IntelliJ IDEA. To use other tools, use the VM arguments described in either the Eclipse or IntelliJ IDEA sections.

 

Prerequisites

 

Networking Tracing-

 

Fiddler - https://www.telerik.com/download/fiddler

 

Development Tools

 

Eclipse - https://www.eclipse.org/downloads/

or

IntelliJ IDEA Community - https://www.jetbrains.com/idea/download/

 

Configuring Fiddler

 

By default, Fiddler is not configured to decode any encoded traffic. To enable this feature you can select an encoded request/response and select the "click to decode" message.

 

TIP: Stop capturing of all traffic from Fiddler by pressing f12. All traffic sent from the Java App will still be captured in Fiddler when traffic is sent using the proxy settings. This makes it easier to troubleshoot the requests coming from the app.

 

fiddler-decode

You will also need to perform the following.

 

1) Select the Tools menu.

2) Choose Telerik Fiddler Options.

3) Select the HTTPS tab and check the following

  1. Capture HTTPS CONNECTs
  2. Decrypt HTTPS Traffic

fiddler-options

 

4) We'll need to export the certificate used by Fiddler to use with Eclipse later. Perform the following.

  1. Select the "Actions" button.
  2. Choose "Export Root Certificate to Desktop. Press the OK button.

fiddler-export

 

5) To create a keystore with this certificate, perform the following.

  1. Open the command line as administrator.
  2. echo %JAVA_HOME%
  3. Change directories to the variable provided (I.e. C:\Program Files\Java\jdk1.8.0_121 in my case).
  4. Cd bin
  5. keytool.exe -import -file C:\Users\<username>\Desktop\FiddlerRoot.cer -keystore FiddlerKeystore -alias Fiddler
  6. Enter a password and confirm the password.
  7. Trust this certificate? [no]: y
  8. Example screenshot below.

fiddler-keystore

 

Configure Eclipse

 

1) In Eclipse, select the Run menu and choose "Run Configurations".

eclipse-1

2) Select your Project and choose the "Arguments" tab.

3) Enter the following in the VM arguments section.

 

 -DproxySet=true 
-DproxyHost=127.0.0.1 
-DproxyPort=8888
-Djavax.net.ssl.trustStore="path\to\java_home\bin\FiddlerKeyStore" 
-Djavax.net.ssl.trustStorePassword="password_used_during_keystore_creation"

 

4) Press Apply and Run.

eclipse-2

 

Configuring IntelliJ IDEA

 

1) Select the Run menu and choose "Edit Configurations"

intellij-1

2) Select your Java Application on the left and enter the following "VM Options".

 

 -DproxySet=true 
-DproxyHost=127.0.0.1 
-DproxyPort=8888 
-Djavax.net.ssl.trustStore="path\to\java_home\bin\FiddlerKeyStore" 
-Djavax.net.ssl.trustStorePassword="password_used_during_keystore_creation"

 

 

3) Press OK, Apply, and Run the App.

intellij-2

Fiddler Capture Examples

 

1) HTTP 401 response showing the JSON output for the authentication request from the Azure SDK for Java.

fiddler-sample1

 

2) HTTP 200 with JSON response for a REST API to the Azure Resource Management Service from the Azure SDK for Java

fiddler-sample2