3 Replies Latest reply on Aug 8, 2008 8:16 AM by Andrew Rubinger

    Context lookup

    ritesh udapudi Newbie

      I have the following interface and bean

      userProfile.java //interface
      userProfileBean.java //implementation

      and i do the following from a servlet

      private userProfile UserProfile;
      Context context = new InitialContext();
      UserProfile = (userProfile)context.lookup("userProfileBean/remote");

      It works fine. Im able to invoke the method and get the right return value.
      My query is wouldnt I(client) do a lookup based on the interface, rather than the bean?

      shouldn't the lookup be more like this
      UserProfile = (userProfile)context.lookup("userProfile/remote");

      I just started programming with EJBs and conceptually, lookin up an interface makes sense because the client wouldnt know about the bean implementation.

      Can someone clarify or point me to some link/tutorial which could help me?


        • 1. Re: Context lookup
          Wolfgang Knauf Master

          Hi !

          By default, JBoss places EJBs in JNDI according to this naming rules:
          -"EARName/BeanName/remote" for remote interfaces
          -"EARName/BeanName/local" for remote interfaces.
          If the EJB jar is not part of an EAR file, then "EARName" is not present.
          So, the lookup for "userProfileBean/remote" will find an interface annotated with "@Remote", while "userProfileBean/local" will find an interface annotated with "@Local".

          Hope this clears things


          • 2. Re: Context lookup

            Is there any chance to lookup an implementation of a SessionBean using simply the interface and not constructing a JNDI-Name where I would have to care about the prefix wheather it has been deployed in an ear or not?


            • 3. Re: Context lookup
              Andrew Rubinger Master

              The packaging-based prefix is a default to ensure unique bindings.

              You may use the JBoss-specific (ie. non-portable) @RemoteBinding.jndiBinding annotation to manually specify a JNDI target.