5 Replies Latest reply on Sep 25, 2012 4:25 AM by jaikiran pai Branched from an earlier discussion.

    JNDI lookup of EJB2  on AS7

    Chandra Shekhar Newbie

      Kindly help me to resolve JNDI Invocation.

      EJB jar deployed sucessfully in server that I can see server logs but I am getting NameNotfound exception during invocation.

       

      ejb-jar.xml

      ------------------------------------------------         

       

      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE ejb-jar PUBLIC '-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN' 'http://java.sun.com/dtd/ejb-jar_2_0.dtd'>
      <!-- Generated XML! -->
      <ejb-jar>
      <enterprise-beans>
        <session>
         <ejb-name>EmpolyeeInfo</ejb-name>
         <home>com.migration.EmpolyeeInfoHome</home>
         <remote>com.migration.EmpolyeeInfoLocal</remote>
         <ejb-class>com.migration.EmpolyeeInfo</ejb-class>
         <session-type>Stateless</session-type>
         <transaction-type>Bean</transaction-type>
        <ejb-ref>
                      <ejb-ref-name>java:global/EmpolyeeInfoJNDI</ejb-ref-name>
                      <ejb-ref-type>Session</ejb-ref-type>
                      <home>com.migration.EmpolyeeInfoHome</home>
                      <remote>com.migration.EmpolyeeInfoLocal</remote>
                  </ejb-ref>
        </session>
      </enterprise-beans>
      </ejb-jar>

       

      Server logs:

      10:27:58,656 INFO  [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-1) JNDI bindings for session bean named EmpolyeeInfo in deployment unit deployment "MigrationEJB.jar" are as follows:

              java:global/MigrationEJB/EmpolyeeInfo!com.migration.EmpolyeeInfoHome
              java:app/MigrationEJB/EmpolyeeInfo!com.migration.EmpolyeeInfoHome
              java:module/EmpolyeeInfo!com.migration.EmpolyeeInfoHome
              java:jboss/exported/MigrationEJB/EmpolyeeInfo!com.migration.EmpolyeeInfoHome
              java:global/MigrationEJB/EmpolyeeInfo!com.migration.EmpolyeeInfoLocal
              java:app/MigrationEJB/EmpolyeeInfo!com.migration.EmpolyeeInfoLocal
              java:module/EmpolyeeInfo!com.migration.EmpolyeeInfoLocal
              java:jboss/exported/MigrationEJB/EmpolyeeInfo!com.migration.EmpolyeeInfoLocal
       
      Server logs
      --------------

      [org.jboss.as.server] (DeploymentScanner-threads - 2) JBAS018559: Deployed "MigrationEJB.jar"

       

       

      Console exception
      -------------------
      javax.naming.NameNotFoundException: EmpolyeeInfoJNDI
      at org.jboss.ha.jndi.HAJNDI.lookupRemotely(HAJNDI.java:265)
      at org.jboss.ha.jndi.HAJNDI.lookup(HAJNDI.java:206)

       

       

      public void test() {
        Properties env = new Properties();

        env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
        env.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
        env.put(Context.PROVIDER_URL, "jnp://127.0.0.1:1099");

        InitialContext ctx = null;

        try {
         ctx = new InitialContext(env);
        } catch (NamingException e) {
         e.printStackTrace();
        }

        Object obj = null;

        try {
      //   obj = ctx.lookup("com.migration.EmpolyeeInfoHome"); // Jboss 4.5.2 look up EJB2.0
        
      //   obj = ctx.lookup("ejb:/MigrationEJB//EmpolyeeInfoHome!com.migration.EmpolyeeInfoHome?Stateless"); //JBOSS7.0 EJB3.0
        
         obj = ctx.lookup("EmpolyeeInfoJNDI"); // Jboss 7.0 EJB2.0
      //   obj = ctx.lookup("java:global/EmpolyeeInfoJNDI"); // Jboss 7.0 EJB2.0
        
         EmpolyeeInfoHome home = (EmpolyeeInfoHome) javax.rmi.PortableRemoteObject.narrow(obj,
           EmpolyeeInfoHome.class);
         EmpolyeeInfoLocal infoLocal = home.create();
         System.out.println(infoLocal.getEmpFullName("Hello Buddy"));
        } catch (NamingException e) {
         e.printStackTrace();
        } catch (RemoteException e) {
         e.printStackTrace();
        } catch (CreateException e) {
         e.printStackTrace();
        }

      }