How do I access an EJB on a remote server?

I am using GlassFish-3.1.2 server running on my subnet (192.168.1.3:3700). 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", "192.168.1.3");
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!

+3


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", "192.168.1.3");
    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 ...

+6


source







All Articles