This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

How to write EJB client?  RSS feed

 
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 ]
 
Sheriff
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
Sheriff
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!