简体   繁体   English

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

[英]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? Java rmi注册表中远程对象的可能名称是什么? 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 MalformedUrlException . 我尝试调用Naming类的rebind方法来绑定rmi注册表中的对象,并且得到MalformedUrlException 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. 我知道问题出在对象的名称,因为当我使用abc之类的名称时,它就可以工作,因此您可能不需要堆栈跟踪即可回答。

The thing is that the name is pseudorandomly generated.For example one of the names that caused the problem is [B@f3d6a5 . 问题是名称是伪随机生成的。例如,引起问题的名称之一是[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 . 这很奇怪,因为api没有说明有关名称的任何规则,您可以在此处看到它。 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. 也许不是关于Java而是关于url规范,如果有的话,在这种情况下,我可能不得不使用其他名称。

该API当然没有说明任何限制,但是如果您遇到MalformedUrlException ,我将尝试对随机生成的名称进行URLEncode

The javadocs state: javadocs状态:

name - a name in URL format (without the scheme component) name-URL格式的名称(不含方案组件)

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. 如果查看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);
    }

This means that the name must be a valid URI and, an in addition, cannot contain # , ? 这意味着名称必须是有效的URI ,并且此外不能包含# ? or @ . @

Take a look at the code yourself for more details. 自己看一下代码以获取更多详细信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM