Discussions

EJB programming & troubleshooting: how to lookup a remote host jndi service

  1. how to lookup a remote host jndi service (2 messages)

    Can i lookup a ejb HOME INTERFACE in remote host using JNDI?
    please help me,thanks .
  2. how to lookup a remote host jndi service[ Go to top ]

      /**
       * Gets the home reference for an EJB associated
       * with the JNDI_Lookup_Name.
       */
    private Object lookupHome(String jndiName,
             String initialContextFactory,
             String providerURL) throws NamingException {
    Properties env = new Properties();
    env.put (Context.INITIAL_CONTEXT_FACTORY,
                                     initialContextFactory);
    env.put(Context.PROVIDER_URL, providerURL);
    Context ctx = new InitialContext(env);
    return ctx.lookup(jndiName);
    }

    you can use "weblogic.jndi.WLInitialContextFactory" for the initialContextFactory, "t3://127.0.0.1" for providerURL if you are using weblogic. jndiName is whatever name the object is bound to on the server.

    make sure you cast the object returned from the above method to the proper home interface
  3. how to lookup a remote host jndi service[ Go to top ]

    thank Amar. I had do it like you said, but when i lookup HOME INTERFACE, i got a NULL result.

    *********************** my code ********************
    String url = "rmi://192.168.1.168:6888";
    Context initCtx = null;
    HelloHome hellohome = null;
    try{
    Hashtable env = new Hashtable();
    env.put(Context.INITIAL_CONTEXT_FACTORY,
    "com.apusic.jndi.InitialContextFactory");
    env.put(Context.PROVIDER_URL, url);
    initCtx = new InitialContext(env);
    dfad }catch(Exception e){
    System.out.println("Cannot get initial context: " + e.getMessage());
    System.exit(1);
    }
    try{
    hellohome = (HelloHome)initCtx.lookup("HelloHome");

    // *****hellohome==null**********
      
    Hello hello = hellohome.create();
    String s = hello.getHello();
    System.out.println(s);
    }catch(Exception e){
    System.out.println(e.getMessage());
    System.exit(1);
    }
      
    *******************************************************