How do I access an EJB on a remote server?

I am using GlassFish-3.1.2 server running on my subnet ( I have already deployed an enterprise application that includes an EJB in which I have defined a business method. Now I want to remotely access the EJB from my Java application client. How do I configure JNDI accordingly. an InitialContext object for EJB lookup? How do I define properties? Btw. I had to run "asadmin enabled-secure-admin" to get the GlassFish server running on the local network. Perhaps I also need to send my credentials with properties?

Here's my current "solution", which seems to be completely wrong:

Properties props = new Properties();
props.setProperty("java.naming.factory.initial", "com.sun.enterprise.naming.SerialInitContextFactory");
props.setProperty("org.omg.CORBA.ORBInitialHost", "");
props.setProperty("org.omg.CORBA.ORBInitialPort", "3700");
InitialContext ctx = new InitialContext(props);

TestentityFacadeRemote tfr = (TestentityFacadeRemote)ctx.lookup("java:global/TestEE/TestEE-ejb/TestentityFacadeRemote");


When I run this program, it just waits indefinitely ...

Any help is greatly appreciated!


source to share

1 answer

I solved the problem by setting the host and port directive to System.setProperty () and using the default constructor to initialize InitialContext (). Please note that the following lines must be the very first in your program / main method:

public static void main(String[] args) {
    System.setProperty("org.omg.CORBA.ORBInitialHost", "");
    System.setProperty("org.omg.CORBA.ORBInitialPort", "3700");
    InitialContext ctx = new InitialContext();
    TestentityFacadeRemote tfr = (TestentityFacadeRemote)ctx.lookup("java:global/TestEE/TestEE-ejb/TestentityFacadeRemote!com.acme.remote.TestentityFacade");


Hope it helps ...



All Articles