Discussions

EJB programming & troubleshooting: EJB Client failed lookingup?

  1. EJB Client failed lookingup? (6 messages)

    I wrote a simple session bean. And packed class files with ejb-jar.xml and jboss.xml into a single HelloWorld.jar. I succeeded in deploying this EJB-JAR.
    However, when I test it in a standalone client, "NoInitialContextException" occurs.

    Here is my code.

    // ejb-jar.xml

    <!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
    <ejb-jar>
    <enterprise-beans>
    <session>
    <ejb-name>Hello</ejb-name>
    <home>examples.HelloHome</home>
    <remote>examples.Hello</remote>
    <local-home>examples.HelloLocalHome</local-home>
    <local>examples.HelloLocal</local>
    <ejb-class>examples.HelloBean</ejb-class>
    <session-type>Stateless</session-type>
    <transaction-type>Bean</transaction-type>
    </session>
    </enterprise-beans>
    </ejb-jar>

    // jboss.xml
    <?xml version="1.0" encoding="UTF-8"?>
    <jboss>
    <enterprise-beans>
    <session>
    <ejb-name>Hello</ejb-name>
    <jndi-name>HelloWorld/Hello</jndi-name>
    </session>
    </enterprise-beans>
    </jboss>

    // code in client
    InitialContext ctx = new InitialContext();
    Object obj = ctx.lookup("HelloWorld/Hello");

    When the app reaches here, the exception is:

    javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial

    Threaded Messages (6)

  2. java.util.Properties props = new java.util.Properties ();

    props.put (javax.naming.Context.INITIAL_CONTEXT_FACTORY,"com.ibm.websphere.naming.WsnInitialContextFactory");
    props.put (javax.naming.Context.PROVIDER_URL, "iiop:///");

    javax.naming.InitialContext ctx = new javax.naming.InitialContext (props);

    ctx should be used as initial context ....... example given for websphere.
  3. It's for WAS. But I use JBoss 3.2.1
  4. Context[ Go to top ]

    But Context u have to define whether it is weblogicwebsphere or JBoss, for JBoss there will be a different driver check it
  5. Driver[ Go to top ]

    noted. And the only problem is I have to find the driver and define the context. Right?
  6. Problem of looking up an EJB in Websphere.[ Go to top ]

    I use WSAD to develop a simple EJB. I wrote a standalone Java application to access this EJB. In the classpath, I put the namingclient.jar.

    Here is piece of my client code.
    -----------------------------------------------------------------
    Properties props = new Properties();
    props.put(Context.INITIAL_CONTEXT_FACTORY,
    "com.ibm.websphere.naming.WsnInitialContextFactory");
    props.put(Context.PROVIDER_URL, "iiop://localhost:9080/");
    InitialContext ctx = new InitialContext(props);
    -----------------------------------------------------------------

    Here is the error message:
    -----------------------------------------------------------------
    javax.naming.CommunicationException: A communication failure occurred while attempting to obtain an initial context using the provider url: "iiop://localhost:9080/". Make sure that the host and port information is correct and that the server identified by the provider url is a running name server. If no port number is specified, the default port number 2809 is used. Other possible causes include the network environment or workstation network configuration. Root exception is org.omg.CORBA.COMM_FAILURE: purge_calls:1186 minor code: 4942F306 completed:

    What's the solution?
  7. try using port 2809 instead of 9080.[ Go to top ]

    try using port 2809 instead of 9080.