问题
I'm trying to program in Java a class to start my Selenium Server in case it is down for some reason. I found very good help here: http://www.testingexcellence.com/how-to-start-selenium-server-with-java-code/
I see that some if the configuration parameters can be set using the class RemoteControlConfiguration and methods such as setPort, setLogOutFileName, setTimeoutInSeconds, ...
The problem is that my Selenium Server connects to a proxy in this way:
java -jar selenium-server.jar -Dhttp.proxyHost=my.proxy.com -Dhttp.proxyPort=8080
Unfortunately, I haven't found how to put this into java code. My question is: Is it possible to set the proxyHost and proxyPort values in java?
Thanks for your time =)
}Panacea{
回答1:
The easiest way is probably just to set them globally within 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 that entire instance of the JVM, so any other outgoing connections will also try to use the proxy. That's probably fine in your case, but if you need more isolated scope 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
回答2:
You should be able to use java.lang.System.setProperty(String, String)
for each property name and value.
来源:https://stackoverflow.com/questions/5622547/how-to-set-proxy-configuration-in-java-code