• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to write EJB client?

 
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic