是否需要任何特定的 Glassfish 配置才能允许跨 LAN 进行远程 CORBA 查找?或者,路由器防火墙是否需要配置?
我该怎么做troubleshoot这个连接?
CORBA lookup client只是挂起:
BUILD SUCCESSFUL
Total time: 3 seconds
Nov 22, 2014 3:45:26 AM aggregatorclient.AggregatorClient remoteEJB
WARNING: {org.omg.CORBA.ORBInitialPort=3700, java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, Context.SECURITY_CREDENTIALS=pass123, org.omg.CORBA.ORBInitialHost=192.168.0.119, java.naming.factory.url.pkgs=com.sun.enterprise.naming, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, Context.SECURITY_PRINCIPAL=user1}
当从本地主机(即从本地主机,连接到本地主机)运行时,所有内容都在同一台计算机上,连接工作正常。
CORBA 连接查找参数,位于jndi.properties
中:
java.naming.factory.initial=com.sun.enterprise.naming.SerialInitContextFactory
java.naming.factory.url.pkgs=com.sun.enterprise.naming
java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl
Context.SECURITY_PRINCIPAL=user1
Context.SECURITY_CREDENTIALS=pass123
org.omg.CORBA.ORBInitialHost=192.168.0.119
org.omg.CORBA.ORBInitialPort=3700
连接客户端代码:
package aggregatorclient;
import dur.ejb.AnswerSessionBeanRemote;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
public class AggregatorClient {
private static final Logger log = Logger.getLogger(AggregatorClient.class.getName());
public static void main(String[] args) {
try {
new AggregatorClient().remoteEJB();
} catch (NamingException ex) {
Logger.getLogger(AggregatorClient.class.getName()).log(Level.SEVERE, null, ex);
}
}
private void remoteEJB() throws NamingException {
Context ctx = new InitialContext();
log.warning(ctx.getEnvironment().toString());
Object obj = ctx.lookup("dur.ejb.AnswerSessionBeanRemote");
AnswerSessionBeanRemote asbr = (AnswerSessionBeanRemote) obj;
log.info("answer\t" + asbr.lifeTheUniverseAndEverything());
}
}
client使用 Glassfish appclient
执行。
请您参考如下方法:
与在远程主机上运行的独立 ejb 客户端具有相同的“永远挂起”查找行为。事实证明,这与服务器主机将自己的主机名解析为自己的非环回地址的能力有关。我通过在 /etc/hosts
中添加/修复条目解决了这个问题:
10.0.10.102 my-server-hostname
我检查了服务器实际上可以使用 hostname -i
解析正确的 IP 地址:
$ hostname -i
10.0.10.102
重新启动 GlassFish 后,远程查找和调用 EJB 变得非常神奇!
说明
我在嗅探客户端和服务器之间的流量后找到了这个解决方案。底层协议(protocol)是GIOP(没听说过)。
执行远程查找时,我客户的请求实际上能够到达GlassFish。但服务器回复了一个误导性的“位置转发”响应,将 127.0.1.1
指示为 IIOP:Profile_host
。 127.0.1.1
是我修复 /etc/hosts
之前我的服务器主机名解析到的环回 IP 地址。