• 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

Using servlet to call EJB and give the response.

 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
I have an EJB application which is exposed as a service to other stand alone services. I have developed that EJB application in the Weblogic container. i have tested the EJB application using a standalone code. Now I have to use a web application that calls the EJB application and displays the result in the JSP.
I have planned to convert the code in the stand alone code to a servlet. Is this approach correct. If correct how do I get assess to various util classes that the standalone code uses.

What are the code change I have to do to my standalone code to act as a servlet?



Regards,
Arjun.
 
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Arjun,


You can convert your code to use Servelt so as to invoke an EJB.




props = new Properties(); props.put(Context.PROVIDER_URL, "t3://localhost:7001");props.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");ctx = new InitialContext(props);obj = ctx.lookup("TestApp");home = (TestHome)javax.rmi.PortableRemoteObject.narrow(obj, TestHome.class);



Have this code in the init() method of the servlet and store the home object in a member variable in the Servlet. [You should have that code in the init method which you want to initialise once and that can be reused by all the clients, please read Servlet specs for this]


Have all other code in your service method.


Now you compile the Servlet and bundle it in a war file. Have all the classes(util classes, stubs, home and remote interface of EJBs) in the WEB-INF/classes folder and all the jars in the WEB-INF/lib of the war. Have proper servlet mapping in the web.xml for the Servlet.

Hope this is what you are looking for in the Servelt.

Cheers,
Amit Tank
 
Arjun Karthick
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Amit,
Thanks for the guidence.
But again I have a doubt. The Ejb Home, remote and stub are part of that EJB application. How can i get the reference of those object. Should i do that by importing that is by adding that jar in the lib folder or by using the web.xml file i can give the reference to the EJB. Please advice on the same.

Regards,
Arjun.
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes you need to have the client jar file for the created EJBs . At the same time you need to create the reference so as to create an alias so that you can use a local reference for the global jndi so that your code remains safe from changes in global jndi name
 
reply
    Bookmark Topic Watch Topic
  • New Topic