dev@glassfish.java.net

URLStreamHandlerFactory and PELaunch

From: Ronald V. Simmons <Van_Simmons_at_TheSimmonses.Net>
Date: Sat, 20 May 2006 15:50:55 -0400

Ok, so here's a pretty esoteric problem.

I have a need to install my own implementation of
URLStreamHandlerFactory at startup of my glassfish domain.

It's a long story, but the reason is that I have ear files which need
a custom protocol handler from a third party. At present my ears all
use the same version of the protocol that's causing this, but it's
easy to conceive of a day when that might not be the case. So I'd
like to _not_ install the the protocol handler in the customary
manner of putting it in the system classpath and specifying system
properties like this:

-Djava.protocol.handler.pkgs=XXX

(This also presents difficulties because the handler I need is
actually rolled in a 3rd party jar that I'd prefer not to unpack or
stick in the system classpath). Instead, I'd prefer to have a custom
version of URLStreamHandlerFactory which:

a) came with appropriate policy-driven permissions to restrict
ability to install a new URLStreamHandler class
b) could deal with dynamically determining which URLStreamHandler
implementation to use when createURLStreamHandler(String protocol) is
invoked.

The problem with doing this is that:

a) there is no system property (that I, or google, seem to be aware
of) to allow you to specify an URLStreamHandlerFactory implementation
for java.net.URL to use as the default
b) The URLStreamHandlerFactory that the java.net.URL class uses by
default (at least in Sun's implementation) is a singleton which can
be set precisely once, after which further attempts to set it throw
an exception
c) That default gets set soon as anyone in the entire JVM calls new
URL()
d) Creating classloaders calls new URL()

I've got such an URLStreamHandlerFactory implementation up and tested
and have written a main() class which installs it and invokes
PELaunch and everything seems to work, but... This is ugly. It
means that I have to change things under glassfish/lib rather than
under glassfish/domains/mydomain/config, which means I'm not using a
stock glassfish.

Anyone have any thoughts here? Ideally, JSE could give me the
opportunity to specify what I need via a system property, but my
suspicion is that that's a pretty forlorn hope.

thanks

rvs