fiddler and java ws problem - java

Properties systemProps = System.getProperties();
//systemProps.put("proxySet", "true");
systemProps.put("proxyHost", "127.0.0.1");
systemProps.put("proxyPort", "8888");
When I open fiddler I can't see anything. Must I do something else? I use fiddler proxy for sending ws request.

Try starting the application with startup parameters
-DproxyHost=127.0.0.1 -DproxyPort=8888
if that helps, it is probable that your code is called too late or maybe not at all.

Related

Routing java intelij traffic through fiddler

I am attempting to view https requests in Fiddler made by a program in inteliJ.
I have been attempting to use the different methods that are posted on the internet. By the way, this is for one-off testing.
These include:
- Programmatically
- This works, but its not scaleable, and we have to add extra code to ignore ssl certificates. I do not want to pursue this path.
System.setProperty("http.proxyHost", "127.0.0.1");
System.setProperty("https.proxyHost", "127.0.0.1");
System.setProperty("http.proxyPort", "8888");
System.setProperty("https.proxyPort", "8888");
Exporting Fiddler cert
This is the most common thing I am seeing, and I think this is the route that I want to go.
Only issue is that once I use keytool and make sure intelij is seeing it (at least I think I am, I am not sure how to confirm), the tests that I am running fail. They ping another port on the server computer, but as soon as they send a request, they fail.
I am not looking to change the proxy service. Right now fiddler is what I need to use.
I also do not want to do this programattically. I have that working, but its not the solution that I want.
Thank you for your help.

Cannot login into Salesforce with Java using Proxy Server

I wrote Java code to login to Salesforce and ran this code on a firewalled server. For this, I have to specify the proxy url and proxy port before connecting to Salesforce due to the firewall. However, I'm getting an unknownhostexception error for the proxy url. If I try to login via curl with the proxy settings, I am able to connect. How come there is a problem connecting using Java then? Any help is appreciated.
Apparently the issue was caused by JVM configs. We have to configure JVM to use the proxy settings as follows:
System.setProperty("http.proxyHost", crmProxyURL);
System.setProperty("http.proxyPort", crmProxyPort);
Depending on your HTTP library the System settings might not be enough or not needed. In the Salesforce context it is quite possible that one would try using the Jetty HTTP Client. In this case the System properties are ignored and proxy needs to be handled by the Jetty client:
ProxyConfiguration proxyConfig = httpClient.getProxyConfiguration();
HttpProxy proxy = new HttpProxy("proxyHost", proxyPort);
proxyConfig.getProxies().add(proxy);
The Apache HTTP Client, another popular choice, also uses its own little mechanism:
HttpHost proxy = new HttpHost("proxyHost", proxyPort, "https");
RequestConfig config = RequestConfig.custom().setProxy(proxy).build();
HttpGet request = new HttpGet(someURL);
request.setConfig(config);
Interesting here: one can specify to use http or https as the proxy protocol.
In general I found using one of the http client much easier that the JDK low level functions.

Spring-Boot behind a network proxy

I am currently implementing an OpenID authentication based on this example. Now I am developing behind a network proxy, therefore the server cannot connect to google. The java proxy settings seem to not have any effect. I also found this stackoverflow question, but I cannot figure out where to put the code. How can I configure the proxy for my spring boot container?
thanks
Not sure if this is of any use, but I'm just working through a Spring Boot tutorial currently (https://spring.io/guides/gs/integration/) and hit a similar network proxy issue. This was resolved just by providing the JVM arguments
-Dhttp.proxyHost=your.proxy.net -Dhttp.proxyPort=8080
Adding just the two provided arguments didn't work for me.
Full list that did it is this:
-Dhttp.proxyHost=somesite.com -Dhttp.proxyPort=4321
-Dhttps.proxyHost=somesite.com -Dhttps.proxyPort=4321 -Dhttps.proxySet=true
-Dhttp.proxySet=true
If you need this to make a call to an external service, then try to set proxy to the Client you are using (RestTemplate, etc), as below:
HttpComponentsClientHttpRequestFactory requestFactory = new
HttpComponentsClientHttpRequestFactory();
DefaultHttpClient httpClient = (DefaultHttpClient) requestFactory.getHttpClient();
HttpHost proxy = new HttpHost("proxtserver", port);
httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY,proxy);
restTemplate.setRequestFactory(requestFactory);
For me, server.use-forwarded-headers=true in application.properties solved the problem.
I could able to solve the problem in two methods
Through JVM args (both http & https)
-Dhttp.proxyHost=your-http-proxy-host -Dhttp.proxyPort=8080
-Dhttps.proxyHost=your-https-proxy-host -Dhttps.proxyPort=8080
Or Programatically
public static void setProxy() {
System.setProperty("http.proxyHost", "your-http-proxy-host");
System.setProperty("http.proxyPort", "8080");
System.setProperty("https.proxyHost", "your-http-proxy-host");
System.setProperty("https.proxyPort", "8080");
}

how to set proxy for firefox using java?

I am trying to develop an app which will take ip address as a input and set it as a proxy in clients firefox as a proxy. The idea here is , I am trying to gain access to squid server through java? is there any possibility of doing so? Thanks in advance
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).
System.setProperty("https.proxyHost", "127.0.0.1");
System.setProperty("https.proxyPort", "8888");
proxy settings for Firefox are stored in prefs.js file of user
%APPDATA%\Mozilla\Firefox\Profiles\7a3fd5zw.default\prefs.js
here 7a3fd5zw is a random string.
There are settings named "network.proxy.http" and "network.proxy.http_port".
May be, you can try to modify them.

how to test proxy internet connection using java?

i have some code to test if the proxy server and port is working ,some of the code like this:
System.getProperties().put("proxySet", "true");
System.getProperties().put("https.proxyHost", "localhost");
System.getProperties().put("https.proxyPort", "1234");
System.getProperties().put("http.proxyHost", "localhost");
System.getProperties().put("http.proxyPort", "1234");
HttpURLConnection conn = (HttpURLConnection) new URL("https://www.google.com").openConnection();
conn.getContent();
conn.disconnect();
it seems that openConnection() method will do thing like this:
try to connect given URL using proxy.
if it fails to use proxy,it will connect URL directly without proxy.
that's the problem,i meant to test if the proxy is working,but this code won't stop if the proxy can not connect.
i also tried to use isReachable() method of InetAddress class,but i get the same result.
so how could i stop this connection if the proxy doesn't work ,in order to test if the proxy is reachable ?
System.getProperties().put("proxySet", "true");
That one doesn't do anything. It is an urban myth. It was part of the defunct 1997 HotJava bean and leaked from there into various books. It has never been part of any JDK. Try setting it to false in some situation where you need it on and see for yourself.
Sorry guys, I found out the way to do it.
I used java.net.Proxy class to open a connection via proxy.
It's easy to use and works fine. See Java Networking and Proxies

Categories