Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

spaces in URL causes "java.net.MalformedURLException: no protocol: "

919255Feb 22 2012 — edited Feb 24 2012
Hi all,

i've got a Problem using RMI. Following exception is thrown:

java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.net.MalformedURLException: no protocol: xxx.

Cause of this error is an URLClassLoader of an external application using my JDBC-Driver which connects to my server via RMI. The URLClassLoader (got by class.getClassLoader()) contains at first position in the array an URL representing a jarfile by absoulte path, containing whitespaces. This URL seems to be set by the extern application to the classpath with these whitespaces. I do not know where and how to change it.
I thought of a solution of this problem to manipulate ClassLoader to replace all containing white spaces in the URLs with the correct syntax for URLs: %20.
In the first try, i used system-property "java.rmi.server.codebase" to set the correct codebase with replaced spaces. This seems not to work. The codebase-property seems to be used by RMIClassLoader (i short look to the code shows, that codebase-property is only used if the current classloader is also a system classloader?).
Second try was to create an own URLClassLoader with correct URL-Strings. But i do not know how to use it for RMI. Using my correct URLClassLoader for my class instance with following code:

final URL[] urLs = ((URLClassLoader) cl.getClassLoader()).getURLs();
final URL[] newUrls = new URL[urLs.length];
int i = 0;
for (final URL url : urLs) {
try {
newUrls[i] = new URL(url.toExternalForm().replace(" ", "%20"));
} catch (final MalformedURLException e) {
LOG.error("An error occurred, cause is: " + e.getMessage(), e);
}
i++;
}
loader = new URLClassLoader(newUrls, originalClassLoader);
final Class<?> clazz = loader.loadClass("MyDriver");
final Object instance = clazz.newInstance();

does not work. Do you know how i can use this classloader instead of the original classloader to solve my problem with white spaces in URLs?

Many thanks in advance!

Comments

Processing
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Mar 22 2012
Added on Feb 22 2012
6 comments
10,960 views