0

Please see the code below:

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

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

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"));

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

w0051977
  • 15,099
  • 32
  • 152
  • 329

1 Answers1

2

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);

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

Mike
  • 4,852
  • 1
  • 29
  • 48
  • Thanks. That does work. Why does your context lookup path contain full stops whilst mine contains forward slashes? +1 for the answer. – w0051977 Sep 29 '16 at 12:35
  • It's just an example I ripped from the Oracle docs linked, and made a bit clearer. In that lookup, it's just the bean itself and its package, whereas you have (rightly) used a global lookup and include the `appname/EJB-JAR-name/BeanName` path. – Mike Sep 29 '16 at 12:40