java.rmi.UnmarshalException:无法通过服务器拉取客户端类

发布于 2024-08-14 07:51:28 字数 3833 浏览 8 评论 0原文

我在两台机器上设置了 RMI 客户端/服务器,当服务器不需要客户端定义的类时,它可以在简单的情况下正常工作。但是,当我需要使用在客户端定义的类时,我无法让服务器解组这些类。我怀疑这是我作为参数传递给客户端应用程序的 java.rmi.server.codebase 属性的问题。我遵循了Sun的RMI教程,我想我已经完全遵循了这些步骤,除了在执行客户端和服务器时我没有指定类路径参数,因为它们在根包目录正上方的目录中执行(但是我也尝试过,没有影响)。

当我尝试执行下面详细描述的不同客户端组合时遇到的异常都是相同的:

Rmi服务器异常: java.rmi.ServerException:服务器线程中发生RemoteException;嵌套异常是: java.rmi.UnmarshalException:解组参数时出错;嵌套异常是: java.lang.ClassNotFoundException:test.MyTask 在 sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:353) 在 sun.rmi.transport.Transport$1.run(Transport.java:177) 在 java.security.AccessController.doPrivileged(本机方法) 在 sun.rmi.transport.Transport.serviceCall(Transport.java:173) 在 sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:553) 在 sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:808) 在 sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:667) 在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) 在 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) 在 java.lang.Thread.run(Thread.java:636) 在 sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:255) 在 sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:233) 在 sun.rmi.server.UnicastRef.invoke(UnicastRef.java:142) 在 java.rmi.server.RemoteObjectInitationHandler.invokeRemoteMethod(RemoteObjectInitationHandler.java:178) 在 java.rmi.server.RemoteObjectInitationHandler.invoke(RemoteObjectInitationHandler.java:132) 在 $Proxy0.execute(来源不明) 在 test.myClient.main(myClient.java:32) 详细

信息是:

我的客户端/服务器 rmi 是通过路由器后面的家庭网络设置的。路由器被分配到一个静态 IP 地址,我将其称为 myhostname。在指向正确机器的路由器中设置适当的端口映射。

角色、机器、操作系统、IP 地址:

服务器、venice、linux ubuntu 9.10、10.0.1.2
client, naples, mac os x leopard, 10.0.1.4

我在 /home/andrews/workspace/epsilon/bin 中按如下方式启动服务器端:

1 在默认端口 1099:

venice% rmiregistry &

2 在端口 2001 上启动 Web 服务器,指向通用接口的代码库:

venice% java webserver/ClassFileServer 2001 /home/andrew/ workspace/epsilon/bin

3 启动服务器应用程序(test/myServer 中的主类),用于注册服务器对象:

venice% java -Djava.rmi.server.codebase="http:// myhostname:2001/" -Djava.security.policy=server.policy -Djava.rmi.server.hostname=myhostname test/myServer &

现在是 /Users/andrews/Development/Java 内的客户端/workspace/epsilon/bin:

1启动一个本地Web服务器,可以将客户端类服务器到服务器(不确定是否需要这个,但我添加了我尝试过,但仍然没有成功;我已经添加端口映射到路由器(2001 年到威尼斯,2002 年到那不勒斯

naples$ java webserver/ClassFileServer 2002 /Users/andrews/Development/Java/workspace /epsilon/bin/

尝试运行客户端(注意:我没有指定 -cp 参数,因为客户端在根包目录的正上方执行):

1 尝试使用 #1 http 主机名

naples$ java -Djava.rmi.server.codebase=http://10.0.1.4:2002/ -Djava.security.policy=client.policy test.myClient myhostname

注 1: <最后的 code>myhostname 参数被传递给客户端,以便它解析为服务器的 rmi 主机名。

注 2:我也尝试使用 localhost:2002 而不是 10.0.1.4:2002

注意 3:我尝试使用 myhostname:2002 因为 myhostname 已分配给路由器并且我有正确的端口映射设置,该地址应解析为 naples 而不是venice

2 尝试#2:

naples$ java -Djava.rmi.server.codebase=file:/Users/andrews/Development/Java/workspace/epsilon/bin / -Djava.security.policy=client.policy test.myClient myhostname

注1:代码库url格式正确,我创建了一个小程序将当前文件目录路径转换为url并使用它。使用 file:///Users... 具有相同的效果。

其他注意事项:

1 我的服务器和客户端策略文件正确指定了路径,因为我已经使用好路径和坏路径测试了此设置,并获得了坏路径的安全异常

2 如果我不使用客户端定义的设置,则此设置有效对象,客户端正确连接到服务器并且服务器执行。

3 当我将客户端类放在服务器上的服务器类路径中时,一切都执行正常。

感谢所有帮助。

I have an RMI client/server set-up on two machines that works fine in a simple situation when the server doesn't require a client-side defned class. However, when I need to use a class defined on the client side I am unable to have the server unmarshall those classes. I suspect this is an issue with my java.rmi.server.codebase property that I pass in as argument to the client app. I followed Sun's RMI Tutorial trail and I think I have followed the steps exactly except that I don't specify a classpath argument when executing client and server because they execute in the directory right above the root package directory (however I tried that too with no effect).

The exceptions I get when attempting to execute the different client-side combinations described in detail below are all the same:


RmiServer exception:
java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: test.MyTask
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:353)
at sun.rmi.transport.Transport$1.run(Transport.java:177)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:173)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:553)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:808)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:667)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:636)
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:255)
at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:233)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:142)
at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(RemoteObjectInvocationHandler.java:178)
at java.rmi.server.RemoteObjectInvocationHandler.invoke(RemoteObjectInvocationHandler.java:132)
at $Proxy0.execute(Unknown Source)
at test.myClient.main(myClient.java:32)

The details are:

My client/server rmi is set up over a home network behind a router. The router is assigned to a static ip address I will call myhostname. Appropriate port-mapping is set-up in the router that points to the right machines.

role, machine, os, ip-address:

server, venice, linux ubuntu 9.10, 10.0.1.2
client, naples, mac os x leopard, 10.0.1.4

I startup the server side as follows inside /home/andrews/workspace/epsilon/bin:

1 starting registry on the default port 1099:

venice% rmiregistry &

2 starting web-server on port 2001 pointing to code base for common interfaces:

venice% java webserver/ClassFileServer 2001 /home/andrew/workspace/epsilon/bin

3 starting server app (main class in test/myServer) which registers the server object:

venice% java -Djava.rmi.server.codebase="http://myhostname:2001/" -Djava.security.policy=server.policy -Djava.rmi.server.hostname=myhostname test/myServer &

Now the client side inside /Users/andrews/Development/Java/workspace/epsilon/bin:

1 start a local web server that can server client-side classes to the server (not sure if this is needed, but I added I tried it, and still no success; I have added port-mapping to the router for 2001 to venice, for 2002 to naples)

naples$ java webserver/ClassFileServer 2002 /Users/andrews/Development/Java/workspace/epsilon/bin/

Trying to run the client (note: I don't specify the -cp argument because client executes right above the root package directory):

1 try #1 using an http hostname

naples$ java -Djava.rmi.server.codebase=http://10.0.1.4:2002/ -Djava.security.policy=client.policy test.myClient myhostname

Note 1: the myhostname argument at the end is passed-in to the client so that it resolves to server's rmi hostname.

Note 2: I tried using localhost:2002 instead of 10.0.1.4:2002 too.

Note 3: I tried using myhostname:2002 since myhostname is assigned to the router and I have proper port-mapping set-up, this address should resolve to naples and not venice

2 try #2:

naples$ java -Djava.rmi.server.codebase=file:/Users/andrews/Development/Java/workspace/epsilon/bin/ -Djava.security.policy=client.policy test.myClient myhostname

Note 1: the code base url format is correct, I created a small program to convert current file directory path into a url and used that. using file:///Users... has same effect.

Other notes:

1 my server and client policy files correctly specify the path, as I've tested this setup with good and bad paths, and getting a security exception for bad path

2 this setup works if I don't use client-side defined objects, the client connects correctly to the server and the server executes.

3 when I place the client-side class on the server in the server's classpath, all executes fine.

All help is appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一桥轻雨一伞开 2024-08-21 07:51:28

你真的需要使用 RMI 吗?我和一个朋友在学校尝试过一次,它方式慢,比我们之前做的简单的 ObjectOutputStream 网络慢得多。

Do you really need to use RMI? Me and a friend tried it once in school and it was way slow, much slower then the simple ObjectOutputStream networking we had been doing earlier.

你又不是我 2024-08-21 07:51:28

我非常同意 Chad Okere 的说法,RMI 确实非常慢并且消耗资源。有时直接使用套接字也许是简单而有用的选择,关于您的异常您能确认您的rmi服务器正常工作吗? http://www.javarmi.com/2010/05 /java-rmi-error-unmarshalling-arguments/ 也许可以帮助你

I strong agree with Chad Okere's said, RMI is really very slow and consuming-resouces. sometimes directly use Sockets maybe is simple and useful chooice, regarding your exception Could you confirm your rmi server work correctly? http://www.javarmi.com/2010/05/java-rmi-error-unmarshalling-arguments/ maybe be can help you

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文