【发布时间】:2015-12-09 05:58:24
【问题描述】:
这是我的客户代码
package com.tutorialspoint.test;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Properties;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import com.tutorialspoint.stateless.testRemote;
public class test
{
BufferedReader brConsoleReader = null;
Properties props;
static InitialContext ctx;
{
props = new Properties();
try {
props.load(new FileInputStream("jndi.properties"));
} catch (IOException ex) {
ex.printStackTrace();
}
try {
ctx = new InitialContext(props);
} catch (NamingException ex) {
ex.printStackTrace();
}
brConsoleReader =
new BufferedReader(new InputStreamReader(System.in));
}
public static void main(String[] args)
{
test _test = new test();
try {
testRemote libraryBean =(testRemote)ctx.lookup("java:global/TestEjb/testBean!
com.tutorialspoint.stateless.testRemote");
} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
这是部署在服务器上
package com.tutorialspoint.stateless;
import javax.ejb.Stateless;
@Stateless
public class testBean implements testRemote
{
public void hello()
{
System.out.println("hello");
}
}
package com.tutorialspoint.stateless;
import javax.ejb.Remote;
@Remote
public interface testRemote
{
void hello();
}
我在服务器端遇到异常:
19:09:12,676 错误 [org.jboss.remoting.remote.connection](远程处理“cognam-
pc-26" read-1) JBREM000200:远程连接失败: java.io.IOException: 一个现有的连接被
强行关闭 远程主机
我在客户端遇到异常:-
javax.naming.CommunicationException:无法获得连接 到这些网址中的任何一个: localhost:4447 并且发现失败并出现错误: javax.naming.CommunicationException:接收超时[根异常 是 java.net.SocketTimeoutException: 接收超时] [根异常 是 javax.naming.CommunicationException:无法从中检索存根 服务器 localhost:4447 [根异常是 java.io.StreamCorruptedException:
无效的流标头:0000000F]]org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:1414) 在 org.jnp.interfaces.NamingContext.lookup(NamingContext.java:594) 在 org.jnp.interfaces.NamingContext.lookup(NamingContext.java:587) 在 javax.naming.InitialContext.lookup(InitialContext.java:392) 在 com.tutorialspoint.test.test.main(test.java:37)
【问题讨论】:
-
它只被调用一次
-
那我猜你的剪切和粘贴不正确或者我看错了,我会删除我的cmets。
-
这可能是您的服务器实际上不允许连接到 4447。检查您是否可以 telnet 到该端口或使用 netstat -an 查询。