Uploaded image for project: 'AMQ Broker'
  1. AMQ Broker
  2. ENTMQBR-4944

[Openwire-protocol] ClassCastException consuming messages

    XMLWordPrintable

    Details

    • Target Release:
    • Steps to Reproduce:
      Hide

      The following code using Openwire protocol, will try to produce and consume a message setting one of the problematic properties.

      import javax.jms.Connection;
      import javax.jms.MessageConsumer;
      import javax.jms.MessageProducer;
      import javax.jms.Queue;
      import javax.jms.Session;
      import javax.jms.TextMessage;import org.apache.activemq.ActiveMQSslConnectionFactory;
      /**
       * A simple JMS Queue example that creates a producer and consumer on a queue and sends then receives a message.
       */
      public class QueueExample {   public static void main(final String[] args) throws Exception {
            Connection connection = null;
            try {
             ActiveMQSslConnectionFactory cf = new ActiveMQSslConnectionFactory("ssl://mycluster.mydomain.com:443");
             cf.setTrustStore("/foo/bar/broker.ks");
             cf.setTrustStorePassword("password");
             connection = cf.createConnection("user", "password");
               Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
               Queue queue = session.createQueue("exampleQueue");         ///// PRODUCE MESSAGE
               
               MessageProducer producer = session.createProducer(queue);         
              TextMessage message = session.createTextMessage("This is a text message");
               message.setStringProperty("__HDR_BROKER_PATH", "test-broker-path");
      //         message.setStringProperty("__HDR_CLUSTER", "test-cluster");
      //         message.setStringProperty("__HDR_USER_ID", "test-user-id");
      
              System.out.println("Sent message: " + message.getText());
              producer.send(message);         
      
      ///// TRY TO CONSUME MESSAGE 
               MessageConsumer messageConsumer = session.createConsumer(queue);
               connection.start();
               TextMessage messageReceived = (TextMessage) messageConsumer.receive(5000);
      
               if(messageReceived != null)
                   System.out.println("Received message: " + messageReceived.getText());
               else
                   System.out.println("No message was received");
            } finally {
               if (connection != null) {
                  connection.close();
               }
            }
         }
      }
      

       

      Executing the above code, the produced message won't be received, and will remain in the queue. At the same time, the exception will arise in the server log:

      WARN [org.apache.activemq.artemis.core.server] Error during message dispatch: java.lang.ClassCastException: org.apache.activemq.artemis.api.core.SimpleString cannot be cast to java.lang.String

       

       

       

      Show
      The following code using Openwire protocol, will try to produce and consume a message setting one of the problematic properties. import javax.jms.Connection; import javax.jms.MessageConsumer; import javax.jms.MessageProducer; import javax.jms.Queue; import javax.jms.Session; import javax.jms.TextMessage; import org.apache.activemq.ActiveMQSslConnectionFactory; /** * A simple JMS Queue example that creates a producer and consumer on a queue and sends then receives a message. */ public class QueueExample { public static void main( final String [] args) throws Exception { Connection connection = null ; try { ActiveMQSslConnectionFactory cf = new ActiveMQSslConnectionFactory( "ssl: //mycluster.mydomain.com:443" ); cf.setTrustStore( "/foo/bar/broker.ks" ); cf.setTrustStorePassword( "password" ); connection = cf.createConnection( "user" , "password" ); Session session = connection.createSession( false , Session.AUTO_ACKNOWLEDGE); Queue queue = session.createQueue( "exampleQueue" ); ///// PRODUCE MESSAGE MessageProducer producer = session.createProducer(queue); TextMessage message = session.createTextMessage( "This is a text message" ); message.setStringProperty( "__HDR_BROKER_PATH" , "test-broker-path" ); // message.setStringProperty( "__HDR_CLUSTER" , "test-cluster" ); // message.setStringProperty( "__HDR_USER_ID" , "test-user-id" ); System .out.println( "Sent message: " + message.getText()); producer.send(message); ///// TRY TO CONSUME MESSAGE MessageConsumer messageConsumer = session.createConsumer(queue); connection.start(); TextMessage messageReceived = (TextMessage) messageConsumer.receive(5000); if (messageReceived != null ) System .out.println( "Received message: " + messageReceived.getText()); else System .out.println( "No message was received" ); } finally { if (connection != null ) { connection.close(); } } } }   Executing the above code, the produced message won't be received, and will remain in the queue. At the same time, the exception will arise in the server log: WARN [org.apache.activemq.artemis.core.server] Error during message dispatch: java.lang.ClassCastException: org.apache.activemq.artemis.api.core.SimpleString cannot be cast to java.lang. String      

      Description

      Using Openwire protocol, when some messages have been produced setting some specific properties, later on trying to consume those messages also using Openwire, the following exception is shown in the server log:

       

      WARN [org.apache.activemq.artemis.core.server] Error during message dispatch: java.lang.ClassCastException: org.apache.activemq.artemis.api.core.SimpleString cannot be cast to java.lang.String

       

      The exception log level is WARNING, but the effect is that all messages having that problem are stuck in the server, and cannot be consumed using Openwire. Using the Core protocol you can consume them without any problem.

       

      If the messages are published with one of the following properties set, the error will arise:

      • __HDR_BROKER_PATH
      • __HDR_CLUSTER
      • __HDR_USER_ID

      Example code:

      message.setStringProperty("__HDR_BROKER_PATH", "test-broker-path");

      The properties have been extracted after analyzing the class org.apache.activemq.artemis.core.protocol.openwire.OpenWireMessageConverter.

      The whole exception stacktrace is attached.exception-stacktrace.log

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              jbertram Justin Bertram
              Reporter:
              ryanezil Rafael Yáñez Illescas
              Tester:
              Roman Vais Roman Vais
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: