java rmi注册表中远程对象的可能名称是什么?

时间:2011-01-18 12:35:54

标签: java rmi

java rmi注册表中远程对象的可能名称是什么?有禁止的角色吗?

我尝试调用类Naming的rebind方法来绑定rmi注册表中的对象,然后得到MalformedUrlException。我知道问题是对象的名称,因为当我使用像abc这样的名称时它会起作用,所以你可能不需要堆栈跟踪来回答。

事实是该名称是伪随机生成的。例如,导致该问题的名称之一是[B@f3d6a5。有没有办法使用你喜欢的任何名称,如果没有,那么允许的名称是什么?

这很奇怪,因为api没有说明有关名称的任何规则,你可以看到它here。也许名称中出现的某些字符(例如[)必须使用\进行转义。也许它不是关于java而是关于url规范,如果有的话,在这种情况下我可能不得不使用其他名称。

2 个答案:

答案 0 :(得分:1)

API肯定没有说明有关限制的内容,但如果你得到MalformedUrlException,我会尝试URLEncode随机生成的名称。

答案 1 :(得分:1)

javadocs州:

  

name - URL格式的名称(不含   方案组件)

如果您查看Naming的源代码,您会看到它会转换为您传入URI并在某些条件下抛出MalformedURLException

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);
    }

这意味着该名称必须是有效的URI,此外,该名称不能包含#?@

请自行查看代码以获取更多详细信息。

相关问题