10 Replies Latest reply on May 2, 2002 4:44 AM by vinjh

    Class Not Found Exception on getObject()

    jmschust

      I'm getting this exception out of the server using JBoss 3.0.

      I'm wondering if this may be because of a similar type problem as was found back in Jun 2001

      http://main.jboss.org/thread.jsp?forum=48&thread=1255&message=4580&q=ClassNotFoundException+getObject#4580

      If not, any ideas?

      Here's the code and the exception:

      public void onMessage( javax.jms.Message msg) {
      try {
      if( msg instanceof ObjectMessage) {
      ObjectMessage obj = (ObjectMessage) msg;


      com.cctus.ejb.be2.Message myMsg = (com.cctus.ejb.be2.Message) obj.getObject();

      System.out.println( "Message Recieved - id: " + myMsg.accountId);
      } else {
      System.out.println( "Wrong Message Type");
      }
      } catch( Throwable te) {
      te.printStackTrace();
      }
      }



      javax.jms.MessageFormatException: ClassNotFoundException
      at org.jboss.mq.SpyObjectMessage.getObject(SpyObjectMessage.java:92)
      at com.cctus.ejb.be2.MessageHandler.onMessage(MessageHandler.java:47)
      at java.lang.reflect.Method.invoke(Native Method)
      at org.jboss.ejb.MessageDrivenContainer$ContainerInterceptor.invoke(MessageDrivenContainer.java:407)
      at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:98)
      at org.jboss.ejb.plugins.AbstractTxInterceptorBMT.invokeNext(AbstractTxInterceptorBMT.java:143)
      at org.jboss.ejb.plugins.MessageDrivenTxInterceptorBMT.invoke(MessageDrivenTxInterceptorBMT.java:36)
      at org.jboss.ejb.plugins.MessageDrivenInstanceInterceptor.invoke(MessageDrivenInstanceInterceptor.java:79)
      at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:131)
      at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:166)
      at org.jboss.ejb.MessageDrivenContainer.invoke(MessageDrivenContainer.java:282)
      at org.jboss.ejb.plugins.jms.JMSContainerInvoker.invoke(JMSContainerInvoker.java:564)
      at org.jboss.ejb.plugins.jms.JMSContainerInvoker$MessageListenerImpl.onMessage(JMSContainerInvoker.java:909)
      at org.jboss.mq.SpyMessageConsumer.sessionConsumerProcessMessage(SpyMessageConsumer.java:433)
      at org.jboss.mq.SpyMessageConsumer.addMessage(SpyMessageConsumer.java:303)
      at org.jboss.mq.SpySession.run(SpySession.java:216)
      at org.jboss.jms.asf.StdServerSession.run(StdServerSession.java:209)
      at EDU.oswego.cs.dl.util.concurrent.PooledExecutor$Worker.run(PooledExecutor.java:642)
      at java.lang.Thread.run(Thread.java:484)

        • 1. Re: Class Not Found Exception on getObject()
          hchirino

          nope. not related.

          Make sure that current context classloader, Thread.currentThread().getContextClassLoader(), can load class that is stored in the ObjectMessage.

          Just do a Thread.currentThread().getContextClassLoader().loadClass("the.name.of.the.Class");
          in the thread that you setup the session in. If It can load it, send me a small sample program that shows the problem.

          Regards,
          Hiram

          • 2. Re: Class Not Found Exception on getObject()
            brunofr

            I am getting the same exception as you, but using JBoss 2.4.3. The classloader seems to be able to load the class, but I still get the exception within an MDB:

            [Default] javax.jms.MessageFormatException: ClassNotFoundException
            [Default] javax.jms.MessageFormatException: ClassNotFoundException
            [Default] at org.jboss.mq.SpyObjectMessage.getObject(SpyObjectMessage.java:92)
            [Default]
            [Default] at com.meridea.cs.wfengine.server.WfControllerServer.onMessage(WfControllerServer.java:87)
            [Default]
            [Default] at java.lang.reflect.Method.invoke(Native Method)
            [Default]
            [Default] at org.jboss.ejb.MessageDrivenContainer$ContainerInterceptor.invoke(MessageDrivenContainer.java:400)
            [Default]
            [Default] at org.jboss.ejb.plugins.MessageDrivenInstanceInterceptor.invoke(MessageDrivenInstanceInterceptor.java:58)
            [Default]
            [Default] at org.jboss.ejb.plugins.TxInterceptorCMT.invokeNext(TxInterceptorCMT.java:133)
            [Default]
            [Default] at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:247)
            [Default]
            [Default] at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:99)
            [Default]
            [Default] at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:128)
            [Default]
            [Default] at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:195)
            [Default]
            [Default] at org.jboss.ejb.MessageDrivenContainer.invoke(MessageDrivenContainer.java:281)
            [Default]
            [Default] at org.jboss.ejb.plugins.jms.JMSContainerInvoker.invoke(JMSContainerInvoker.java:165)
            [Default]
            [Default] at org.jboss.ejb.plugins.jms.JMSContainerInvoker$MessageListenerImpl.onMessage(JMSContainerInvoker.java:644)
            [Default]
            [Default] at org.jboss.mq.SpyMessageConsumer.sessionConsumerProcessMessage(SpyMessageConsumer.java:420)
            [Default]
            [Default] at org.jboss.mq.SpyMessageConsumer.addMessage(SpyMessageConsumer.java:295)
            [Default]
            [Default] at org.jboss.mq.SpySession.run(SpySession.java:216)
            [Default]
            [Default] at org.jboss.jms.asf.StdServerSession.run(StdServerSession.java:177)
            [Default]
            [Default] at EDU.oswego.cs.dl.util.concurrent.PooledExecutor$Worker.run(PooledExecutor.java:642)
            [Default]
            [Default] at java.lang.Thread.run(Thread.java:484)
            [Default]

            This is the relevant code in the Message Driven Bean:

            public void onMessage(Message message) {
            try {
            // process the request

            Thread.currentThread().getContextClassLoader().loadClass("com.meridea.cs.wfengine.ProcessRequestMessage");

            ObjectMessage msg = (ObjectMessage) message;
            ProcessRequestMessage request = (ProcessRequestMessage) msg.getObject();

            } catch(Exception e) {
            e.printStackTrace();
            }

            Am I missing something? Any ideas?

            • 3. Re: Class Not Found Exception on getObject()
              enigma69

              I am getting the same problem too, with jBoss 2.4.4. Has the problem been solved yet..... please let me know.

              • 4. Re: Class Not Found Exception on getObject()
                enigma69

                What kind of message do you use.... I have problem with a vector consisting of an array of objects, and a single object.

                • 5. Re: Class Not Found Exception on getObject()
                  jameslai

                  I am using JBoss-2.4.4-Tomcat-3.2.3 and have the same problem. It works fine when I run my app as a WAR file under another Tomcat-4.0.1 and run the JBoss just as an separate JMS server. But when I run my app in the Tomcat of JBoss, this problem occurs. The Thread.currentThread().getContextClassLoader().loadClass(...) returns correctly but ClassNotFoundException still occurs. I solve this problem by adding my object jar file under JBoss lib/ext. Is this normal? Any better solution?

                  • 6. Re: Class Not Found Exception on getObject()
                    vinjh

                    Hi, I'm welcoming myself to the club - I got the same CNF Exception... I'm trying to send a MessageData object, that is an object that contains a string (an identifier) and a complex data object (that implements iXMLData).
                    Although the sender recognizes the class as such (com...MessageData), and although the class loading seems to function in my client (the receiver), with the loadClass in the current thread, the error occurs when I try to get, in the onMessage() method, the message as MessageData:
                    MessageData request = (MessageData) m.getObject();
                    (--where m is the message as ObjectMessage:
                    ObjectMessage m = (ObjectMessage)msg; )
                    So, the getObject() calls the exception on my client, as follows in the jBoss:
                    javax.jms.MessageFormatException: ClassNotFoundException
                    Hmm, it seems I'm in a dead-end. Pleez, if anyone did solve it, gimme a reply.
                    thanks

                    • 7. Re: Class Not Found Exception on getObject()
                      amueller

                      This problem also exists if you use a foreign JMS provider such as SwiftMQ and others. The onMessage isn't driven by a JBoss thread but by a SwiftMQ thread. So you can't use the context CL here. SwiftMQ has a method getObject(classloader) to get over this, however, it's a proprietary method.

                      I'm not sure how to resolve that. May be to wrap up a received ObjectMessage with a JBoss ObjectMessage which overwrites getObject() and knows about the MDB classloader?

                      -- Andreas

                      • 8. Re: Class Not Found Exception on getObject()
                        amueller

                        > The onMessage
                        > isn't driven by a JBoss thread but by a SwiftMQ
                        > thread.

                        Ooops that's wrong. It's driven from a thread which drives the ServerSession.

                        • 9. Re: Class Not Found Exception on getObject()
                          enigma69

                          If I use Thread.currentThread().getContextClassLoader().loadClass in the code, the stuff works, but if I remove it again, it doesn't work anymore. I thought it was a problem with inconsistent versions, but I didn't find any proof of that (yet).

                          • 10. Re: Class Not Found Exception on getObject()
                            vinjh

                            All right, it worked by loading in the client, in the current thread ALL the classes I used in my message constructor. thanks.