users@glassfish.java.net

Remote server: bean call

From: <glassfish_at_javadesktop.org>
Date: Wed, 30 Jun 2010 06:57:54 PDT

Hi,

We are developing a project on Glassfish v3 (version build 74.2) that runs on multiple physical machines. We want to call (remote-interface) methods in beans on one server from within beans on the other server. On the Glassfish dev website (https://glassfish.dev.java.net/javaee5/ejb/EJB_FAQ.html#cross-appserverremoteref) I thought I had found the way to do this, but this does not seem to work. In the last few days I searched the internet for answers and tried maybe over 50 possibilities to make it work, but I always get exceptions when doing the lookup. Let me try and sketch the situation.

On server A, I have a jar deployed called MailSender.jar. In that jar, I have two classes:
MailSenderRemote : interface with @Remote annotation and sendMail()-method
MailSenderBean : class with @Stateless annotation and implements the sendMail()-method
I also have the MailSender.jar copied to the domains/domain1/lib folder

When deploying, I find in the server.log file of server A:

[#|2010-06-30T10:32:21.563+0200|INFO|glassfishv3.0|javax.enterprise.system.container.ejb.com.sun.ejb.containers|_ThreadID=23;_ThreadName=Thread-1;|Portable JNDI names for EJB MailSenderBean : [java:global/MailSender/MailSenderBean, java:global/MailSender/MailSenderBean!com.test.MailSenderRemote]|#]

[#|2010-06-30T10:32:21.563+0200|INFO|glassfishv3.0|javax.enterprise.system.container.ejb.com.sun.ejb.containers|_ThreadID=23;_ThreadName=Thread-1;|Glassfish-specific (Non-portable) JNDI names for EJB MailSenderBean : [mailsender, mailsender#com.test.MailSenderRemote]|#]

On server B, I have a jar deployed called AlarmSender.jar. In that jar, I also have two classes:
AlarmSenderRemote : interface with @Remote annotation and sendAlarm()-method
AlarmSenderBean : class with @Stateless annotation and implements the sendAlarm()-method in which a call is made to the sendMail()-method.
I also have the MailSender.jar and the AlarmSender.jar copied to the domains/domain1/lib folder

Now, on server B I also have another jar called AlarmSenderProcess.jar which only has a main class with a ‘public static void main(String[] args)’ method. In that main-method, we do a lookup of the AlarmSender bean using the code:
InitialContext icx = new InitialContext();
AlarmSenderRemote alarmSender = (AlarmSenderRemote)icx.lookup(“com.test.AlarmSenderRemote”);
Once we have done the lookup, we call the sendAlarm()-method on the returned AlarmSenderRemote-object.

We run this jar using following command:
Java –Dorg.omg.CORBA.ORBInitialHost=127.0.0.1 –jar AlarmSenderProcess.jar

Now, what we see is that the standalone-client does not cause a problem, because the AlarmSenderRemote bean is correctly found and the sendAlarm()-method is executed.
However, the lookup of the MailSenderRemote (which only runs on server A) inside the sendAlarm()-method always fails.

I have tried to do the lookup in several ways:
1) Completely follow the instructions on https://glassfish.dev.java.net/javaee5/ejb/EJB_FAQ.html#cross-appserverremoteref, and in the sun-ejb-jar.xml, fill in “<jndi-name>corbaname:iiop:10.1.1.2:3700#java:global/MailSender/MailSenderBean</jndi-name>” instead of “<jndi-name>corbaname:iiop:host2:3700#Foo</jndi-name>”
2) Don’t use injection using the @EJB annotation, but use a lookup with a ‘InitialContext icx = new InitialContext()’ and then icx.lookup(“corbaname:iiop:10.1.1.2:3700#java:global/MailSender/MailSenderBean”);
3) Same as 2), but don’t use the empty-argument constructor for the InitialContext, but use Properties and add (one or more) of the following properties:
a. Java.naming.factory.initial : com.sun.enterprise.naming.impl.SerialInitContextFactory OR com.sun.jndi.cosnaming.CNCtxFactory
b. Java.naming.factory.url.pkgs : com.sun.enterprise.naming
c. Java.naming.factory.state : com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl
d. Java.naming.provider.url : iiop://10.1.1.2:3700
e. Org.omg.CORBA.OMGInitialHost : 10.1.1.2
f. Org.omg.CORBA.OMGInitialPort : 3700
4) Same as 3) but for the lookup use: icx.lookup(java:global/MailSender/MailSenderBean)
5) 1), 2) and 3) but replaced: ‘10.1.1.2:3700’ with ‘1.2_at_10.1.1.2:3700’
6) Use @EJB injection, but don’t use sun-ejb-jar.xml and as arguments for the @EJB use: @EJB(mappedName=” corbaname:iiop:10.1.1.2:3700#java:global/MailSender/MailSenderBean”)

But none of these methods above work….A bit strange, since a couple of them are literally described by Glassfish as the correct way to do it…
I also tried to do ‘ctx.list()’ and print out the result. Again, just like in 2) and 3) initializing the InitialContext in different ways, but the strange thing is that it never returned me the beans that were deployed on server A, even if I set the org.omg.CORBA.OMGInitialHost and the java.naming.provider.url to the ip-address and port of server A, it always returns me the beans that are deployed on server B…

Anyhow, I would really appreciate it if somebody could finally tell me how I could manage to do something really simple like calling a method on a remote bean.

Kind regards,
Jan De Beule
[Message sent by forum member 'jandebeule']

http://forums.java.net/jive/thread.jspa?messageID=476407