 |
We deserve a better proxy support!
Posted by kohsuke on August 10, 2005 at 01:16 PM | Comments (8)
Nowadays many Java tools need to access HTTP resources. For example, Ant has a <get> task, Maven needs to download jar files, javadoc needs to locate package-list from a remote site, JAX-WS's WsImport reads WSDL from a remote website, and JAXB's schema compiler does the same for schema files. The list could go on forever.
So first let's look at how these tools support proxies?
- Ant
-
With Ant, you either do export ANT_OPTS="-Dhttp.proxy.port=8080 -Dhttp.proxy.host=webproxy.acme.com" or use the setproxy task. The latter is particularly bad, because proxy setting is by its nature different from one developer to another. But this task requires that you set proxies inside a build script, which is supposed to be shared by multiple people. So you typically end up defining a property in a file like build.properties and tell individuals to override them. The former is better, but it's not well advertised.
- Maven
-
With Maven, you typically write ~/build.properties like this:
maven.proxy.host=webproxy.acme.com
maven.proxy.port=8080
- javadoc
-
Javadoc is probably the worst of those tools I mentioned here, because it doesn't even attempt to support a proxy. So you'll either have to download package-list and use the -linkoffline option, or you'd run it as javadoc -J-Dhttp.proxy.port=8080 -J-Dhttp.proxy.host=webproxy.acme.com ... which isn't mentioned anywhere in the documentation.
- WsImport / XJC
-
These tools have the -proxy option to let you configure the proxy info. Fortunately they take the similar syntax, where the only difference is that XJC accepts userid/password authentication, whereas (I believe) WsImport doesn't.
The problem here is that every tool invents its own way of configuring proxies. So whenever I bring my laptop between home (no proxy) and office (need proxy), I have to dilligently change the settings in so many places. First, you change the IE connection, then you change Firefox connection, then ~/build.properties. Am I done now? No, I still have to modify ~/.svn/servers!
It would be much better if the configuration location is consolidated, so that I can only change it once and be done with it.
So, that's why I'm going to talk about this feature I recently discovered in Java SE 5, where you can tell the VM to use the platform proxy configuration (meaning IE's connection setting in Windows, or Gnome's if you are on it.) To activate this, you need to put the following lines in the beginning of your tool:
try {
System.setProperty("java.net.useSystemProxies","true");
} catch (SecurityException e) {
; // failing to set this property isn't fatal
}
This has to be done before your tool starts accessing URL class and so on, because this system property is checked only once at the start-up time.
This works even with pre-Java 5 JVMs. It just doesn't take any effect, which is a reasonable fallback behavior.
I've already finished changing XJC, so it now works without the explicit -proxy option, as long as your Internet Expolorer / Gnome is configured correctly. Now if only Maven, Ant, javadoc, and million other tools could do the same...
Bookmark blog post: del.icio.us Digg DZone Furl Reddit
Comments
Comments are listed in date ascending order (oldest first) | Post Comment
-
hi there,
+1.
BR,
~A
Posted by: anjanb2 on August 10, 2005 at 05:07 PM
-
Now if only Maven, Ant, javadoc, and million other tools could do the same...
Have you filled a bug for Maven, Ant, javadoc and all these other tools?
Posted by: felipeal on August 10, 2005 at 09:26 PM
-
Since java.net.useSystemProxies is a documented system property, you can just pass it on the command line or set it and forget it in the normal tool specific manner, once.
Posted by: ljnelson on August 11, 2005 at 03:54 AM
-
For me, the real problem is that Java can't authenticate on the company's ISA Server (Microsoft's Proxy)!!! If Firefox, GNU wget, etc. can, why can't Java?
Because of this, I can't load applets. To use maven, I have to run it in offline mode (-X), and use wget to fetch the required dependencies.
Java is really crippled in this aspect.
Posted by: dserodio on August 11, 2005 at 07:58 AM
-
I'll file bugs for those tools I mentioned here, felipeal.
Posted by: kohsuke on August 11, 2005 at 09:02 AM
-
ljnelson, yes, you can do that, or you can even put it to $JRE/lib/net.properties
Posted by: kohsuke on August 11, 2005 at 09:05 AM
-
dserodio, you should report that as a bug at BugParade (http://bugs.sun.com/bugdatabase/index.jsp). Perhaps it's doing the authentication?
Posted by: kohsuke on August 11, 2005 at 09:06 AM
-
Not to mention that using a proxy while running javadoc within ant is even more annoying because javadoc doesn't run in ant's JVM. I'm looking into a way to do this, but any suggestions would be appreciated.
Posted by: dgreenbean on April 18, 2007 at 08:28 AM
|