Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to write EJB client?

 
Shyam kumar
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Greeting Ranchers,
This is my first EJB application.
I have to create a web client to the Advice EJB. The idea is to create a simple GetAdvice.jsp and a servlet. The servlet will lookup the advice bean and display the advice. To achieve this I created a j2ee project and added the Advice EJB. Now I created another dynamic web project with the servlet and jsp. In the deployment descriptor I added the ejb-ref name and type as the lookup name and jndi name respectively.
In the service method I'm looking up the enterprise bean.

Context ic = new InitialContext();
Object o = ic.lookup("ejb/Advice");
Advice ad = (Advice) PortableRemoteObject.narrow(o,Advice.class);

I'm using WSAD 5.1. In this way will I be able to retreive the remote bean?
[ February 28, 2007: Message edited by: Naveen Sharma ]
 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Object o = ic.lookup("ejb/Advice");


I guess the lookup should be java:/comp/env/ejb/Advice

Give it a try and let us know if that doesnt work
 
Shyam kumar
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okie, thanks... I'll try it and let you know. Btw I'm still very doubious about all this I mean, we are not making any declarative provisions at the client end expect for ebj-ref tag in the web.xml. Any client I create with the ejb package in the class path will be able to access the ejb? I read somewhere that some client.jar needs to be created. Not sure though
 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any client I create with the ejb package in the class path will be able to access the ejb?


As long as the jndi name is known to the client, any client can always lookup the bean. If however you want to restrict access to some beans to some specific roles then you can do that by securing the EJB.
 
Shyam kumar
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks mate... That's a confidence booster, I'll try it and let you know
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic