how to set proxy for firefox using java? - 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.

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");
}

Java HTTP proxy wont connect

How to connect properly using HTTP proxy in java? I can do it with sockProxyHost, but not with http.proxyHost.
If i do with socks, it will wait out for the proxy to connect and then it will create the web request, but if i do it with http it will just create the request and dont connect to the proxy.
System.setProperty("http.proxySet", "true");
System.setProperty("http.proxyHost", "validproxyip");
System.setProperty("http.proxyPort", "validproxyport");
is my code. but it wont connect to the proxy. Please help!
Check out the proxy documentation at Oracle
Either you have a typo, or you are using https and not http, or you access a "No-proxy" host. If you want to be sure, use the ProxySelector.
Try set it in the vm args
java -DproxyHost=proxy.mydomain.com -DproxyPort=3128 your.Main

fiddler and java ws problem

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.

Categories