mirror of https://github.com/apache/activemq.git
fix to allow a foreign JMS message ID to be set on an ActiveMQMessage
git-svn-id: https://svn.apache.org/repos/asf/incubator/activemq/trunk@367741 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
ffad45edff
commit
da77d2c649
|
@ -114,8 +114,13 @@ public class ActiveMQMessage extends Message implements javax.jms.Message {
|
||||||
try {
|
try {
|
||||||
MessageId id = new MessageId(value);
|
MessageId id = new MessageId(value);
|
||||||
this.setMessageId(id);
|
this.setMessageId(id);
|
||||||
} catch (Throwable e) {
|
}
|
||||||
throw JMSExceptionSupport.create("Invalid message id '" + value + "', reason: " + e.getMessage(), e);
|
catch (NumberFormatException e) {
|
||||||
|
// we must be some foreign JMS provider or strange user-supplied String
|
||||||
|
// so lets set the IDs to be 1
|
||||||
|
MessageId id = new MessageId();
|
||||||
|
id.setTextView(value);
|
||||||
|
this.setMessageId(messageId);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.setMessageId(null);
|
this.setMessageId(null);
|
||||||
|
|
|
@ -42,7 +42,7 @@ public class MessageId implements DataStructure {
|
||||||
}
|
}
|
||||||
|
|
||||||
public MessageId(String messageKey) {
|
public MessageId(String messageKey) {
|
||||||
setMessageKey(messageKey);
|
setValue(messageKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
public MessageId(String producerId, long producerSequenceId) {
|
public MessageId(String producerId, long producerSequenceId) {
|
||||||
|
@ -54,17 +54,28 @@ public class MessageId implements DataStructure {
|
||||||
this.producerSequenceId = producerSequenceId;
|
this.producerSequenceId = producerSequenceId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMessageKey(String messageKey) {
|
/**
|
||||||
|
* Sets the value as a String
|
||||||
|
*/
|
||||||
|
public void setValue(String messageKey) {
|
||||||
key = messageKey;
|
key = messageKey;
|
||||||
// Parse off the sequenceId
|
// Parse off the sequenceId
|
||||||
int p = messageKey.lastIndexOf(":");
|
int p = messageKey.lastIndexOf(":");
|
||||||
if( p >= 0 ) {
|
if( p >= 0 ) {
|
||||||
producerSequenceId = Long.parseLong(messageKey.substring(p+1));
|
producerSequenceId = Long.parseLong(messageKey.substring(p+1));
|
||||||
messageKey = messageKey.substring(0,p);
|
messageKey = messageKey.substring(0,p);
|
||||||
}
|
}
|
||||||
producerId = new ProducerId(messageKey);
|
producerId = new ProducerId(messageKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the transient text view of the message which will be ignored
|
||||||
|
* if the message is marshaled on a transport; so is only for in-JVM changes
|
||||||
|
* to accommodate foreign JMS message IDs
|
||||||
|
*/
|
||||||
|
public void setTextView(String key) {
|
||||||
|
this.key = key;
|
||||||
|
}
|
||||||
|
|
||||||
public byte getDataStructureType() {
|
public byte getDataStructureType() {
|
||||||
return DATA_STRUCTURE_TYPE;
|
return DATA_STRUCTURE_TYPE;
|
||||||
|
|
|
@ -129,6 +129,11 @@ public class ActiveMQMessageTest extends TestCase {
|
||||||
assertTrue(test);
|
assertTrue(test);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testSetToForeignJMSID() throws Exception {
|
||||||
|
ActiveMQMessage msg = new ActiveMQMessage();
|
||||||
|
msg.setJMSMessageID("ID:EMS-SERVER.8B443C380083:429");
|
||||||
|
|
||||||
|
}
|
||||||
/*
|
/*
|
||||||
* Class to test for boolean equals(Object)
|
* Class to test for boolean equals(Object)
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue