Win a copy of Terraform in Action this week in the Cloud 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

how to use local & remote intefaces in ejb3

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi
i am not able to understand the concept of local & remote


--------------

---------------------------

----------client---------





this bean is deploying properly but when i am running the client it is giving exception


Exception in thread "main" java.lang.NullPointerException
at com.ericsson.testApp.main(testApp.java:18)




 
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You must also deploy the client, or use JNDI to remotely invoke the bean.
 
author & internet detective
Posts: 40847
829
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sanjay,
Welcome to JavaRanch! I've added [ code ] tags to make your post easier to read.

There are a few ways of calling an EJB:
  • from a servlet and auto-injecting
  • from another EJB and auto-injecting
  • from an application client - don't remember if injecting works here
  • looking up the JNDI name
  •  
    sanjay nitwal
    Greenhorn
    Posts: 15
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Nick Potter wrote:You must also deploy the client, or use JNDI to remotely invoke the bean.




    hi
    i know remotly accessing ejb
    my question is how can i access it localy ? because it is giving nullpointer exception
     
    Ranch Hand
    Posts: 39
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    As already pointed out,

    A) if you're calling the ejb from a stand-alone client outside the jee container, then there are two things wrong with your approach:

    - the ejb needs to be remote
    - you cannot use resource injection ("@EJB"). you have to use jndi lookup instead.

    B) If on the other hand you're using your jee server application client container to run the client you may use injection but the ejb still needs to be remote (check this link : http://docs.sun.com/app/docs/doc/820-4336/beakv?a=view)


    To access an ejb locally, the client app needs to be part of the same deployed application, whether it is a servlet, an ejb or simply a pojo.
    Even inside the container, injection only works inside ejbs(3.0) and servlets (since 2.5, if I'm not mistaken), not POJOs. For the later, you do have to use jndi lookup.
    You may use the "java:comp/env/<BeanName>" jndi name if you're in case B and do define a reference to the ejb in your app-client dd. This is necessary for the container to create a reference to the ejb in that jndi tree.
    If you're in case A, you have to use the global jndi name to lookup your ejb, which you can get by checking your container's jndi browser.
     
    sanjay nitwal
    Greenhorn
    Posts: 15
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    hi

    I am calling the ejb from client inside the same jee container
    My application is working fine using jndi lookup but problem is how to use the (@EJB) dependency injection.



    :confused:
     
    Jonh Smith
    Ranch Hand
    Posts: 39
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Besides what others and i have already told you, i can only suggest further that you confirm that you're using an ejb 3.0 container and not a 2.1 one. I do suggest you read the link i provided you and the jee tutorial about ejbs .
     
    Ranch Hand
    Posts: 65
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    [quote]I am calling the ejb from client inside the same jee container[/quote]



    Your sample code does not look like you do it. I looks like it is standalone program outside of jee container.
     
    You showed up just in time for the waffles! And this tiny ad:
    Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    reply
      Bookmark Topic Watch Topic
    • New Topic