aspose file tools*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Accessing remote Ejb Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Accessing remote Ejb" Watch "Accessing remote Ejb" New topic
Author

Accessing remote Ejb

Sagar Shroff
Ranch Hand

Joined: Jun 07, 2011
Posts: 208

Hello Ranchers , i was trying a small example and i am facing a problem which i am not able to resolve.

I have an ejb bean which exposes remote service.I have deployed that bean in Jboss App Server.
I made a separate web module project which has a servlet in which i am accessing my remote bean.
like this :

and this is working fine for me.
What i did next was create another web module project which again has a servlet with similar code but deployed this web app in tomcat.
Now after deploying when i try to send request to servlet i get this java.lang.ClassNotFoundException: mypack.MyBeanRemote
i am not able to understand as i am new to this.Why did it work when i deployed it Jboss and why not with Apache.

Regards,
Shroff.

OCJP-90%,OCPWCD-95%
Frits Walraven
Creator of Enthuware JWS+ V6
Bartender

Joined: Apr 07, 2010
Posts: 1731
    
  25

Hi Sagar,

Tomcat doesn't have an EJB-container (or are you using TomEE?), so that won't work (it only contains a Servlet-container)

Regards,
Frits
Sagar Shroff
Ranch Hand

Joined: Jun 07, 2011
Posts: 208

Yeah i am using Tomcat . And i am aware that tomcat is not an ejb compliant app server.But i thought that ejb annotation was simply an abstract way of doing a JNDI (nothing Ejb specific) , the reason i thought so was because at the end of the day my servlet is going to be deployed in a Web container , so it is going to be managed by a Web container , so i thought that ejb complaint or not being ejb compliant wont make difference.

Regards,
Shroff.
gurpeet singh
Ranch Hand

Joined: Apr 04, 2012
Posts: 924
    
    1

Sagar Shroff wrote:Yeah i am using Tomcat . And i am aware that tomcat is not an ejb compliant app server.But i thought that ejb annotation was simply an abstract way of doing a JNDI (nothing Ejb specific) , the reason i thought so was because at the end of the day my servlet is going to be deployed in a Web container , so it is going to be managed by a Web container , so i thought that ejb complaint or not being ejb compliant wont make difference.

Regards,
Shroff.


dear Sagar,
even if you used JNDI to do lookup then also you wouldn't have got the reference to the bean. the reason is what Fritz pointed. there is no EJB CONTAINER. in other words there is no deploytime or runtime environment in which ejb's run. there wont be logical namespaces (java:app,java:module,java:global) available for the ejb since all this environment is provided by the ejb container.
Sagar Shroff
Ranch Hand

Joined: Jun 07, 2011
Posts: 208

dear Sagar,
even if you used JNDI to do lookup then also you wouldn't have got the reference to the bean. the reason is what Fritz pointed. there is no EJB CONTAINER. in other words there is no deploytime or runtime environment in which ejb's run. there wont be logical namespaces (java:app,java:module,java:global) available for the ejb since all this environment is provided by the ejb container.


If so then i am confused because how i can always do jndi lookup from a normal java standalone application which has no EJB container. Please rectify me where i am getting wrong in my understanding.

Regards,
Shroff
gurpeet singh
Ranch Hand

Joined: Apr 04, 2012
Posts: 924
    
    1

dependency injection is a service provided by the container. if there is no container then you cannot use dependency injection. in a stand alone client there is no container environment so you cannot use services provided by the container. when you do jndi lookup from your SE client then you are actually connecting to the naming service of your container and then lookup names from there. you specify the connection properties through the jndi environment and then use container-specific implementation of global jndi names(which are not portable; also I am not sure I have read about portable global jndi names which are new feature of ejb 3.1 that allows to do lookup in a portable manner).
Sagar Shroff
Ranch Hand

Joined: Jun 07, 2011
Posts: 208

gurpeet singh wrote:when you do jndi lookup from your SE client then you are actually connecting to the naming service of your container and then lookup names from there. you specify the connection properties through the jndi environment and then use container-specific implementation of global jndi names(which are not portable; also I am not sure I have read about portable global jndi names which are new feature of ejb 3.1 that allows to do lookup in a portable manner).


SE client means standard Java application ? i dint understood What SE means here ? if its java application then how can i connect to the naming service of container , because my java application is not deployed in any application server its a standalone client . I am really confused here . Can you please clarify my doubts . And What does portability means in context to jndi ? Can you also explain as this is a new concept to me in terms of jndi . Also a short defination of global jndi will be really awesome.


Regards,
Shroff.

Sagar Shroff
Ranch Hand

Joined: Jun 07, 2011
Posts: 208

And one more question which is popping in my mind is suppose if i have an Ejb service running in one application server , and the client who is going to invoke it is a remote client in another application server , So if i want to invoke that serviced then i would do a JNDI Global lookup right ? So thats what global means , for remote access ? And can i use EJB annnotation to get a reference to that remote service if yes then how ? because in the annotation we simply specify the ejb mapping name right ? also how can my remote client can do jndi lookup ? I am damn confused with all the concepts unclear to me like a fog .

Regards,
Shroff.
gurpeet singh
Ranch Hand

Joined: Apr 04, 2012
Posts: 924
    
    1

Dear Sagar,
java se application means stand-alone java application. let me explain you with a requirement. you have a ejb application running on a remote glassfish server. I want to access your say MyEjbBean from my standalone java application which is running on different physical machine. how would we do it ? . we cannot use @EJB annotation since there is no container environment in which we can run our standalone java application so we wont have dependency injection services . as you know that as per jee specifications , a container has to provide a naming support for the components , so there will be a naming environment on your remote glassfish server under which your ejb components will be bind. now until ejb 3. 0 there was no standardized or portable global jndi names. each vendor has its own format ( refer http://www.theserverside.com/news/1363649/New-Features-in-EJB-31-Part-5). we can connect with our glassfish server from our java standalone application and lookup our ejb's using the naming format provided by the vendor. as told earlier in case of ejb 3.1 this has been standardized . so even though your standalone java application is not running inside a application server , it can access/lookup ejb's or any other resources on your remote glassfish server.
Sagar Shroff
Ranch Hand

Joined: Jun 07, 2011
Posts: 208

Thank you so much for such good explanation .
I tried one example but it threw an exception i have posted it on the forum. Can you check and help me out ?

Regards,
Shroff
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Accessing remote Ejb