• 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Look up code for EJB

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have a servlet that will call an ejb. I need to find two things:
1. the code to put into the servlet to do the lookup for the ejb.
2. should I put that lookup code into the init() of the servlet and then call my business methods from another method in the servlet?
Thanks,
Steve
 
author
Posts: 3892
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, EJB references are not guaranteed to be threadsafe, so you should probably look up your EJB reference everytime you do a doPost() or a doGet() method, rather than in the init() method. Just do the lookup then call the business methods one right after the other.
(Hopefully you're talking about using a stateless session bean, right? If not, we've got more to talk about )
Kyle
------------------
Kyle Brown,
Author of Enterprise Java (tm) Programming with IBM Websphere
See my homepage at http://members.aol.com/kgb1001001 for other WebSphere information.
 
steve dowdall
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Kyle,
Yup, SSB is what we are talking about. Per your suggestion I'll put it in a service method instead of the init(). Do you have a snippet of code perhaps that I would use to do the ejb lookup from this method?
Steve
 
Kyle Brown
author
Posts: 3892
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Look around page 54 of the EJB 1.1 specification. Reading that chapter should fill you in pretty well...
It will basically go:
// first set up a properties to correctly get an initial context
//(the details are dependent on your app server)
InitialContext initContext = new InitialContext(properties);
Object ref = initContext.lookup("someJndiName");
MyHome home = (MyHome) PortableRemoteObject.narrow(ref, MyHome.class);
MyEJB ejb = MyHome.create();

Kyle
------------------
Kyle Brown,
Author of Enterprise Java (tm) Programming with IBM Websphere
See my homepage at http://members.aol.com/kgb1001001 for other WebSphere information.
 
steve dowdall
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a bunch!
 
Water! People swim in water! Even tiny ads swim in water:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic