Somehow the URL handlers cache has the sun file protocol handler from the start,
at least as early as a debugger will let me stop in the URL.getURLStreamHandler
method. You need to flush this handler cache by setting a URLStreamHandlerFactory.
The change to make your example work is to install a factory that always returns
null:

Tests 1371>cat tstProtocol.java
import java.io.*;
import java.net.*;

class tstProtocol
{
   static class NullFactory implements java.net.URLStreamHandlerFactory
   {
      public URLStreamHandler createURLStreamHandler(final String protocol)
      {
         return null;
      }
   }

public static void main(String[] args) throws Exception
{
   // set handler pkgs
   System.out.println("java.protocol.handler.pkgs: " + System.getProperty("java.
protocol.handler.pkgs"));

   // Flush the handlers cache by setting a noop factory
   URL.setURLStreamHandlerFactory(new NullFactory());

   URL url = new URL("file", null, args[0]);
   System.out.println("url: " + url);
   URLConnection urlCon = url.openConnection();
   System.out.println("connection class: " + urlCon.getClass().getName());

   url = new URL("other", null, args[0]);
   System.out.println("url: " + url);
   urlCon = url.openConnection();
   System.out.println("connection class: " + urlCon.getClass().getName());
}
}

Tests 1369>java -cp ".;/tmp/JBoss/jboss-3.0.5/client/jboss-common-client.jar"
-Djava.protocol.handler.pkgs=org.jboss.net.protocol tstProtocol /tmp
java.protocol.handler.pkgs: org.jboss.net.protocol
url: file:/tmp
connection class: org.jboss.net.protocol.file.FileURLConnection
java.net.MalformedURLException: unknown protocol: other
        at java.net.URL.<init>(URL.java:302)
        at java.net.URL.<init>(URL.java:219)
        at java.net.URL.<init>(URL.java:238)
        at tstProtocol.main(tstProtocol.java:27)

xxxxxxxxxxxxxxxxxxxxxxxx
Scott Stark
Chief Technology Officer
JBoss Group, LLC
xxxxxxxxxxxxxxxxxxxxxxxx

----- Original Message ----- 
From: "Alex Loubyansky" <[EMAIL PROTECTED]>
To: "Scott M Stark" <[EMAIL PROTECTED]>
Sent: Tuesday, January 14, 2003 9:48 PM
Subject: Re[6]: [JBoss-dev] URLConnection and opened files


> Yes, I thought about it too. There are two cases:
> - the thread creating URL can't find custom handlers;
> - Sun's handler was somehow initialized/used before (before setting the
> property or somehow else?)
> 
> But I can't understand why my standalone test doesn't work. I set
> property in the command line and my handlers are in the classpath.
> I don't see any chance for Sun's handler to be used first.
> 
> Ok, I'll update JBoss-3.0 and see.
> 
> Thanks,
> alex



-------------------------------------------------------
This SF.NET email is sponsored by: Take your first step towards giving 
your online business a competitive advantage. Test-drive a Thawte SSL 
certificate - our easy online guide will show you how. Click here to get 
started: http://ads.sourceforge.net/cgi-bin/redirect.pl?thaw0027en
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to