Search code examples
ejbwebspherewebsphere-8iiop

How to find InitialContext details in WebSphere?


I am working on setting up a servlet client which accesses Deployed EJBs. EJBs are deployed in 2 node setup on WebSphere 8.5 . On each server, I will be deploying Servlet which access EJBs. People will be connecting to Servlet which internal will connect to EJB and return the response.

To access the EJB I need to initialize the context. I believe code looks something around below lines.

 private void doSomething()  {      
      Hashtable env = new Hashtable(); 
      env.put(Context.INITIAL_CONTEXT_FACTORY,"com.ibm.websphere.naming.WsnInitialContextFactory"); 
      env.put(Context.PROVIDER_URL,"iiop//host:port"); 
      Object obj;      
      try{ 
            InitialContext ctx = new InitialContext(env); 
            obj =  ctx.lookup("EjbSample");       
      } catch(Exception ne){ ... } 
  }

My questions here are:

  • where can I find iiop//host:port host and port to connect EJB. Somewhere in WebSphere Admin Console? Any Config file?

  • As I have 3 node setup. I have 2 Clusters with name ClusterServlet and ClusterEJB in each node. Will the IIOP host and port vary node to node or these are consistent across both nodes?

[Edit 1]: When I try to access EJB from same host on which WAS is running, I am getting following error

javax.naming.NameNotFoundException: Name "EjbSample" not found in context "serverlocal:CELLROOT/SERVERROOT


Solution

  • The following KnowledgeCenter page discusses getting an InitialContext via a ProviderURL: https://www.ibm.com/support/knowledgecenter/en/SSAW57_8.5.5/com.ibm.websphere.nd.multiplatform.doc/ae/rnam_example_prop2.html

    It states "A provider URL contains bootstrap server information that the initial context factory can use to obtain an initial context."

    One can find the bootstrap port information for a particular server via the admin console or the serverindex.xml file. These port values can vary from node to node depending on settings used during the install or adding of Nodes and/or Servers into the Cell.

    Admin Console:

    serverindex.xml:

    • found on each server node at WAS_HOME/profiles/serverProfile/config/cells/cellName/nodes/nodeName

    • Contains a list of each server on the node and their server ports.

    • endPointName="BOOTSTRAP_ADDRESS" contains the desired port