2 Replies Latest reply on Oct 19, 2004 5:37 AM by dragospd

    jndi problem, please help

    dragospd

      I write a simple session session bean and a java client that access the bean. here is the client:

      import javax.naming.InitialContext;
      import javax.rmi.PortableRemoteObject;
      
      class InterestClient
      {
       public static void main(String[] args)
       {
       try
       {
       // Get a naming context
       InitialContext jndiContext = new InitialContext();
       System.out.println("Got context");
       Object ref = jndiContext.lookup("java:comp/env/ejb/rdcs/checkin/TestServiceSession");
       System.out.println("Got reference");
      
       }
       catch(Exception e)
       {
       System.out.println(e.toString());
       }
       }
      }
      


      Here is the java:comp namespace of the session bean:

      java:comp namespace of the TestServiceSession bean:
      + env (class: org.jnp.interfaces.NamingContext)
      | + ejb (class: org.jnp.interfaces.NamingContext)
      | | + rdcs (class: org.jnp.interfaces.NamingContext)
      | | | + checkin (class: org.jnp.interfaces.NamingContext)
      | | | | + TestServiceSession[link -> ejb/rdcs/checkin/TestServiceSession] (class: javax.naming.LinkRef)

      Here is the jndi.properties file content:

      java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
      java.naming.provider.url=jnp://localhost:1099
      java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces

      And here is the result:
      Got context
      javax.naming.NameNotFoundException: comp not bound

      I don't understand these result, where could be the error?. If I replace the java:comp/env with the direct root jndi path (ejb/rdcs/checkin/TestServiceSession) to the bean it works.

      Anyone with an answer, please?



        • 1. Re: jndi problem, please help
          darranl

          If I replace the java:comp/env with the direct root jndi path (ejb/rdcs/checkin/TestServiceSession) to the bean it works.

          The way that works is the correct way to do it.

          The java:comp/env namespace you are accessing is the private namespace of a component that can not be accessed by your client.

          Additionaly in general remote clients can not access anything prefixed with 'java:'

          • 2. Re: jndi problem, please help
            dragospd

            Thank you. In the mean time I found myself the answer reading the JBOSS online docs. here is the specs:

            An application component environment is a local environment that is accessible only by the component when the application server container thread of control is interacting with the application component. This means that an EJB Bean1 cannot access the ENC elements of EJB Bean2, and visa-versa. Similarly, Web application Web1 cannot access the ENC elements of Web application Web2 or Bean1 or Bean2 for that matter. Also, arbitrary client code, whether it is executing inside of the application server VM or externally cannot access a component's java:comp JNDI context. The purpose of the ENC is to provide an isolated, read-only namespace that the application component can rely on regardless of the type of environment in which the component is deployed. The ENC must be isolated from other components because each component defines its own ENC content, and components A and B may define the same name to refer to different objects. For example, EJB Bean1 may define an environment entry java:comp/env/red to refer to the hexadecimal value for the RGB color for red, while Web application Web1 may bind the same name to the deployment environment language locale representation of red.

            thanx for your quick answer, I was stucked with this problem a whole day
            anyway it's very hard to find this answer on the net.