Charles is not capturing HTTP requests from a Java client (client is based on spring rest template) in my MAC pro
Asked Answered
L

2

6

Environment: MAC Proc

I have looked at HTTP Traffic monitoring issue when using MonoTouch, HttpClient and Charles Proxy.

Although my question is similar to it, my application is using RestTemplate http://docs.spring.io/autorepo/docs/spring-android/1.0.x/reference/html/rest-template.html. I am able to capture HTTP and HTTPS traffic whenever request is through web browsers (Safari and Chrome to be specific), whereas when I make rest requests through my application (which is basically using RestTemplate) Charles proxy is not capturing them.

From the answers to the above questions, it should be something related setting proxy setting on the RestTempate. But am a .NET developer and quite familiar with fiddler - but recently moved to Java and new to Charles - so it will be great if you can let me know specific details, or your thoughts on configuring rest template to use my mac os proxy...

Basically question is how to configure my rest template (client) such that the charles web proxy is able to capture the requests and responses through my application (client).

And rest template is instantiated by custom request factory which extends __https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/http/client/SimpleClientHttpRequestFactory.html.


Looks like I need to do something similar to this (reference: http://docs.spring.io/spring-integration/reference/html/http.html#http-proxy)

<bean id="requestFactory"
    class="org.springframework.http.client.SimpleClientHttpRequestFactory">
    <property name="proxy">
        <bean id="proxy" class="java.net.Proxy">
            <constructor-arg>
                <util:constant static-field="java.net.Proxy.Type.HTTP"/>
            </constructor-arg>
            <constructor-arg>
                <bean class="java.net.InetSocketAddress">
                    <constructor-arg value="123.0.0.1"/>
                    <constructor-arg value="8080"/>
                </bean>
            </constructor-arg>
        </bean>
    </property>
</bean>
Longdrawn answered 26/10, 2015 at 0:11 Comment(0)
M
3

I also had a similar problem. But I was using JUnit and core Java. Below is a link that helped in a few cases for me.

https://www.charlesproxy.com/documentation/configuration/browser-and-system-configuration/

you can go to JAVA APPLICATION PROXY CONFIGURATION to find the answer.

You can configure your Java application to use Charles in code or as command line arguments to the java executable.

System.setProperty("http.proxyHost", "127.0.0.1");

System.setProperty("http.proxyPort", "8888");

And for HTTPS as well. Note that you may also want to configure Java to trust Charles’s root certificate in this case (see SSL Proxying).

Martinemartineau answered 17/6, 2016 at 7:13 Comment(1)
This didn't work for me. I have added it as vm param as well. But none of them worked.Portly
S
0

you can not do that in tomcat level, you must config proxy in RestTemplate. Reference this https://mcmap.net/q/670625/-how-to-set-proxy-host-on-httpclient-request-in-java, although it use HttpClient but I think you can find a same way for RestTemplate

Serle answered 27/9, 2019 at 7:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.