tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Alberto Garoffolo" <>
Subject Please, need help about Tomcat 4.0.x classloader compatibility with custom protocol definition
Date Mon, 14 Jan 2002 15:28:54 GMT

I' ve a problem defining under Tomcat 4.0.x my own protocol
handler setting the property "java.protocol.handler.pkgs"

(URL class cannot load URLStreamHandlers located in the "common/lib"

My protocol interacts with all my webapps allowing them to
add their handlers at runtime
( for example: protocolname://handler1/ , protocolname://handler2/ ...).
I' ve implemented this with a singletone object
(queryied by my implementation of the URLStreamHandler Class) that
holds the associations handler_name->component_instance.
Under Tomcat 4 i had to put my protocol jar in the common/lib
directory to access the same singletone object from all webapps.

Then i've encountered some problems registering the protocol,
before with "URL.setURLStreamHandlerFactory" because the factory
was already defined by Tomcat, and after with the property

One month ago i solved the problem modifying Tomcat 4.0.1
to not register the factory if the package "org.apache.naming.resources"
is specified in the property "java.protocol.handler.pkgs", then i sent
the patch to tomcat-dev list but no reply

Now, having the same problem with Tomcat 4.0.2 b1, i retried to declare
my protocol setting the "java.protocol.handler.pkgs" property but it still
doesn't work.

Debugging the application, i found that the ClassLoader used by
find my URLStreamHandler implementation that is in the common/lib.

This is the "" code that should instantiate the
(packagePrefix is the package found in the property
 and protocol, the requested protocol name )

      try {
            String clsName = packagePrefix + "." + protocol + ".Handler";

            Class cls = null;
             try {
                     cls = Class.forName(clsName);
             } catch (ClassNotFoundException e) {

                    ClassLoader cl = ClassLoader.getSystemClassLoader();
                    if (cl != null) {
                           cls = cl.loadClass(clsName);
             if (cls != null) {
                       handler  =
      } catch (Exception e) {
           // any number of exceptions can get thrown here

I think it could be a ClassLoader bug.

Thanks for patience :-)

Thanks in advance for any help.


Here follows how i patched Tomcat 4.0.1 to not register the
if the package "org.apache.naming.resources" is specified in the property

I' ve modified with success my tomcat 4.01 to allow webapps to register
their protocol handler in this way:

in and in before setting the factory i
check if the property
"java.protocol.handler.pkgs" contains the package
"org.apache.naming.resources", in this case it' s not
necessary to set the Factory because the URL class will use, for the jndi
protocol, the class named:
"org.apache.naming.resources" + ".jndi" + ".Handler"; if the proprty isn't
set i register the Factory.

Then, i' ve modified setting CATALINA_OPTS with value:

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message