0 Replies Latest reply on Apr 23, 2008 8:12 AM by baumar

    Why can't existing Remote Interface of a deployed session be

    baumar

      Hi,

      I'm trying a basic example with an entity bean Person
      and a stateless bean PersonFeederBean that is getting a list of persons and to persist them, print them and maybe remove them.

      The PersonFeederBean is called by ClientPersonFeeder creating the list of person to store.

      The code compiles in eclipse 3.2 with java compliance level 5, the jar can is deployed (on JBoss 404), the PersonFeederBean can be looked up and narrowed; to make sure it is not empty I added a test retrieving the methods; they are there.

      But when I want to call one of these methods I get the error:

      "$Proxy0.testInstanceAlive(Unknown Source)" as listed at the end of the code section.

      Can anybody tell me, what went wrong?
      I also wonder, what I might do to get rid of the java.lang.reflect.UndeclaredThrowableException, is there a strategy or documentation about it?


      Thanks for help

      Markus


      code:

      import java.io.Serializable;
      @Entity
      @NamedQueries({
      @NamedQuery(name="Person.findall_sortlastname", query="SELECT p FROM Person p")
      })

      @Table(name="PERSON")
      public class Person implements Serializable{

      private static final long serialVersionUID = 1L;

      public Person() {};

      public Person(String firstName, String lastName) {
      setTechnicalId(technicalId);
      setFirstName(firstName);
      setLastName(lastName);
      };


      @Id
      @Column(name="TECHNICALID")
      @GeneratedValue(strategy=GenerationType.AUTO)
      private int technicalId;
      public int getTechnicalId() {
      return technicalId;
      }
      public void setTechnicalId(int technicalId) {
      this.technicalId = technicalId;
      }
      @Column(name="FIRSTNAME")
      private String firstName;
      public String getFirstName() {
      return firstName;
      }
      public void setFirstName(String firstName) {
      this.firstName = firstName;
      }

      @Column(name="LASTNAME")
      private String lastName;
      public String getLastName() {
      return lastName;
      }
      public void setLastName(String lastName) {
      this.lastName = lastName;
      }


      public String toString() {
      return "firstname: "+getFirstName()+"; lastname: "+getLastName()+"; id: "+getTechnicalId();
      }
      }



      @Remote
      public interface PersonFeederRemote {

      public void feedPersonList(Vector personList);
      public void deletePersonList(Vector personList);
      public void listAllPerson();
      public void testInstanceAlive();

      }



      @Stateless

      public class PersonFeederBean implements PersonFeederRemote {
      @PersistenceUnit(unitName="ForumorganizerTest")

      EntityManager manager;

      public void feedPersonList(Vector personList) {

      for (Person person: personList) {
      manager.persist(person);
      System.out.println("added "+person.toString());
      }
      }
      }


      public void deletePersonList(Vector personList) {
      for (Person person: personList) {
      manager.remove(person);
      System.out.println("added "+person.toString());
      }
      }



      public void listAllPerson() {
      List resultList = manager.createNamedQuery("Person.findAll_sortlastname").getResultList();
      for( Object o: resultList) {
      System.out.println(o.toString());
      }

      }

      public void testInstanceAlive() {
      System.out.println("PersonFeederBean is alive");

      }

      }





      14:14:28,109 INFO [JmxKernelAbstraction] installing MBean: jboss.j2ee:jar=person.jar,name=PersonFeederBean,service=EJB3 with dependencies:
      14:14:28,109 INFO [JmxKernelAbstraction] persistence.units:jar=person.jar,unitName=ForumorganizerTest
      14:14:28,140 INFO [EJBContainer] STARTED EJB: com.informationcontrol.forumorganizer.persistence.PersonFeederBean ejbName: PersonFeederBean
      14:14:28,250 INFO [EJB3Deployer] Deployed: file:/C:/Programme/JBoss/JBoss404/server/default/deploy/person.jar



      public class ClientPersonFeeder {

      /**
      * @param args
      */
      public static void main(String[] args) {

      Context ctx =null;
      Object ref = null;
      try {
      ctx = new InitialContext();
      ref = ctx.lookup("PersonFeederBean/remote");
      } catch (NamingException e) {
      System.out.println("could not find PersonFeederBean/remote");
      e.printStackTrace();
      }
      try {
      NamingEnumeration nameList = ctx.listBindings("");
      while (nameList.hasMore()) {
      Binding binding = (Binding) nameList.next();
      System.out.println(binding.getName()+"; "+binding.getObject());
      }
      } catch (NamingException e) {
      System.out.println("Could not find root directory");
      e.printStackTrace();
      }

      PersonFeederRemote pfr = (PersonFeederRemote) PortableRemoteObject.narrow(ref, PersonFeederRemote.class);
      if (pfr == null) {
      System.out.println("PersonFeederRemote is null");
      } else {
      Method[] methods = pfr.getClass().getMethods();
      for (Method method: methods) { System.out.println(method.getName());}
      }
      Vector personList = new Vector();
      Person person = new Person("First", "Last");
      personList.add(person);
      person = new Person("Peter", "Muster");
      personList.add(person);

      // !!!!!!!!!!! the first call to a method of the bean causes the error: !!!!!!

      pfr.testInstanceAlive();
      pfr.feedPersonList(personList);
      pfr.listAllPerson();
      pfr.deletePersonList(personList);
      pfr.listAllPerson();
      }



      Exception in thread "main" java.lang.reflect.UndeclaredThrowableException
      at $Proxy0.testInstanceAlive(Unknown Source)
      at com.informationcontrol.forumorganizer.clientfortest.ClientPersonFeeder.main(ClientPersonFeeder.java:67)
      Caused by: java.lang.ClassNotFoundException: [Ljava.lang.StackTraceElement;
      at java.net.URLClassLoader$1.run(Unknown Source)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.net.URLClassLoader.findClass(Unknown Source)
      at java.lang.ClassLoader.loadClass(Unknown Source)
      at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
      at java.lang.ClassLoader.loadClass(Unknown Source)
      at org.jboss.remoting.loading.RemotingClassLoader.loadClass(RemotingClassLoader.java:50)
      ...
      ERROR: JDWP Unable to get JNI 1.2 environment, jvm->GetEnv() return code = -2
      JDWP exit error AGENT_ERROR_NO_JNI_ENV(183): [../../../src/share/back/util.c:820]