使用RMI时抛出 error during JRMP connection establishment; nested exception is:java.io.EOFException]

Jo_Cai 2009-03-12 08:07:23
刚学了RMI,编译教材上的代码运行很正常,教材上是使用rmiregistry注册远程对象的。然后我想用weblogic来代替行不行,但修改代码后就报错了。代码如下:
---------HelloService.java------------------------------------------------------------------------------------------
package chapter11;
import java.util.Date;
import java.rmi.*;
public interface HelloService extends Remote{
public String echo(String msg)throws RemoteException;
public Date getTime()throws RemoteException;
}
-------------HelloServiceImpl.java----------------------------------------------------------------------
package chapter11;
import java.rmi.*;
import java.util.Date;
import java.rmi.server.UnicastRemoteObject;
public class HelloServiceImpl extends UnicastRemoteObject implements HelloService{
private String name;
public HelloServiceImpl(String name)throws RemoteException{
this.name = name;
}
public String echo(String msg)throws RemoteException{
System.out.println(name+":use the echo() method");
return "echo:"+msg+"from"+name;
}
public Date getTime()throws RemoteException{
System.out.println(name+":use the getTime() method");
return new Date();
}
}
----------SimpleServer.java----------------------------------------------------------------------------
package chapter11;
import java.rmi.*;
import javax.naming.*;

import java.util.*;
public class SimpleServer {
static Context namingContext = null;
public static void bind(String name,HelloService object){
Hashtable ht = new Hashtable();
ht.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
ht.put(Context.PROVIDER_URL, "t3://localhost:7001");
try{
namingContext = new InitialContext(ht);
namingContext.rebind(name,object);
}catch(NamingException e){
e.printStackTrace();
}finally{
try{
namingContext.close();
}catch(Exception e){
e.printStackTrace();
}
}
}
public static void main(String args[]){
try{
HelloService service1 = new HelloServiceImpl("service1");
HelloService service2 = new HelloServiceImpl("service2");

bind("rmi://localhost:7001/HelloService1",service1);
bind("rmi://localhost:7001/HelloService2",service2);

System.out.println("the server has registered two HelloService Object");
}catch(Exception e){
e.printStackTrace();
}
}
}
--------------------------------------
在项目里引入weblogic.jar后,运行weblogic server,再运行服务器类即SimpleServer 就报错
javax.naming.CommunicationException [Root exception is java.rmi.ConnectIOException: error during JRMP connection establishment; nested exception is:
java.io.EOFException]
at com.sun.jndi.rmi.registry.RegistryContext.rebind(RegistryContext.java:142)
at com.sun.jndi.toolkit.url.GenericURLContext.rebind(GenericURLContext.java:231)
at javax.naming.InitialContext.rebind(InitialContext.java:408)
at chapter11.SimpleServer.bind(SimpleServer.java:15)
at chapter11.SimpleServer.main(SimpleServer.java:31)
。。。

...全文
3281 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
大西瓜hubery 2012-10-16
  • 打赏
  • 举报
回复
刚看到一个说法,说是weblogic相关包的问题,把其他weblogic包去掉,只保留了weblogic.jar,确实OK了,所以应该是weblogic相关jar包太多,引用类错误吧。
大西瓜hubery 2012-10-16
  • 打赏
  • 举报
回复
楼主这个问题有找到原因了吗?
鸿风 2011-10-19
  • 打赏
  • 举报
回复
我也遇到了!有木有人帮忙?
Stephen@Tang 2011-01-20
  • 打赏
  • 举报
回复
碰到同样的问题了
Exception in thread "main" java.io.IOException
at weblogic.management.remote.common.ClientProviderBase.makeConnection(ClientProviderBase.java:151)
at weblogic.management.remote.common.ClientProviderBase.newJMXConnector(ClientProviderBase.java:79)
at javax.management.remote.JMXConnectorFactory.newJMXConnector(JMXConnectorFactory.java:326)
at javax.management.remote.JMXConnectorFactory.connect(JMXConnectorFactory.java:247)
at cn.com.besttone.monitor.wls.WeblogicJmx.initConnection(WeblogicJmx.java:67)
at cn.com.besttone.monitor.wls.WeblogicJmx.main(WeblogicJmx.java:46)
Caused by: javax.naming.CommunicationException [Root exception is java.rmi.ConnectIOException: error during JRMP connection establishment; nested exception is:
java.io.EOFException]
at weblogic.jrmp.Context.lookup(Context.java:189)
at weblogic.jrmp.Context.lookup(Context.java:195)
at javax.naming.InitialContext.lookup(InitialContext.java:351)
at weblogic.management.remote.common.ClientProviderBase.makeConnection(ClientProviderBase.java:139)
... 5 more
Caused by: java.rmi.ConnectIOException: error during JRMP connection establishment; nested exception is:
java.io.EOFException
at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:273)
at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:171)
at sun.rmi.server.UnicastRef.newCall(UnicastRef.java:306)
at weblogic.jrmp.BaseRemoteRef.invoke(BaseRemoteRef.java:221)
at weblogic.jrmp.RegistryImpl_Stub.lookup(Unknown Source)
at weblogic.jrmp.Context.lookup(Context.java:185)
... 8 more
Caused by: java.io.EOFException
at java.io.DataInputStream.readByte(DataInputStream.java:243)
at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:215)
... 13 more
Jo_Cai 2009-03-20
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 java2000_net 的回复:]
服务连接失败。原因我也不清楚。

也许你应该简化你的测试代码。从最简单开始测试



[/Quote]
服务器是没有问题的,因为我写了最简单的 rebind 和 lookup代码是可以绑定,但用到RMI就不行了
Jo_Cai 2009-03-16
  • 打赏
  • 举报
回复
没有修改代码之前,使用rmiregistry注册远程对象的话,是可以的。换了用Weblogic就不行了
老紫竹 2009-03-16
  • 打赏
  • 举报
回复
服务连接失败。原因我也不清楚。

也许你应该简化你的测试代码。从最简单开始测试



Jo_Cai 2009-03-16
  • 打赏
  • 举报
回复
自己顶一下

67,541

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧