从远程客户端获取初始上下文 [英] Obtaining initial context from remote client

查看:133
本文介绍了从远程客户端获取初始上下文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请参见下面的代码:

Context ctx = null;
ctx=new InitialContext();
TestEJBRemote t = (TestEJBRemote) ctx.lookup("java:global/EJBTest/EJBTest-ejb/TestEJB");
System.out.println(t.getName("Ian"));

输出是我所期望的,即Ian,你好.

The output is what I expect i.e. Hello Ian.

上面的代码假定客户端与Glassfish实例安装在同一台计算机上.我如何从远程应用程序客户端获得相同的结果.我已经尝试过了:

The code above assumes that the client is installed on the same computer as the Glassfish instance. How do I get the same result from a remote application client. I have tried this:

Context ic = new InitialContext();
        TestEJBRemote t = (TestEJBRemote) ic.lookup("corbaname:computer:4848#/a/b/TestEJB");
        System.out.println(t.getName("Ian"));

这会产生错误.我认为该端口是安装Glassfish的端口.

which produces an error. I assume that the port is the port that Glassfish is installed on.

推荐答案

对于连接到GlassFish和Payara的远程客户端,我通常使用以下命令:

For remote clients connecting to GlassFish and Payara, I normally use the following:

Properties props = new Properties();  
props = new Properties();
props.setProperty("java.naming.factory.initial",
    "com.sun.enterprise.naming.SerialInitContextFactory");
props.setProperty("java.naming.factory.url.pkgs",
    "com.sun.enterprise.naming");
props.setProperty("java.naming.factory.state",
    "com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl");
props.setProperty("org.omg.CORBA.ORBInitialHost", "127.0.0.1");
props.setProperty("org.omg.CORBA.ORBInitialPort", "3700");
InitialContext ctx = new InitialContext(props);

MyBeanRemote bean = (MyBeanRemote) ctx.lookup("com.example.MyBean");

从您的示例中我可以想象,您的原始查询将在这种情况下起作用:

I would imagine, from your example, that your original lookup would work in this scenario:

TestEJBRemote t = (TestEJBRemote) ctx.lookup("java:global/EJBTest/EJBTest-ejb/TestEJB");

如果您有多个远程端点,则可以使用以下方法在它们之间进行负载平衡:

If you have multiple remote endpoints, you can load balance between them with the following:

Hashtable env = new Hashtable();
env.put("com.sun.appserv.iiop.endpoints","host1:port1,host2:port2,...");
InitialContext ctx = new InitialConext(env);


参考: https://docs. oracle.com/cd/E26576_01/doc.312/e24930/java-clients.htm#GSDVG00075

这篇关于从远程客户端获取初始上下文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆