Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access EJB on remote server?

I am using a GlassFish-3.1.2 server running in my subnet (192.168.1.3:3700). I already deployed an enterprise app including an EJB in which i defined a business method. Now I want to remotely access the EJB from my java application client. How do i have to setup the JNDI resp. the InitialContext object for doing the lookup of the EJB ? How do I need to define the properties? Btw. I had to run "asadmin enabled-secure-admin" in order to make the GlassFish server work on the LAN. Probably I also need to send my credentials with the properties ?

Here's my current "solution", which seems to be completley 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 programm, it just waits infinitely...

Any help highly appreciated!

like image 564
salocinx Avatar asked Apr 28 '26 11:04

salocinx


1 Answers

I solved the problem by setting the host and port directy by System.setProperty() and using the default constructor for initializing the InitialContext(). Note that the following lines should 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 this helps ...

like image 194
salocinx Avatar answered Apr 30 '26 00:04

salocinx



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!