Ok.. if finished that workaround. I don't know if it will break anything
else, but at least it fixes our test case. To use it, add the following
line to the top of the tstMO main() method.
FileURLSpaceFixer.install();
below is the FileURLSpaceFixer.java file.
-------------------------
import java.net.URL;
import java.net.URLStreamHandlerFactory;
import java.net.URLStreamHandler;
import java.net.URLConnection;
/**
* Used to fix the problem with the RMI classloader for
* when a space appears in the path to where a class
* should be loaded from.
*
* @author: Hiram Chirino
*/
class FileURLSpaceFixer {
private static FileHandler fileHander= new FileHandler();
private static CustomURLStreamHandlerFactory
customURLStreamHandlerFactory= new CustomURLStreamHandlerFactory();
//
// This class is used to hook into the URL protocol parsing sysytem
//
private static class CustomURLStreamHandlerFactory implements
URLStreamHandlerFactory {
public URLStreamHandler createURLStreamHandler(String protocol) {
if (protocol.equals("file"))
return fileHander;
return null;
}
}
//
// This class will override how the file handler is implemented.
//
private static class FileHandler extends
sun.net.www.protocol.file.Handler {
// When we externalize the URL we want to make all the spaces in the
file name
// a '+' character
protected String toExternalForm(URL u) {
String s= super.toExternalForm(u);
return s.replace(' ', '+');
}
// When we load a URL in we want to convert all the '+' characters in
the file name
// into spaces.
protected void parseURL(URL u, String spec, int start, int limit) {
super.parseURL(u, spec, start, limit);
setURL(u, u.getProtocol(), u.getHost(), u.getPort(),
u.getFile().replace('+', ' '), u.getRef());
}
}
// use this method to install this fix.
public static void install() {
URL.setURLStreamHandlerFactory(customURLStreamHandlerFactory);
}
}
-----------------
Regards,
Hiram
>From: "Scott M Stark" <[EMAIL PROTECTED]>
>Reply-To: [EMAIL PROTECTED]
>To: <[EMAIL PROTECTED]>
>Subject: Re: [JBoss-dev] (no subject)
>Date: Fri, 24 Aug 2001 15:46:16 -0700
>
>This may due to existing bug report on File.toURL() not escaping chars
>correctly. Here is a trival example that demonstrates the problem:
>
>Space Here 1162>ls
>ASerializable.java ser.jar tstMO.class tstMO.java
>Space Here 1163>pwd
>/tmp/Space Here
>Space Here 1164>java tstMO
>cwd = file:/tmp/Space Here/./
>serializable class = class java.lang.Class
>serializable codesource = null
>Exception in thread "main" java.net.MalformedURLException: no protocol:
>Here/./ser.jar
> at java.net.URL.<init>(URL.java:473)
> at java.net.URL.<init>(URL.java:376)
> at java.net.URL.<init>(URL.java:330)
> at sun.rmi.server.LoaderHandler.pathToURLs(LoaderHandler.java:387)
> at sun.rmi.server.LoaderHandler.loadClass(LoaderHandler.java:132)
> at
>sun.rmi.server.MarshalInputStream.resolveClass(MarshalInputStream.java:143)
> at
>java.io.ObjectInputStream.inputClassDescriptor(ObjectInputStream.java:918)
> at
>java.io.ObjectInputStream.readObject(ObjectInputStream.java:366)
> at
>java.io.ObjectInputStream.readObject(ObjectInputStream.java:350)
> at
>java.io.ObjectInputStream.readObject(ObjectInputStream.java:236)
> at java.rmi.MarshalledObject.get(MarshalledObject.java:138)
> at tstMO.main(tstMO.java:21)
>Space Here 1165>cat tstMO.java
>import java.io.*;
>import java.net.*;
>import java.rmi.*;
>import java.security.*;
>
>class tstMO
>{
> public static void main(String[] args) throws Exception
> {
> File cwd = new File(".");
> File jarFile = new File(cwd, "ser.jar");
> System.out.println("cwd = "+cwd.toURL());
> URL[] urls = {jarFile.toURL()};
> URLClassLoader cl = new URLClassLoader(urls);
> Object serializable = cl.loadClass("ASerializable");
> Class sc = serializable.getClass();
> System.out.println("serializable class = "+sc);
> CodeSource cs = sc.getProtectionDomain().getCodeSource();
> System.out.println("serializable codesource = "+cs);
> MarshalledObject mo = new MarshalledObject(serializable);
> System.out.println("mo.get() ->"+mo.get());
> }
>}
>
>Space Here 1166>cat ASerializable.java
>
>public class ASerializable implements java.io.Serializable
>{
>}
>Space Here 1167>jar -tf ser.jar
>META-INF/
>META-INF/MANIFEST.MF
>ASerializable.class
>Space Here 1168>
>
>----- Original Message -----
>From: "Scott M Stark" <[EMAIL PROTECTED]>
>To: <[EMAIL PROTECTED]>
>Sent: Friday, August 24, 2001 3:07 PM
>Subject: Re: [JBoss-dev] (no subject)
>
>
> > This looks to be a bug in the sun.rmi.server.LoaderHandler class as
> > it takes the URLs from the class's URLClassLoader and converts these
> > into a space seperated list of url strings for use as the codebase, but
> > these are not x-www-form-urlencoded string and so they will contain
> > spaces if the file url contains a space. Thus, when the codebase is
>parsed
> > into url strings by spaces the result is invalid url strings.
> >
> > The only workaround I can see at this point is to not install the server
>in
> > a directory with spaces.
> >
>
>
>
>_______________________________________________
>Jboss-development mailing list
>[EMAIL PROTECTED]
>http://lists.sourceforge.net/lists/listinfo/jboss-development
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-development