我有一个 EJB 容器,部署在 Amazon AWS Fedora 8 虚拟机上的 JBoss 5.1 上。我有另一个应用程序,我想通过 Internet 远程访问此 EJB 容器。但我收到以下异常
javax.naming.CommunicationException [Root exception is java.rmi.ConnectException: Connection refused to host: xxx.xxx.xx.x; nested exception is: java.net.ConnectException: Connection timed out]
Caused by: java.rmi.ConnectException: Connection refused to host: xxx.xxx.xx.x; nested exception is: java.net.ConnectException: Connection timed out
Caused by: java.net.ConnectException: Connection timed out
这里xxx.xxx.xx.x
是运行EJB的机器的内部IP。
这是我用来访问它的代码
Properties props = new Properties();
props.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
props.setProperty(Context.INITIAL_CONTEXT_FACTORY,org.jboss.security.jndi.JndiLoginInitialContextFactory");
props.setProperty(Context.PROVIDER_URL, "<external-ip>:1099");
props.put("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
props.put("java.naming.factory.url.pkgs","org.jboss.naming:org.jnp.interfaces");
props.put("java.naming.provider.url", "jnp://<external-ip>:1099");
InitialContext ic = new InitialContext(props);
ic.lookup("EJBName");
我还编辑了 /etc/hosts
文件,例如
127.0.0.1 localhost.localdomain localhost
xxx.xxx.xx.x hostname alias
并启动 JBoss
-Djboss.bind.address=0.0.0.0 -Djava.rmi.server.hostname=xxx.xxx.xx.x -Dremoting.bind_by_host=false
我想我已经完成了所有必要的配置和正确的代码,但似乎不起作用。请帮我解决这个问题,它已经困扰我一个多星期了。出于安全考虑,我们很抱歉隐藏了实际的 IP。
最佳答案
连接超时 这可能是防火墙问题。验证端口是否打开:http://www.canyouseeme.org/
您还可以尝试设置属性:“org.omg.CORBA.ORBInitialHost”和“org.omg.CORBA.ORBInitialPort”。
关于java - 远程 EJB 接口(interface)无法通过 Internet 工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4706411/