2 Replies Latest reply on Apr 23, 2003 4:56 AM by catharine

    JNDI Properties

    catharine Newbie

      I am new to JBoss and EJB.

      I jave just written a very simple EJB, and want to test it using my client application.

      How do I determine the properties to set in the InitialContext, and how can I write my client code so that I don't need to set them each time I get an InitialContext.


        • 1. Re: JNDI Properties
          Jon Barnett Master

          Your code fragment would run something like this to get a reference to the bean:

          Properties jndiProps = new Properties();
          jndiProps.setProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
          // Replace this with the URL to the JBoss JNDI if on a remote machine
          jndiProps.setProperty("java.naming.provider.url", "jnp://localhost:1099");
          jndiProps.setProperty("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
          // Get a naming context
          InitialContext jndiContext = new InitialContext(jndiProps);

          // Get a reference to the Bean by it's declared JNDI ref
          Object ref = jndiContext.lookup("Entries");

          // Get a reference from this to the Bean's Home interface
          BeanHome home = (BeanHome)PortableRemoteObject.narrow(ref, BeanHome.class);

          // Create a Bean object from the Home interface
          Bean beanObject = home.create();
          catch(Exception e)
          System.out.println("Unable to create Bean home");

          BeanHome should be substituted with your Bean's Home class.
          Bean is the interface class to your bean. To remotely use methods of your bean, the client only needs to know the interface and the home and does not nead the class with the actual bean code. Usually when building your EJBs for deployment, you pack what I call a client jar which holds these two classes, while the EJB jar has these and the implemented bean code class (as well as any other support classes). Hope that gives you a start.

          • 2. Re: JNDI Properties
            catharine Newbie

            Thanks for your help with this, it worked fine.