diff --git a/activemq-core/src/main/java/org/apache/activemq/ActiveMQSession.java b/activemq-core/src/main/java/org/apache/activemq/ActiveMQSession.java index da93c1a44f..186c2f82d4 100755 --- a/activemq-core/src/main/java/org/apache/activemq/ActiveMQSession.java +++ b/activemq-core/src/main/java/org/apache/activemq/ActiveMQSession.java @@ -1603,6 +1603,21 @@ public class ActiveMQSession implements Session, QueueSession, TopicSession, Sta TransactionId txid = transactionContext.getTransactionId(); long sequenceNumber = producer.getMessageSequence(); + //Set the "JMS" header fields on the orriginal message, see 1.1 spec section 3.4.11 + message.setJMSDestination(destination); + message.setJMSDeliveryMode(deliveryMode); + long expiration = 0L; + if (!producer.getDisableMessageTimestamp()) { + long timeStamp = System.currentTimeMillis(); + message.setJMSTimestamp(timeStamp); + if (timeToLive > 0) { + expiration = timeToLive + timeStamp; + } + } + message.setJMSExpiration(expiration); + message.setJMSPriority(priority); + message.setJMSRedelivered(false); + // transform to our own message format here ActiveMQMessage msg = ActiveMQMessageTransformation.transformMessage(message, connection); @@ -1616,19 +1631,6 @@ public class ActiveMQSession implements Session, QueueSession, TopicSession, Sta //clear the brokerPath in case we are re-sending this message msg.setBrokerPath(null); - msg.setJMSDestination(destination); - msg.setJMSDeliveryMode(deliveryMode); - long expiration = 0L; - if (!producer.getDisableMessageTimestamp()) { - long timeStamp = System.currentTimeMillis(); - msg.setJMSTimestamp(timeStamp); - if (timeToLive > 0) { - expiration = timeToLive + timeStamp; - } - } - msg.setJMSExpiration(expiration); - msg.setJMSPriority(priority); - msg.setJMSRedelivered(false); msg.setTransactionId(txid); if (connection.isCopyMessageOnSend()) { diff --git a/activemq-core/src/test/java/org/apache/activemq/JMSMessageTest.java b/activemq-core/src/test/java/org/apache/activemq/JMSMessageTest.java index 45e64f9f47..2e596ceb94 100755 --- a/activemq-core/src/test/java/org/apache/activemq/JMSMessageTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/JMSMessageTest.java @@ -465,7 +465,23 @@ public class JMSMessageTest extends JmsTestSupport { ForeignMessage message = new ForeignMessage(); message.text = "Hello"; message.setStringProperty("test", "value"); - producer.send(message); + long timeToLive = 10000L; + long start = System.currentTimeMillis(); + producer.send(message, Session.AUTO_ACKNOWLEDGE, 7, timeToLive); + long end = System.currentTimeMillis(); + + + //validate jms spec 1.1 section 3.4.11 table 3.1 + // JMSDestination, JMSDeliveryMode, JMSExpiration, JMSPriority, JMSMessageID, and JMSTimestamp + //must be set by sending a message. + assertEquals(destination, message.getJMSDestination()); + assertEquals(Session.AUTO_ACKNOWLEDGE, message.getJMSDeliveryMode()); + assertTrue(start + timeToLive <= message.getJMSExpiration()); + assertTrue(end + timeToLive >= message.getJMSExpiration()); + assertEquals(7, message.getJMSPriority()); + assertNotNull(message.getJMSMessageID()); + assertTrue(start <= message.getJMSTimestamp()); + assertTrue(end >= message.getJMSTimestamp()); } // Validate message is OK.