Custom URLStreamHandler for "file" protocol

A

Abhijat Vatsyayan

Hi ,
I have an application (part of it is an RMI server) deployed on JBOSS
3.2.5 as a JMX service. I need my application to use my custom
URLStreamHandler for "file" protocol. I have tried two things -

* invoke URL.setURLStreamHandlerFactory( ... ) with my custom factory.
This throws an Error. JBOSS is setting up a factory before my code gets
a chance to do this (does make some sense).

* I moved my handler (subclass of URLStreamHandler) to "x.y.z.url.file"
package and renamed the handler class to "Handler" . After this I set
the system property "java.protocol.handler.pkgs" to "x.y.z.url" . This
does not seem to work as well in JBoss. I tried this in a simple
application and looks like I can not use my custom handler for "file"
protocol (without setting a factory). It works if I change the protocol
name (and package name) to "tile" (or some other unknown protocol)
instead of "file".

So here is the problem - if someone has already set the
URLStreamHandlerFactory, how do I use my custom URLStreamHandler for
"file" protocol ?

Thanks,
Abhijat
|*

*||*
<../../java/net/URL.html#setURLStreamHandlerFactory%28java.net.URLStreamHandlerFactory%29>*|
 
R

Roedy Green

So here is the problem - if someone has already set the
URLStreamHandlerFactory, how do I use my custom URLStreamHandler for
"file" protocol ?


I know it is possible to add a new protocol. We did it on a project I
worked on in the early days of Java.

Have a look at the method URLStreamHandler
URL.getURLStreamHandler(String protocol)

You have somehow got to get your code linked in there as the official
handler.
 
R

Roedy Green

So here is the problem - if someone has already set the
URLStreamHandlerFactory, how do I use my custom URLStreamHandler for
"file" protocol ?

have a look at
org.eclipse.osgi.framework.internal.protocol.URLStreamHandlerSetter
in Eclipse to see how they do it.
 
A

Abhijat Vatsyayan

Roedy said:
I know it is possible to add a new protocol. We did it on a project I
worked on in the early days of Java.

Have a look at the method URLStreamHandler
URL.getURLStreamHandler(String protocol)

getURLStreamHandler is a package protected method and in any case it
does not let me "set" a handler for a specific (file) protocol. I have
the option of writing a class that belongs to package "java.net" which
can change the contents of "handlers" field (this is package protected
static). This sounds pretty ugly not to mention that sun will probably
not like it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,983
Messages
2,570,187
Members
46,747
Latest member
jojoBizaroo

Latest Threads

Top