mirror of https://github.com/apache/activemq.git
This commit is contained in:
parent
deee040151
commit
b1bc593931
|
@ -396,13 +396,25 @@ public class ActiveMQMessage extends Message implements org.apache.activemq.Mess
|
|||
JMS_PROPERTY_SETERS.put("JMSDeliveryMode", new PropertySetter() {
|
||||
@Override
|
||||
public void set(Message message, Object value) throws MessageFormatException {
|
||||
Integer rc = (Integer) TypeConversionSupport.convert(value, Integer.class);
|
||||
Integer rc = null;
|
||||
try {
|
||||
rc = (Integer) TypeConversionSupport.convert(value, Integer.class);
|
||||
} catch (NumberFormatException nfe) {
|
||||
if (value instanceof String) {
|
||||
if (((String) value).equalsIgnoreCase("PERSISTENT")) {
|
||||
rc = DeliveryMode.PERSISTENT;
|
||||
} else if (((String) value).equalsIgnoreCase("NON_PERSISTENT")) {
|
||||
rc = DeliveryMode.NON_PERSISTENT;
|
||||
} else {
|
||||
throw nfe;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (rc == null) {
|
||||
Boolean bool = (Boolean) TypeConversionSupport.convert(value, Boolean.class);
|
||||
if (bool == null) {
|
||||
throw new MessageFormatException("Property JMSDeliveryMode cannot be set from a " + value.getClass().getName() + ".");
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
rc = bool.booleanValue() ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ import java.io.IOException;
|
|||
import java.util.Enumeration;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.jms.DeliveryMode;
|
||||
import javax.jms.JMSException;
|
||||
import javax.jms.Message;
|
||||
import javax.jms.MessageFormatException;
|
||||
|
@ -353,6 +354,41 @@ public class ActiveMQMessageTest extends TestCase {
|
|||
assertTrue(((Float) msg.getObjectProperty(name)).floatValue() == 1.3f);
|
||||
}
|
||||
|
||||
public void testSetJMSDeliveryModeProperty() throws JMSException {
|
||||
ActiveMQMessage message = new ActiveMQMessage();
|
||||
String propertyName = "JMSDeliveryMode";
|
||||
|
||||
// Set as Boolean
|
||||
message.setObjectProperty(propertyName, Boolean.TRUE);
|
||||
assertTrue(message.isPersistent());
|
||||
message.setObjectProperty(propertyName, Boolean.FALSE);
|
||||
assertFalse(message.isPersistent());
|
||||
message.setBooleanProperty(propertyName, true);
|
||||
assertTrue(message.isPersistent());
|
||||
message.setBooleanProperty(propertyName, false);
|
||||
assertFalse(message.isPersistent());
|
||||
|
||||
// Set as Integer
|
||||
message.setObjectProperty(propertyName, DeliveryMode.PERSISTENT);
|
||||
assertTrue(message.isPersistent());
|
||||
message.setObjectProperty(propertyName, DeliveryMode.NON_PERSISTENT);
|
||||
assertFalse(message.isPersistent());
|
||||
message.setIntProperty(propertyName, DeliveryMode.PERSISTENT);
|
||||
assertTrue(message.isPersistent());
|
||||
message.setIntProperty(propertyName, DeliveryMode.NON_PERSISTENT);
|
||||
assertFalse(message.isPersistent());
|
||||
|
||||
// Set as String
|
||||
message.setObjectProperty(propertyName, "PERSISTENT");
|
||||
assertTrue(message.isPersistent());
|
||||
message.setObjectProperty(propertyName, "NON_PERSISTENT");
|
||||
assertFalse(message.isPersistent());
|
||||
message.setStringProperty(propertyName, "PERSISTENT");
|
||||
assertTrue(message.isPersistent());
|
||||
message.setStringProperty(propertyName, "NON_PERSISTENT");
|
||||
assertFalse(message.isPersistent());
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void testGetPropertyNames() throws JMSException {
|
||||
ActiveMQMessage msg = new ActiveMQMessage();
|
||||
|
|
Loading…
Reference in New Issue