Getting the InitialContext in Websphere 4.0


EJB programming & troubleshooting: Getting the InitialContext in Websphere 4.0

  1. Getting the InitialContext in Websphere 4.0 (11 messages)

    Hi Guys,
      Here is what I have
    1. Websphere 4.0 App server (Evaluation copy)
    2. And have a peiece of code

    java.util.Properties p = new java.util.Properties();
    p.putContext.INITIAL_CONTEXT_FACTORY, "");
    p.put(Context.PROVIDER_URL, "iiop://pgh2393:900/");
    InitialContext jndiContext = new InitialContext(p);

    Object ref = jndiContext.lookup("DealInfo");
    DealInfoHome home = (DealInfoHome) PortableRemoteObject.narrow(ref, DealInfoHome.class);
    deal = home.create();

    Am getting exception as below
    javax.naming.ServiceUnavailableException: NULL returned when resolving initial reference=NameService





    at javax.naming.spi.NamingManager.getInitialContext(

    at javax.naming.InitialContext.getDefaultInitCtx(

    at javax.naming.InitialContext.init(

    at javax.naming.InitialContext.<init>(




    Any help ! Any suggestion is welcomed.

    Thanks in advance

  2. Vivek,

    this is the path for the new initial context factory on 4.0

    also make sure the naming service is listening on the correct port in ur case 900.

    the default for 4.0 is i think 9070. u can ofcourse change it using the web-based admin console.

    hope this helps, lemme know

  3. Kapil,
      I tried using the port no. 9070.But still the same exception is thrown.
      And FYI, the Client is Swing based.And it is not running in the App server.
      Moreover, While installing app server I got two errors about some DLL's(Not able to write to xyz DLL).I just ignored it bcoz it was for HTTP setup.This my understanding so far.Pls correct me if am wrong.

  4. Kapil,
      In the admin tool this is what I found.
        host: localhost
        port: 9070
        provider class:

      Now, Is that I need to specify this class name instead.
    (Am not able to find this class in any jar, under c:\websphere\AppServer)

     Kapil, This is the first time am using websphere. May be there are some tweeks to be performed.Pls let me know if am missing some thing.

  5. Vivek,

    i just had a look at server-cfg.xml and it looks the ORB service is running on port 900. so u r fine with port.

    and the provider class u mentioned - is a driver class for IBM jndi service. this is not the one to be used.

    also i just checked out u r fine using the class- for initial context cause in turn it calls on the new lib , i.e,

    but its better to use the new lib.

    so ur earlier piece of code looks fine. it shud work as it is.

    i tried out ur piece of code and it runs fine, though my client is within the app server. u might wanna try writing a servlet client first and see whether ur JNDI service is actually listening on the port or not. i suspect it isnt. but try with a servlet first.

    lemme know, we will try n work this thing out


  6. Kapil,
      I appreciate your time and efforts for figuring out the problem.I haven't still not done with the problem.
      Besides, Kapil here are some basic qns which I have to make sure before running all over the app server.
      1.Am using the websphere(adv ver. 4.0) deploy tool,They call it assembly tool.I could see that all properties are being set properly.When I select "Generate Code for deployment" option.It verifies and finally says that "ejb deployed" and 0 errors.
      Now, does this mean that the ejb is truly deployed, And is that I need to restart the app server.
      The problem is,It is not creating the Client jar file.
    It should create automatically right?




  7. when its says "ejb deployed", it merely means that the jar file generated can now be deployed on the app server(it just creates the stub n skeleton for remote objects). so u will have to go to the admin console and deploy it. also the admin console will again ask whether u wanna re-create the deployment jar. u can choose not to create these files.

  8. Hi,
    I have the ame problem as posted by vivek.
    Let me clearify some of my doubts regarding WebSphere4.0.
    1)I'm runnign websphere in 128 mb RAM and 550 Mhz PIII processor.When i use aseembly tool it takes around 50 min. to generate a EAR file from Eejb jar file.Does it take same time in ur machine?
    2)I 'm running the client witrh the same Property object given to Ibnitial
           javax.naming.InitialContext ctx = null;
          java.util.Properties env = new java.util.Properties();
        env.put(Context.PROVIDER_URL, "iiop://localhost:900");
    System.out.println("upto here");
    ctx = new javax.naming.InitialContext(env)

    In above code i get the same Naming Service =null exception as got by vivek.
    So kapil what u mean by running client from the appserver .Could u plz give me some details abt this.'coz i have run my same java client in websphere ,jboss and power tier but it doesnt thows any exception of initial context .They dont seem to be running inside the appserver.
    Plz help out with some setrvlet client code with method to run?
    Cant't i run the above client.?
    If u have tried the above given client did it give the same exception?

  9. Anil,
      I have win 2000 with 256 RAM(Pentium Proc).And for me the generation of .ear file takes may be few sec.
      If you notice the sample code ie "Hello EJB".It is just using "new InitialContext()" without any class or port settings.So you can also test your EJB by running it in some sample Servlet.I think that is what Kapil is saying(Running the Client within app server).
      I haven't seen yet any success so far, for this Client(Out side Appserver) code in 4.0


  10. Hi,
    There are 3 things which u need to keep in mind.
    1. If u are running stand alone client on Windows then you have to use Websphere's JVM.
    2. Add the webshpere.jar in classpath
    3. Place ns.jar file ujc.jar in classpath.

    I hope it will help.
  11. Hi Kapil,
      I think you can help me out in this crazy problem which am facing here.
      I have the update sql query in ejbStore() as follows.At the stm where am trying to get the PreparedStm from con obj, Websphere is throwing a "Non-application exception".Pls let me know if you have any idea ? (basically con.createStm() and ctx.getUserTransaction() are also throwing the same exception)

    Thanks for your immediate help,

    public void ejbStore()
                if(null != con)
                  PreparedStatement ps = con.prepareStatement(DealQueries.updateCIHeader);
                  ps.setString(1, "499 General Mills Incorpo");
                  ps.setString(2, "P");
                  ps.setNull(3, Types.INTEGER); //memo
                  ps.setInt(4, 100);
                  ps.setInt(5, 200);
                  ps.setInt(6, 4600); //parent deal
                  ps.setInt(7, 4500);
            catch( Exception e){
            throw new EJBException();

  12. If your code is executing within an application server, the easy way is to just say:

       new InitialContext();

    with no properties at all!