5 Replies Latest reply on May 16, 2013 8:50 AM by Stephen Coy

    Strange exception when calling a remote bean method passing a queue as parameter

    Alessandro Gelormini Newbie

      Hi..my company has an infrastructure based on jboss 4.2 on java 5 and many java clients on java 6, made some years ago. I have to introduce new functionality on server side but, since some required libraries need java 6 or later, I set up a jboss 7.1.1 to develop it; now I learnt a bit about new jboss structures and beans and made my back end: two ejb modules, one with a remote interface visible to clients and the other with some singletons which dialogate to a c++ application. The first module receive messages on a queue from the second and should routes these messages to the clients (after some processing).

      Since I have to send messages to specific clients, according to messagge contents, when connecting to jboss one client create a temporary queue and passes to it through bean remote interface; jboss will save the association between client and queue, in order to retrieve it later and send the messages to the correct client. The same idea is being used for years in old jboss so i replicate it, thinking that all will be fine but testing with a fake client I encountered one problem. I connect to jboss,create the queue and set receiver..after that i lookup the remote interface and call a method passing the queue as parameter..Well I receive this

       

      java.lang.reflect.UndeclaredThrowableException

                at $Proxy0.startTelegestione(Unknown Source)

                at org.jboss.as.quickstarts.ejb.remote.client.Test.test(Test.java:77)

                at org.jboss.as.quickstarts.ejb.remote.client.Test.esegui(Test.java:51)

                at org.jboss.as.quickstarts.ejb.remote.client.RemoteEJBClient.main(RemoteEJBClient.java:64)

       

       

      Caused by: java.lang.ClassNotFoundException: java.lang.ReflectiveOperationException

                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 java.lang.Class.forName0(Native Method)

                at java.lang.Class.forName(Unknown Source)

                at org.jboss.marshalling.AbstractClassResolver.loadClass(AbstractClassResolver.java:135)

                at org.jboss.marshalling.AbstractClassResolver.resolveClass(AbstractClassResolver.java:116)

                at org.jboss.marshalling.river.RiverUnmarshaller.doReadClassDescriptor(RiverUnmarshaller.java:892)

                at org.jboss.marshalling.river.RiverUnmarshaller.doReadClassDescriptor(RiverUnmarshaller.java:905)

                at org.jboss.marshalling.river.RiverUnmarshaller.doReadNewObject(RiverUnmarshaller.java:1204)

                at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:272)

                at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:209)

                at org.jboss.marshalling.AbstractObjectInput.readObject(AbstractObjectInput.java:37)

                at org.jboss.ejb.client.remoting.InvocationExceptionResponseHandler$MethodInvocationExceptionResultProducer.getResult(InvocationExceptionResponseHandler.java:82)STOPPO CODA

       

       

                at org.jboss.ejb.client.EJBClientInvocationContext.getResult(EJBClientInvocationContext.java:270)

                at org.jboss.ejb.client.TransactionInterceptor.handleInvocationResult(TransactionInterceptor.java:47)

                at org.jboss.ejb.client.EJBClientInvocationContext.getResult(EJBClientInvocationContext.java:272)

                at org.jboss.ejb.client.ReceiverInterceptor.handleInvocationResult(ReceiverInterceptor.java:132)

                at org.jboss.ejb.client.EJBClientInvocationContext.getResult(EJBClientInvocationContext.java:260)

                at org.jboss.ejb.client.EJBClientInvocationContext.awaitResponse(EJBClientInvocationContext.java:399)

                at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:140)

                at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:121)

                at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:104)

                ... 4 more

       

      Note that if i do same operations passing a null instead of the Queue, all works fine, on jboss log i see the method call and the backend operations. WHAT IS THE SENSE OF THIS BEHAVIOUR??

       

      Remote interface

      package remoteInterfaces;
      
      
      import javax.ejb.Remote;
      import javax.jms.Queue;
      
      
      @Remote
      public interface RemoteTelegestioneInterface {
        
        
                public boolean startTelegestione(String username,String ip,Queue coda,String ce_id);
        
                public boolean stopTelegestione(String ce_id);
      
      
      }
      
      

       

      Interface implementation

       

      import gestioneSocketInterfaces.GestoreRichiesteRisposteInterface;
      
      
      import javax.ejb.EJB;
      import javax.ejb.Remote;
      import javax.ejb.Stateless;
      import javax.jms.Queue;
      
      
      import remoteInterfaces.RemoteTelegestioneInterface;
      import utility.OperatoreInTelegestione;
      import utility.Utility;
      
      
      @Stateless
      @Remote({ RemoteTelegestioneInterface.class })
      public class RemoteTelegestioneBean implements RemoteTelegestioneInterface {
      
      
                @EJB(lookup = "java:global/Telegestione_Socket/GestoreRichiesteRisposte!gestioneSocketInterfaces.GestoreRichiesteRisposteInterface")
                GestoreRichiesteRisposteInterface request = null;
      
      
                @Override
                public boolean startTelegestione(String username, String ip, Queue coda,
                                    String ce_id) {
                          if (this.request.richiediTelegestione(ce_id)) {
                                    Utility.getIstance().addOperatore(
                                                        new OperatoreInTelegestione(username, ip, ce_id, coda),
                                                        ce_id);
                                    return true;
                          } else
                                    return false;
                }
      
      
                @Override
                public boolean stopTelegestione(String ce_id) {
                          this.request.fermaTelegestione(ce_id);
                          Utility.getIstance().removeOperatore(ce_id);
                          return false;
                }
      
      
      }
      
      

       

      Test Client, i create the Test object and call esegui() from a main class

       

      import java.util.Hashtable;
      
      
      import javax.jms.Queue;
      import javax.jms.QueueConnection;
      import javax.jms.QueueReceiver;
      import javax.jms.QueueSession;
      import javax.naming.Context;
      import javax.naming.InitialContext;
      import javax.naming.NamingException;
      
      
      import remoteInterfaces.RemoteTelegestioneInterface;
      
      
      public class Test {
      
      
                public Queue tmpQueue;
      
      
                private QueueConnection conn;
      
      
                private QueueSession session;
      
      
                private QueueReceiver receiver;
      
      
                Context context = null;
      
      
                StatiReceive sr = null;
      
      
                public void esegui() {
                          final Hashtable jndiProperties = new Hashtable();
                          jndiProperties.put(Context.URL_PKG_PREFIXES,
                                              "org.jboss.ejb.client.naming");
                          jndiProperties.put("java.naming.factory.initial",
                                              "org.jboss.naming.remote.client.InitialContextFactory");
                          jndiProperties.put(InitialContext.PROVIDER_URL,
                                              "remote://192.168.5.47:4447");
                          jndiProperties.put("jboss.naming.client.ejb.context", true);
      
      
                          // needed for remote access - remember to run add-user.bat
                          jndiProperties.put(Context.SECURITY_PRINCIPAL, "guest");
                          jndiProperties.put(Context.SECURITY_CREDENTIALS, "pass");
                          try {
                                    context = new InitialContext(jndiProperties);
                          } catch (NamingException e) {
                                    // TODO Auto-generated catch block
                                    e.printStackTrace();
                          }
      
      
                          sr = new StatiReceive();
                          sr.start(context);
                          this.test();
                          try {
                                    Thread.sleep(5000);
                          } catch (InterruptedException e) {
                                    // TODO Auto-generated catch block
                                    e.printStackTrace();
                          }
                          sr.stop();
                }
      
      
                private void test() {
      
      
                          RemoteTelegestioneInterface gestore = null;
                          try {
                                    gestore = (RemoteTelegestioneInterface) context
                                                        .lookup("ejb:/Telegestione_Service/RemoteTelegestioneBean!remoteInterfaces.RemoteTelegestioneInterface");
                          } catch (NamingException e) {
                                    System.out.println("ECCEZIONE 1");
                                    e.printStackTrace();
                          } catch (Exception e) {
                                    System.out.println("ECCEZIONE 2");
                                    e.printStackTrace();
      
      
                          }
                          System.out.println(this.sr.tmpQueue);
                          try {
                                    gestore.startTelegestione("ALE", "192.168.5.78",this.sr.tmpQueue, "123499");
                                    //gestore.stopTelegestione("123499");
                          } catch (Exception e) {
                                    System.out.println("ECCEZIONE 3");
                                    e.printStackTrace();
                                    sr.stop();
                          }
                }
      
      
      }
      
      

       

      Messaging class

       

      import javax.jms.JMSException;
      import javax.jms.Message;
      import javax.jms.MessageListener;
      import javax.jms.ObjectMessage;
      import javax.jms.Queue;
      import javax.jms.QueueConnection;
      import javax.jms.QueueConnectionFactory;
      import javax.jms.QueueReceiver;
      import javax.jms.QueueSession;
      import javax.naming.Context;
      import javax.naming.NamingException;
      
      
      import pacchettoStato.PkgStato;
      
      
      public class StatiReceive implements MessageListener {
      
      
                public Queue tmpQueue;
      
      
                private QueueConnection conn;
      
      
                private QueueSession session;
      
      
                private QueueReceiver receiver;
      
      
                private void topicSubscribe(Context Ctx) {
                          try {
                                    Context iniCtx = Ctx;
      
      
                                    Object tmp = iniCtx.lookup("jms/RemoteConnectionFactory");
                                    QueueConnectionFactory tcf = (QueueConnectionFactory) tmp;
                                    conn = tcf.createQueueConnection();
                                    session = conn.createQueueSession(false,
                                                        QueueSession.AUTO_ACKNOWLEDGE);
                                    tmpQueue = session.createTemporaryQueue();
                                    receiver = session.createReceiver(tmpQueue);
                                    receiver.setMessageListener(this);
                                    conn.start();
                          } catch (NamingException ne) {
                                    throw new RuntimeException(ne);
                          } catch (JMSException jmse) {
                                    throw new RuntimeException(jmse);
                          }
      
      
                }
      
      
                public void start(Context iniCtx) {
                          this.topicSubscribe(iniCtx);
                }
      
      
                public void stop() {
                          try {
        
                                    System.out.println("STOPPO CODA");
                                    //receiver.close();
                                    //session.close();
                                    conn.close();
                          } catch (Exception e) {
                                    e.printStackTrace();
                          }
                }
      
      
                public void onMessage(Message arg0) {
      
      
                          // TODO Ricezione nuovi stati e aggiornamento pannello
                          ObjectMessage obj = (ObjectMessage) arg0;
                          PkgStato stato;
      
      
                          try {
                                    stato = (PkgStato) obj.getObject();
                                    System.out.println("ARRIVATA MODIFICA STATO " + stato.getTipo()
                                                        + " " + stato.getNumero() + " " + stato.getStati());
                          } catch (JMSException e) {
                                    // TODO Auto-generated catch block
                                    e.printStackTrace();
                          }
      
      
                }
      
      
      }
      
      

       

       

      I hope I explained well the problem..I'm not english so i apologize for grammar errors