Getting InitialContext from client


EJB programming & troubleshooting: Getting InitialContext from client

  1. Getting InitialContext from client (2 messages)


    Forgive me if I'm being dense, but I can't figure out the "correct" way for an EJB client to get an InitialContext for the EJB container's JNDI root.

    I'd like to do it in a server-agnostic way, using the COS Naming Service, if possible, but this is proving elusive.

    I'm using Sun's reference J2EE SDK, and trying to connect to it from a standalone console app:

      Hashtable env = new Hashtable();
      env.put( Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.cosnaming.CNCtxFactory" );
      env.put( "org.omg.CORBA.ORBInitialPort", "1050" );
      Context context = new InitialContext( env );
      context.lookup( "java:comp/env" );

    This fails on the lookup() with a NameNotFoundException. It's binding to the ORB OK, on port 1050, which is the server's ORB port, and it's finding the NamingService, but it can't look up anything inside it.

    I'm obviously doing something wrong, but what?

    As an aside, is it possible to use the JNDI ENC on the client? This would remove the problem of getting the initial reference to the naming service.


  2. to get the context of the EJB container, u need to specify the context factory AND the provider url like so

    Properties p = new ...
    p.put(Context.INITIAL...) ;
    p.put(Context.PROVIDER_URL, "hostname:port") ;

  3. Yeah, I was actually using the wrong name in the lookup() call :-(

    The SDK uses so many different labels for the same component, I was getting lost.....