1 Reply Latest reply on Feb 17, 2008 9:02 AM by jaikiran pai

    JNDI looking up problem from servlet container

    Krzysztof Malinowski Newbie

      Hi,

      I made a very simple session bean which has only one for testing purposes business method 'saying':

      public String saying(String name) throws EJBException {
       // rename and start putting your business logic here
       return "Have a nice day " + name;
       }


      The bean was deployed correct, notified by JBoss (actually 4.0.3):

      14:26:10,824 INFO [EjbModule] Deploying Hello
      14:26:11,073 INFO [EJBDeployer] Deployed: file:/D:/jboss-4.0.2/server/pzuci/deploy/HelloEJB.jar/

      Then I made a test client, the core part of that is:

      public static void main(String[] args) {
       // TODO Auto-generated method stub
       Hashtable<String, String> props = new Hashtable<String, String>();
       props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
       props.put(Context.PROVIDER_URL, "localhost:1099");
      
       try {
       Context cx = new InitialContext(props);
       HelloHome helloHome = (HelloHome) cx.lookup("java:/Hello");
       Hello hello = helloHome.create();
       System.out.println(hello.saying("Jhon B"));
       hello.remove();
       } catch (Exception e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
       }
       }


      It works fine, but if I tried to addapt the same manner into the simple test servlet, it didn't work. I used the same proxy to the interfaces:

      Hashtable<String, String> props = new Hashtable<String, String>();
       props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
       props.put(Context.PROVIDER_URL, "localhost:1099");

      I don't get exspected message from the business method 'saying', instead the test servelt notifies me:

      Hello not bound

      How should I obtain the home EJB interface from servlet container?

      I'd be glad for some help
      KM

        • 1. Re: JNDI looking up problem from servlet container
          jaikiran pai Master

          Looks like you have specified an incorrect jndi-name for the lookup string (Actually i am surprised as to how it worked with the test client using java:Hello jndi-name, since the java: is not available to remote clients). Follow the steps below to figure out what the jndi-name of the bean is and then use that name to do the lookup:

          - Go to http://< server>:< port>/jmx-console (Ex: http://localhost:8080/jmx-console)
          - Search for service=JNDIView on the jmx-console page
          - Click on that link
          - On the page that comes up click on the Invoke button beside the list() method
          - The page that comes up will show the contents of the JNDI tree.

          Search for your bean here and find out what's it jndi-name. The use it in your code during the lookup.