0 Replies Latest reply on Dec 6, 2001 10:54 AM by Ben Turner

    First time failiure with PortableRemoteObject.narrow(), but

    Ben Turner Newbie

      I am haivng an interesting problem.
      I have deployed an EJB called "EJBTest" with no jboss.xml file (so it is bound under "EJBTest" in my JNDI server).
      I am then trying to call it from an external Web Container (JRun v3.1).

      The first time I try to call it, I get an error when I try to PortableRemoteObject.narrow() it to the correct class - but if I simply try again, it works from them on ?

      From this, has anyone seen anything similar / know what the problem might be ?

      Incase it's of any use, I enclose the code below.

      Cheers,
      Ben

      TestBean.class :
      ----------------

      import java.rmi.RemoteException;
      import javax.ejb.*;

      public class TestBean implements SessionBean
      {
      private SessionContext ctx;

      public void ejbCreate()
      {}
      public Integer getDouble(Integer value)
      {
      System.out.println("Got request to double " + value.intValue());
      return new Integer(value.intValue() * 2);
      }
      public void ejbActivate()
      {}
      public void ejbPassivate()
      {}
      public void ejbRemove()
      {}
      public void setSessionContext(SessionContext ctx)
      {
      this.ctx = ctx;
      }
      }

      Test.class
      ----------

      import java.rmi.RemoteException;
      import javax.ejb.*;

      public interface Test extends EJBObject
      {
      public Integer getDouble(Integer value) throws RemoteException;
      }

      TestHome.class
      --------------

      import javax.ejb.*;
      import java.rmi.RemoteException;

      public interface TestHome extends EJBHome
      {
      public Test create()
      throws CreateException, RemoteException;
      }

      The relavant bit of code from the servlet :
      -------------------------------------------

      try {
      out.print("Getting Initial Context...");
      initial = new InitialContext(ejbEnv);
      out.println(" Done.");
      out.print("Getting Home Interface of Test Bean...");
      Object objRef = initial.lookup("EJBTest");
      testHome = (TestHome) PortableRemoteObject.narrow(objRef, TestHome.class);
      out.println(" Done.");
      out.print("Getting Remote Interface of Test Bean...");
      test = testHome.create();
      out.println(" Done.");
      Integer twentyOne = new Integer(21);
      out.print("Calling the EJB 'getDouble' method on " + twentyOne + "...");
      Integer fourtyTwo = test.getDouble(twentyOne);
      out.println(" Got " + fourtyTwo + ".");
      } catch (Exception ex) {
      out.println("Failed !!!" + ex.getMessage() + "Stack Trace :");
      ex.printStackTrace(out);
      }

      ejb-jar.xml
      -----------

      <?xml version="1.0" encoding="UTF-8"?>

      <ejb-jar>
      EJB Test Bean
      <display-name>Test EJB</display-name>
      <enterprise-beans>

      <ejb-name>EJBTest</ejb-name> TestHome
      Test
      <ejb-class>TestBean</ejb-class>
      <session-type>Stateless</session-type>
      <transaction-type>Bean</transaction-type>

      </enterprise-beans>
      </ejb-jar>