How to configure proxy configuration in Java code

I am trying to program in Java a class to start my Selenium Server, if for some reason it does not work. I found very good help here: http://www.testingexcellence.com/how-to-start-selenium-server-with-java-code/

I see that some configuration parameters can be set using the RemoteControlConfiguration class and methods such as setPort, setLogOutFileName, setTimeoutInSeconds, ...

The problem is that my Selenium Server connects to the proxy in this way:

java -jar selenium-server.jar -Dhttp.proxyHost=my.proxy.com -Dhttp.proxyPort=8080 

Unfortunately, I did not find how to put this in Java code. My question is: is it possible to set the values ​​of proxyHost and proxyPort in java?

Thanks for your time =)

} {Panacea

0
source share
2 answers

The easiest way is to simply install them globally in the JVM

 System.setProperty("http.proxyHost", "yourproxyurl.com"); System.setProperty("http.proxyPort", "80"); 

http://download.oracle.com/javase/6/docs/technotes/guides/net/proxies.html

However, this affects the entire JVM instance, so any other outgoing connections will also try to use proxies. This is probably good in your case, but if you need a more isolated area, you can use URL.openConnection (Proxy).

http://download.oracle.com/javase/1.5.0/docs/api/java/net/URL.html#openConnection%28java.net.Proxy%29

+3
source

You can use java.lang.System.setProperty(String, String) for each property name and value.

+1
source

Source: https://habr.com/ru/post/911564/


All Articles