M
Michael Conner
The Javadoc for URL describes three different ways to add a protocol
for a URL:
1) Create a URLStreamHandlerFactory which creates a new
URLStreamHandler, then install it as the factory.
2) Create an implementation with name, <package>.<protocol>.Handler
and add that name to the system property:
java.protocol.handler.pkgs.
3) Create the handler as:
sun.net.www.protocol.<protocol>.Handler
and simply ensure that it is on the classpath.
Of the three, the last seems the least problematic. The first might
result in problems when dealing with a third party wich also wants to
install its own factory. The second has a similar problem in that some
other party may want to specify the system property. If so, it must
be done programatically, so that you can get the original version of
the property and add to it, or it must be specified on the command
line (or the java configuration properties altered, if that is
supported by the jre).
However, my concerns are:
a) security policies might be defined which do not allow loading of
sun.* from application code.
b) Its not typical practice to define code in some other package
structure. Nevertheless, I've seen #3 used in several places when I
did a web search.
Does someone know of a resource which describes the preferred way to
do this, and addresses the issue of whether #3 is acceptable?
for a URL:
1) Create a URLStreamHandlerFactory which creates a new
URLStreamHandler, then install it as the factory.
2) Create an implementation with name, <package>.<protocol>.Handler
and add that name to the system property:
java.protocol.handler.pkgs.
3) Create the handler as:
sun.net.www.protocol.<protocol>.Handler
and simply ensure that it is on the classpath.
Of the three, the last seems the least problematic. The first might
result in problems when dealing with a third party wich also wants to
install its own factory. The second has a similar problem in that some
other party may want to specify the system property. If so, it must
be done programatically, so that you can get the original version of
the property and add to it, or it must be specified on the command
line (or the java configuration properties altered, if that is
supported by the jre).
However, my concerns are:
a) security policies might be defined which do not allow loading of
sun.* from application code.
b) Its not typical practice to define code in some other package
structure. Nevertheless, I've seen #3 used in several places when I
did a web search.
Does someone know of a resource which describes the preferred way to
do this, and addresses the issue of whether #3 is acceptable?