JEE6: Servlet calling an EJB through @Remote, DI or JNDI ?
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.
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.
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.
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.
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 ....
Knowing that this won't work.
But did try it with EJB-injection.
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 = 126.96.36.199 ) call a SLSB deployed on another glassfish on a different machine ( say ipnr = 188.8.131.52).
If I solve this I will be more than glad to make a tutorial distributed here or elsewere.
best regards, Ingo