2 Replies Latest reply on Jul 23, 2003 1:45 PM by andrewboyd

    Works in 3.0.2. 3.2.1 MessageFormatException: Object cannot

    andrewboyd

      I'm getting the following exception in 3.2.1:
      javax.jms.MessageFormatException: Object cannot be serialized
      at org.jboss.mq.SpyObjectMessage.setObject(SpyObjectMessage.java:67)
      at org.jboss.mq.SpySession.createObjectMessage(SpySession.java:245)
      at com.unetworks.psa.dataminer.DMAsyncPublisher.publishMessage(DMAsyncPublisher.java:47)

      Source for DMAsyncPublisher:
      public void publishMessage(DMAsyncCommandMessage msg){
      try{
      svLocator_ = ServiceLocator.getInstance();
      } catch(ServiceLocatorException e){
      e.printStackTrace();
      }
      try{
      // Lookup the managed connection factory for a topic
      QueueConnectionFactory queueFactory = svLocator_.getDataminerQueueConnectionFactory();

      // Create a connection to the JMS provider
      QueueConnection queueConnection = queueFactory.createQueueConnection("admin", "unetworks");
      queueConnection.start();

      // Create a topic session
      QueueSession session = queueConnection.createQueueSession(true, Session.AUTO_ACKNOWLEDGE);

      // Lookup the destination you want to send to
      Queue queue = svLocator_.getDataminerQueue();

      // Create a sender
      QueueSender queueSender = session.createSender(queue);

      // Create a message
      ObjectMessage message = session.createObjectMessage(msg);

      // Send the message
      queueSender.send(queue, message); <<< line 47

      Source for DMAsyncCommandMessage:
      */
      public interface DMAsyncCommandMessage extends Serializable{
      void execute(DMAsyncHandlerMDB dmAsyncHandlerMDB);
      ...
      Source for implementing class:
      public class DMUrlConceptCommandMessage implements DMAsyncCommandMessage, Serializable{
      private DMUrlConceptMap payload_;
      private SearchResultLineItemList lineItems_;

      The messages are clearly marked as Serializable and it worked fine in 3.0.2. does anyone have any ideas?

      Thanks

      Andrew

        • 1. Re: Works in 3.0.2. 3.2.1 MessageFormatException: Object can

          Marking something as Serializable only
          declares an intention.

          e.g.

          public class MyClass implements Serializable
          {
          public ArrayList list;
          }

          This looks ok, until you do:
          list.add(new Object());

          The MyClass is no longer serializable because Object
          is not Serializable.

          There are other reasons why the object might be
          serialized. Try running your object instance through
          this code to see whether you get a more informative
          IOException:

          ByteArrayOutputStream byteArray = new ByteArrayOutputStream();
          ObjectOutputStream objectOut = new ObjectOutputStream( byteArray );
          objectOut.writeObject( object );
          objectOut.close();

          Regards,
          Adrian

          • 2. Re: Works in 3.0.2. 3.2.1 MessageFormatException: Object can
            andrewboyd

            Thanks Adrian,
            Turns out we put in Log4J and it wasn't Serializable
            java.io.NotSerializableException: org.apache.log4j.Logger

            Your code pointed it out right away.

            Thanks again,

            Andrew