cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stefano Mazzocchi <>
Subject URLHandlerFactory problem
Date Fri, 21 Jan 2000 21:59:57 GMT
Java has _major_ problem with URL design pattern and friends.

While the library is one of the oldest one and includes many
good design patterns, it has a substantial limitation:

- one and only one URLHandlerFactory per JVM can be set, no matter what
security manager you have installed.

This is taken from

    public static synchronized void
setURLStreamHandlerFactory(URLStreamHandlerFactory fac) {
	if (factory != null) {
	    throw new Error("factory already defined");
        factory = fac;

I don't care to know the reasons for such thing, but as it stands today,
most of the ability of the classes is lost because of this.

I explain: the framework allows you to create special protocol
handlers so that you make normal URLs behave like very powerful gateways
to resources. For example, jar://cocoon.jar!/hello.xml opens up a jar
file and reads the hello.xml file, while sql://database/[select * from
clients] might perform an SQL query against a database and so on...

To hook your own protocol handler to the platform, you have three ways:

1) write your own URLStreamHandlerFactory (like Cocoon does today)

2) put your package in the "java.protocol.handler.pkgs" system property.
Note you can't do this internally, but only at command line.

3) you write your class with package "" where
xxx is the protocol you want to handle


1) the first method is the most portable one, but only one software
running in a JVM can set this. It might be ok if you have one
application only, but if you have two servlets that need two different
protocols, you're fucked.

2) this imposes a pretty good system knowledge by the application

3) this is the worst dirty hack I've never seen and will work only with
Sun JVMs.

In a word: the URL is great, but the API to extend it suck.

What do I suggest? simple, easy, something like

 public static registerURLStreamHandler(String protocol,
URLStreamHandler handler);

God, it's not that hard...

[James, would you do us a favor: tell James Gosling about it. I know
he's the one who wrote and designed most of the URL framework.
I would like to know his comment about this... or, please, place this up
high in the "todo list for 1.3final", thank you]

Stefano Mazzocchi      One must still have chaos in oneself to be
                          able to give birth to a dancing star.
<>                             Friedrich Nietzsche
 Come to the first official Apache Software Foundation Conference!  
------------------------- http://ApacheCon.Com ---------------------

View raw message