Capture Java VM Traffic using Fiddler

2 minute read | By Toan Nguyen

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

    a) Capture HTTPS CONNECTs

    b) Decrypt HTTPS Traffic

    fiddler-options  

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

    a) Select the “Actions” button.

    b) Choose “Export Root Certificate to Desktop. Press the OK button.

    fiddler-export  

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

    a) Open the command line as administrator.

    b) echo %JAVA_HOME%

    c) Change directories to the variable provided (I.e. C:\Program Files\Java\jdk1.8.0_121 in my case).

    d) cd bin

    e) keytool.exe -import -file C:\Users\\\Desktop\\FiddlerRoot.cer -keystore FiddlerKeystore -alias Fiddler

    f) Enter a password and confirm the password.

    g) Trust this certificate? [no]: y

    h) 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