You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by Stefano Mazzocchi <st...@apache.org> on 2000/01/21 22:59:57 UTC

URLHandlerFactory problem

Java has _major_ problem with URL design pattern and friends.

While the java.net 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 java.net.URL

    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 java.net classes is lost because of this.

I explain: the java.net 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 "sun.net.www.protocol.xxx" where
xxx is the protocol you want to handle

Notes:

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
launcher

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 java.net 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.
<st...@apache.org>                             Friedrich Nietzsche
--------------------------------------------------------------------
 Come to the first official Apache Software Foundation Conference!  
------------------------- http://ApacheCon.Com ---------------------



Re: URLHandlerFactory problem

Posted by Niclas <ni...@localbar.com>.
Stefano Mazzocchi wrote:

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

Perhaps this is more than workable at this point in time. The JVM is
started from the mod_jserv and an appropriate Packaeg handler string would
not be much of a problem.  And even if you push this into the JDK 1.3
final, you could not really require JDK 1.3 now.  Most non-Windows
platforms are just about to get the JDK 1.2 final....

I agree though, it should been easier and definately more programmatical.

Niclas



Re: URLHandlerFactory problem

Posted by Pierpaolo Fumagalli <pi...@apache.org>.
Stefano Mazzocchi wrote:
> 
> Java has _major_ problem with URL design pattern and friends.

Did you just get that???? Hehehehe, way too slow, my friend...
I already tried to contact EVERYONE involved w/ Java.net, but the answer
is "that's the way it is"...

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

Many substantial limitations... Just look at the different behaviours of
Socket and DatagramSocket... This sucks :(

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

And it cannot be extended....

> This is taken from java.net.URL
> [...]

I had to fight w/ that piece of code while doing the sbk:// thing for
Stylebook... And in Avalon, that will become a NIGHTMARE...

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

Yep...

> 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 java.net 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]

Probably it's too late for 1.3, but can we have something for 1.4?
And rembember that this is not the only "lack" of java.net, as I said,
take a look at all the code in Socket.java and DatagramSocket.java

	Pier

-- 
--------------------------------------------------------------------
-          P              I              E              R          -
stable structure erected over water to allow the docking of seacraft
<ma...@betaversion.org>    <http://www.betaversion.org/~pier/>
--------------------------------------------------------------------
- ApacheCON Y2K: Come to the official Apache developers conference -
-------------------- <http://www.apachecon.com> --------------------