mirror of https://github.com/apache/activemq.git
[AMQ-7291] rework fix to initializeWriting but just with the read only properties check
This commit is contained in:
parent
173426c55c
commit
62cfe83e9d
|
@ -832,6 +832,10 @@ public class ActiveMQBytesMessage extends ActiveMQMessage implements BytesMessag
|
|||
|
||||
private void initializeWriting() throws JMSException {
|
||||
checkReadOnlyBody();
|
||||
initializeWritingNoCheck();
|
||||
}
|
||||
|
||||
private void initializeWritingNoCheck() throws JMSException {
|
||||
if (this.dataOut == null) {
|
||||
this.bytesOut = new ByteArrayOutputStream();
|
||||
OutputStream os = bytesOut;
|
||||
|
@ -914,7 +918,8 @@ public class ActiveMQBytesMessage extends ActiveMQMessage implements BytesMessag
|
|||
|
||||
@Override
|
||||
public void setObjectProperty(String name, Object value) throws JMSException {
|
||||
initializeWriting();
|
||||
checkReadOnlyProperties();
|
||||
initializeWritingNoCheck();
|
||||
super.setObjectProperty(name, value);
|
||||
}
|
||||
|
||||
|
|
|
@ -736,7 +736,7 @@ public class ActiveMQMessage extends Message implements org.apache.activemq.Mess
|
|||
setObjectProperty(name, value);
|
||||
}
|
||||
|
||||
private void checkReadOnlyProperties() throws MessageNotWriteableException {
|
||||
protected void checkReadOnlyProperties() throws MessageNotWriteableException {
|
||||
if (readOnlyProperties) {
|
||||
throw new MessageNotWriteableException("Message properties are read-only");
|
||||
}
|
||||
|
|
|
@ -269,6 +269,30 @@ public class ActiveMQBytesMessageTest extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
public void testClearProperties() throws Exception {
|
||||
ActiveMQBytesMessage bytesMessage = new ActiveMQBytesMessage();
|
||||
bytesMessage.setIntProperty("one", 1);
|
||||
// simulate send
|
||||
bytesMessage.onSend();
|
||||
|
||||
assertEquals(1, bytesMessage.getIntProperty("one"));
|
||||
assertTrue(bytesMessage.isReadOnlyProperties());
|
||||
|
||||
try {
|
||||
bytesMessage.setIntProperty("two", 2);
|
||||
fail("should have thrown b/c readonly");
|
||||
} catch (MessageNotWriteableException expected) {
|
||||
}
|
||||
|
||||
// allow writing new properties
|
||||
bytesMessage.clearProperties();
|
||||
assertFalse(bytesMessage.propertyExists("one"));
|
||||
assertFalse(bytesMessage.isReadOnlyProperties());
|
||||
|
||||
bytesMessage.setIntProperty("two", 2);
|
||||
assertEquals(2, bytesMessage.getIntProperty("two"));
|
||||
}
|
||||
|
||||
public void testReset() throws JMSException {
|
||||
ActiveMQBytesMessage message = new ActiveMQBytesMessage();
|
||||
try {
|
||||
|
|
Loading…
Reference in New Issue