What are the possible names of remote objects in a java rmi registry?
What are the possible names of remote objects in a java rmi registry? Are there forbidden characters?
I try to call the rebind method of the class Naming to bind an object in an rmi registry and I get a MalformedUrlExcepti开发者_高级运维on
. I know that the problem is the name of the object because when I use a name like abc
it works , so you probably don't need a stack trace to answer.
The thing is that the name is pseudorandomly generated.For example one of the names that caused the problem is [B@f3d6a5
. Is there a way to use whatever name you like and if not then what are the permitted names?
This is strange because the api does not state any rules about the name ,you can see it here. Maybe some characters that appear in the names ,like [
, have to be escaped with \
. Maybe it is not about java but about url specifications , if there are any , in which case I probably will have to use other names.
The API certainly doesn't say anything about restrictions, but if you get a MalformedUrlException
, what I'd try is to URLEncode
the randomly generated names.
The javadocs state:
name - a name in URL format (without the scheme component)
If you take a look at the source code for Naming
you will see that it converts thename you pass in into a URI
and throws a MalformedURLException
on certain conditions.
private static ParsedNamingURL intParseURL(String str)
throws MalformedURLException, URISyntaxException
{
URI uri = new URI(str);
if (uri.isOpaque()) {
throw new MalformedURLException(
"not a hierarchical URL: " + str);
}
if (uri.getFragment() != null) {
throw new MalformedURLException(
"invalid character, '#', in URL name: " + str);
} else if (uri.getQuery() != null) {
throw new MalformedURLException(
"invalid character, '?', in URL name: " + str);
} else if (uri.getUserInfo() != null) {
throw new MalformedURLException(
"invalid character, '@', in URL host: " + str);
}
This means that the name must be a valid URI
and, an in addition, cannot contain #
,?
or @
.
Take a look at the code yourself for more details.
精彩评论