Skip to main content

JEE6: Servlet calling an EJB through @Remote, DI or JNDI ?

2 replies [Last post]
Inkimar68
Offline
Joined: 2011-11-25
Points: 0

Hi !

Using JEE6 ( EJB 3.1 ) , the Latest Glassfish ( ver 3.1.2 ) and Maven 3.
I am Using Netbeans 7.3 as my IDE.

In the tutorial Java EE 6 ( http://docs.oracle.com/javaee/6/tutorial/doc/bnaay.html ) there is a figure that shows a Multitiered Application - using that figure as a reference in my example.

Issue:
I would like to be able to deploy my Servlet on one Glassfish domain and my EJB on another, making a Remote ( RMI ) Servlet call to the EJB.
Used plenty of resources out there ( googling and youtubing ) but nothing seems to help me, most of the examples out there use J2SE as a client ( and I have succeeded with that ).

Example 1a is working, example 2 is not working.

Ex 1) Deployment in the same Glassfish domain.

a)
I have created 2 projects ; 1 EJB-Module and 1 WEB-application + utility.jar ( choosing not to use the Enterprise Application alternative in Netbeans ).
My EJB-module contains a Stateless Session bean ( SLSB ) with 2 interfaces ( @Remote and @Local ).The return a String: "Hello".

The utility.jar holds the @Remote-interface.
The EJB-module and the WEB-application are dependant on the utility.jar-project.

My WEB-application contains a Servlet, the Servlet uses the SLSB - I use JNDI to fetch the reference to my SLSB.
I deploy the EJB-Module and WEB-applicatioin in the same Glassfish-domain ( domain-1).
Everything works fine.

b)
Throwing out JNDI from my Servlet and replacing it with an EJB-injection, not working.
I do not understand that. I get an rmi-exception.

Ex 2) Deployment in different Glassfish domains.

a)
Same configuration as in Ex 1a ( using JNDI )
I create a new domain in Glassfish, domain2.
I deploy the EJB-module in domain1 and the WEB-application in domain2.
My Servlet does not find the SLSB, I get a rmi-exception.
- Here I have some understanding, that domain2 does not know of domain1 - that I should be able to configure the ip-adress and jndi-port somewhere , but I do not know where ....

b)
Knowing that this won't work.
But did try it with EJB-injection.
rmi-exception.

Reflection:
I have been able to call my EJB from a J2SE main-method and from an Applet ....
That is a bit puzzling to me, that I am able to do that ... but not be able to make that call using a Servlet as a client ...

So my question to you is :
How can a Servlet deployed on one Glassfish domain call an SLSB on another Glassfish domain ?

And when that question is answered, how can a Servlet deployed on one glassfish on a standalone machine ( say ipnr = 1.2.3.4 ) call a SLSB deployed on another glassfish on a different machine ( say ipnr = 1.2.3.5).

If I solve this I will be more than glad to make a tutorial distributed here or elsewere.

best regards, Ingo

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
kizipro57

Thanks you share info . hjhj

Inkimar68
Offline
Joined: 2011-11-25
Points: 0

Hi !

Did that help you in any way ?

regards, i