views:

346

answers:

4

I am thinking of a simple Java appplication (command line) that connects to the internet to download a XML file, the problem is that my Ubuntu is using a proxy to connect to internet with username and password (through http_proxy ="http://<username>:<pwd>@<ip>:<port>" ). So my question is, could it be possible to write a java app to use http_proxy variable? Instead of programmatically setting http proxy and host in every app I will write.

+1  A: 

With a current JVM you can pass the proxy host and port using Java properties (java -Dhttp.proxyHost=webcache.mydomain.com -Dhttp.proxyPort=8080 -Dhttp.noProxyHosts=”localhost|host.mydomain.com” GetURL ) - http://java.sun.com/javase/6/docs/technotes/guides/net/proxies.html

Username and password examples http://www.rgagnon.com/javadetails/java-0085.html http://www.developer.com/java/other/article.php/1551421/Questions-on-HttpURLConnection-and-Proxies.htm
A: 

in http://java.sun.com/javase/6/docs/technotes/guides/net/proxies.html there is no command to pass proxy username and password to JVM.

rbbeltran
A: 

For username and password, what about -Dhttp.proxyUser=username -Dhttp.proxyPassword=supersecret ?

Stephane
A: 

Dont forget the Shell Variable _JAVA_OPTIONS

export _JAVA_OPTIONS='-Dhttp.proxyPort=cache.com -Dhttp.proxyPort=3128'

for property stuff look to the excellent http://mindprod.com/jgloss/properties.html

wiki1000