You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ri...@apache.org on 2006/11/28 17:26:41 UTC
svn commit: r480119 - in /incubator/qpid/trunk/qpid/java/client/src:
main/java/org/apache/qpid/client/message/
test/java/org/apache/qpid/test/unit/basic/
Author: ritchiem
Date: Tue Nov 28 08:26:40 2006
New Revision: 480119
URL: http://svn.apache.org/viewvc?view=rev&rev=480119
Log:
QPID-122
Pulled _readable (_readableMessage) boolean up to AbstractJMSMessage.java and created (_readableProperties).
Checks are now carried out to ensure that the message is readable/writable for the operation so that the correct exception can be thrown. As per the spec.
clearBody() method had been implemented in AbstractJMSMessage.java to reset the _readableMessage as a result implementations must now implement clearBodyImpl() which is called before the _readableMessage is reset.
Test updated to check that properties and body are correctly read/write set.
Modified:
incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/message/AbstractJMSMessage.java
incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/message/JMSBytesMessage.java
incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/message/JMSMapMessage.java
incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/message/JMSObjectMessage.java
incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/message/JMSTextMessage.java
incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/basic/BytesMessageTest.java
incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/basic/MapMessageTest.java
incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/basic/ObjectMessageTest.java
incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/basic/TextMessageTest.java
Modified: incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/message/AbstractJMSMessage.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/message/AbstractJMSMessage.java?view=diff&rev=480119&r1=480118&r2=480119
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/message/AbstractJMSMessage.java (original)
+++ incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/message/AbstractJMSMessage.java Tue Nov 28 08:26:40 2006
@@ -34,6 +34,8 @@
import javax.jms.Destination;
import javax.jms.JMSException;
+import javax.jms.MessageNotReadableException;
+import javax.jms.MessageNotWriteableException;
import java.util.Collections;
import java.util.Enumeration;
import java.util.Iterator;
@@ -54,12 +56,14 @@
public static final char LONG_PROPERTY_PREFIX = PropertyFieldTable.LONG_PROPERTY_PREFIX;
public static final char FLOAT_PROPERTY_PREFIX = PropertyFieldTable.FLOAT_PROPERTY_PREFIX;
public static final char DOUBLE_PROPERTY_PREFIX = PropertyFieldTable.DOUBLE_PROPERTY_PREFIX;
- public static final char STRING_PROPERTY_PREFIX = PropertyFieldTable.STRING_PROPERTY_PREFIX ;
+ public static final char STRING_PROPERTY_PREFIX = PropertyFieldTable.STRING_PROPERTY_PREFIX;
protected boolean _redelivered;
protected ByteBuffer _data;
+ private boolean _readableProperties = false;
+ private boolean _readableMessage = false;
protected AbstractJMSMessage(ByteBuffer data)
{
@@ -69,6 +73,8 @@
{
_data.acquire();
}
+ _readableProperties = (_contentHeaderProperties != null);
+ _readableMessage = (data != null);
}
protected AbstractJMSMessage(long deliveryTag, BasicContentHeaderProperties contentHeader, ByteBuffer data) throws AMQException
@@ -79,6 +85,9 @@
{
_data.acquire();
}
+
+ _readableProperties = (_contentHeaderProperties != null);
+ _readableMessage = data != null;
}
protected AbstractJMSMessage(BasicContentHeaderProperties contentHeader, long deliveryTag)
@@ -170,7 +179,7 @@
if (!(destination instanceof AMQDestination))
{
throw new IllegalArgumentException("ReplyTo destination my be an AMQ destination - passed argument was type " +
- destination.getClass());
+ destination.getClass());
}
final AMQDestination amqd = (AMQDestination) destination;
@@ -216,9 +225,9 @@
}
public void setJMSType(String string) throws JMSException
- {
+ {
//throw new JMSException("Cannot set JMS Type - it is implicitly defined based on message type");
- // this is not spec comliant, should not throw the message
+ // this is not spec comliant, should not throw the message
}
public long getJMSExpiration() throws JMSException
@@ -247,8 +256,17 @@
{
getJmsContentHeaderProperties().getHeaders().clear();
}
+
+ _readableProperties = false;
}
+ public void clearBody() throws JMSException
+ {
+ clearBodyImpl();
+ _readableMessage = false;
+ }
+
+
public boolean propertyExists(String propertyName) throws JMSException
{
checkPropertyName(propertyName);
@@ -460,6 +478,7 @@
public void setBooleanProperty(String propertyName, boolean b) throws JMSException
{
+ checkWritableProperties();
checkPropertyName(propertyName);
//getJmsContentHeaderProperties().headers.put(BOOLEAN_PROPERTY_PREFIX + propertyName, Boolean.valueOf(b));
getJmsContentHeaderProperties().getHeaders().put(BOOLEAN_PROPERTY_PREFIX + propertyName, b ? new Long(1) : new Long(0));
@@ -467,42 +486,49 @@
public void setByteProperty(String propertyName, byte b) throws JMSException
{
+ checkWritableProperties();
checkPropertyName(propertyName);
getJmsContentHeaderProperties().getHeaders().put(BYTE_PROPERTY_PREFIX + propertyName, new Byte(b));
}
public void setShortProperty(String propertyName, short i) throws JMSException
{
+ checkWritableProperties();
checkPropertyName(propertyName);
getJmsContentHeaderProperties().getHeaders().put(SHORT_PROPERTY_PREFIX + propertyName, new Short(i));
}
public void setIntProperty(String propertyName, int i) throws JMSException
{
+ checkWritableProperties();
checkPropertyName(propertyName);
getJmsContentHeaderProperties().getHeaders().put(INT_PROPERTY_PREFIX + propertyName, new Integer(i));
}
public void setLongProperty(String propertyName, long l) throws JMSException
{
+ checkWritableProperties();
checkPropertyName(propertyName);
getJmsContentHeaderProperties().getHeaders().put(LONG_PROPERTY_PREFIX + propertyName, new Long(l));
}
public void setFloatProperty(String propertyName, float f) throws JMSException
{
+ checkWritableProperties();
checkPropertyName(propertyName);
getJmsContentHeaderProperties().getHeaders().put(FLOAT_PROPERTY_PREFIX + propertyName, new Float(f));
}
public void setDoubleProperty(String propertyName, double v) throws JMSException
{
+ checkWritableProperties();
checkPropertyName(propertyName);
getJmsContentHeaderProperties().getHeaders().put(DOUBLE_PROPERTY_PREFIX + propertyName, new Double(v));
}
public void setStringProperty(String propertyName, String value) throws JMSException
{
+ checkWritableProperties();
checkPropertyName(propertyName);
getJmsContentHeaderProperties().getHeaders().put(STRING_PROPERTY_PREFIX + propertyName, value);
}
@@ -533,7 +559,13 @@
}
}
- public abstract void clearBody() throws JMSException;
+
+ /**
+ * This forces concrete classes to implement clearBody()
+ *
+ * @throws JMSException
+ */
+ public abstract void clearBodyImpl() throws JMSException;
/**
* Get a String representation of the body of the message. Used in the
@@ -604,7 +636,7 @@
break;
default:
buf.append("<unknown type (identifier " +
- typeIdentifier + ") ");
+ typeIdentifier + ") ");
}
buf.append(String.valueOf(entry.getValue()));
}
@@ -630,6 +662,7 @@
private void checkPropertyName(String propertyName)
{
+
if (propertyName == null)
{
throw new IllegalArgumentException("Property name must not be null");
@@ -688,4 +721,44 @@
}
return _data;
}
+
+ protected void checkReadable() throws MessageNotReadableException
+ {
+ if (!_readableMessage)
+ {
+ throw new MessageNotReadableException("You need to call reset() to make the message readable");
+ }
+ }
+
+ protected void checkWritable() throws MessageNotWriteableException
+ {
+ if (_readableMessage)
+ {
+ throw new MessageNotWriteableException("You need to call clearBody() to make the message writable");
+ }
+ }
+
+ protected void checkWritableProperties() throws MessageNotWriteableException
+ {
+ if (_readableProperties)
+ {
+ throw new MessageNotWriteableException("You need to call clearProperties() to make the message writable");
+ }
+ }
+
+ public boolean isReadable()
+ {
+ return _readableMessage;
+ }
+
+ public boolean isWritable()
+ {
+ return !_readableMessage;
+ }
+
+ public void reset() throws JMSException
+ {
+ _readableMessage = true;
+ }
+
}
Modified: incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/message/JMSBytesMessage.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/message/JMSBytesMessage.java?view=diff&rev=480119&r1=480118&r2=480119
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/message/JMSBytesMessage.java (original)
+++ incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/message/JMSBytesMessage.java Tue Nov 28 08:26:40 2006
@@ -37,7 +37,6 @@
{
private static final String MIME_TYPE = "application/octet-stream";
- private boolean _readable = false;
/**
* The default initial size of the buffer. The buffer expands automatically.
@@ -65,7 +64,6 @@
_data = ByteBuffer.allocate(DEFAULT_BUFFER_INITIAL_SIZE);
_data.setAutoExpand(true);
}
- _readable = (data != null);
}
JMSBytesMessage(long messageNbr, ContentHeaderBody contentHeader, ByteBuffer data)
@@ -74,13 +72,11 @@
// TODO: this casting is ugly. Need to review whole ContentHeaderBody idea
super(messageNbr, (BasicContentHeaderProperties) contentHeader.properties, data);
getJmsContentHeaderProperties().setContentType(MIME_TYPE);
- _readable = true;
}
- public void clearBody() throws JMSException
+ public void clearBodyImpl() throws JMSException
{
_data.clear();
- _readable = false;
}
public String toBodyString() throws JMSException
@@ -139,13 +135,6 @@
return _data.limit();
}
- private void checkReadable() throws MessageNotReadableException
- {
- if (!_readable)
- {
- throw new MessageNotReadableException("You need to call reset() to make the message readable");
- }
- }
/**
* Check that there is at least a certain number of bytes available to read
@@ -161,14 +150,6 @@
}
}
- private void checkWritable() throws MessageNotWriteableException
- {
- if (_readable)
- {
- throw new MessageNotWriteableException("You need to call clearBody() to make the message writable");
- }
- }
-
public boolean readBoolean() throws JMSException
{
checkReadable();
@@ -392,13 +373,8 @@
public void reset() throws JMSException
{
- //checkWritable();
+ super.reset();
_data.flip();
- _readable = true;
}
- public boolean isReadable()
- {
- return _readable;
- }
}
Modified: incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/message/JMSMapMessage.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/message/JMSMapMessage.java?view=diff&rev=480119&r1=480118&r2=480119
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/message/JMSMapMessage.java (original)
+++ incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/message/JMSMapMessage.java Tue Nov 28 08:26:40 2006
@@ -68,13 +68,13 @@
// AbstractJMSMessage Interface
- public void clearBody() throws JMSException
+ public void clearBodyImpl() throws JMSException
{
if (_data != null)
{
_data.release();
}
- _data = null;
+ _data = null;
}
public String toBodyString() throws JMSException
@@ -206,48 +206,55 @@
public void setBoolean(String string, boolean b) throws JMSException
{
+ checkWritable();
_map.setBoolean(string, b);
}
public void setByte(String string, byte b) throws JMSException
{
+ checkWritable();
_map.setByte(string, b);
}
public void setShort(String string, short i) throws JMSException
{
+ checkWritable();
_map.setShort(string, i);
}
public void setChar(String string, char c) throws JMSException
{
+ checkWritable();
_map.setChar(string, c);
}
public void setInt(String string, int i) throws JMSException
{
+ checkWritable();
_map.setInteger(string, i);
}
public void setLong(String string, long l) throws JMSException
{
+ checkWritable();
_map.setLong(string, l);
}
public void setFloat(String string, float v) throws JMSException
{
-
+ checkWritable();
_map.setFloat(string, v);
}
public void setDouble(String string, double v) throws JMSException
{
-
+ checkWritable();
_map.setDouble(string, v);
}
public void setString(String string, String string1) throws JMSException
{
+ checkWritable();
_map.setString(string, string1);
}
@@ -258,11 +265,13 @@
public void setBytes(String string, byte[] bytes, int i, int i1) throws JMSException
{
+ checkWritable();
_map.setBytes(string, bytes, i, i1);
}
public void setObject(String string, Object object) throws JMSException
{
+ checkWritable();
_map.setObject(string, object);
}
Modified: incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/message/JMSObjectMessage.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/message/JMSObjectMessage.java?view=diff&rev=480119&r1=480118&r2=480119
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/message/JMSObjectMessage.java (original)
+++ incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/message/JMSObjectMessage.java Tue Nov 28 08:26:40 2006
@@ -36,7 +36,6 @@
public class JMSObjectMessage extends AbstractJMSMessage implements ObjectMessage
{
static final String MIME_TYPE = "application/java-object-stream";
- private final boolean _readonly;
private static final int DEFAULT_BUFFER_SIZE = 1024;
@@ -56,7 +55,6 @@
_data = ByteBuffer.allocate(DEFAULT_BUFFER_SIZE);
_data.setAutoExpand(true);
}
- _readonly = (data != null);
getJmsContentHeaderProperties().setContentType(MIME_TYPE);
}
@@ -66,10 +64,9 @@
JMSObjectMessage(long messageNbr, ContentHeaderBody contentHeader, ByteBuffer data) throws AMQException
{
super(messageNbr, (BasicContentHeaderProperties) contentHeader.properties, data);
- _readonly = data != null;
}
- public void clearBody() throws JMSException
+ public void clearBodyImpl() throws JMSException
{
if (_data != null)
{
@@ -90,10 +87,7 @@
public void setObject(Serializable serializable) throws JMSException
{
- if (_readonly)
- {
- throw new MessageNotWriteableException("Message is not writable.");
- }
+ checkWritable();
if (_data == null)
{
Modified: incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/message/JMSTextMessage.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/message/JMSTextMessage.java?view=diff&rev=480119&r1=480118&r2=480119
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/message/JMSTextMessage.java (original)
+++ incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/message/JMSTextMessage.java Tue Nov 28 08:26:40 2006
@@ -66,7 +66,7 @@
setText(text);
}
- public void clearBody() throws JMSException
+ public void clearBodyImpl() throws JMSException
{
if (_data != null)
{
@@ -93,6 +93,8 @@
public void setText(String string) throws JMSException
{
+ checkWritable();
+
clearBody();
try
{
Modified: incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/basic/BytesMessageTest.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/basic/BytesMessageTest.java?view=diff&rev=480119&r1=480118&r2=480119
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/basic/BytesMessageTest.java (original)
+++ incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/basic/BytesMessageTest.java Tue Nov 28 08:26:40 2006
@@ -135,6 +135,8 @@
buffer.get(data);
actual.add(data);
+
+ //Check Body Write Status
try
{
m.writeBoolean(true);
@@ -144,6 +146,41 @@
{
//normal execution
}
+
+ m.clearBody();
+
+ try
+ {
+ m.writeBoolean(true);
+ }
+ catch (MessageNotWriteableException mnwe)
+ {
+ Assert.fail("Message should be writeable");
+ }
+
+
+ //Check property write status
+ try
+ {
+ m.setStringProperty("test", "test");
+ Assert.fail("Message should not be writeable");
+ }
+ catch (MessageNotWriteableException mnwe)
+ {
+ //normal execution
+ }
+
+ m.clearProperties();
+
+ try
+ {
+ m.setStringProperty("test", "test");
+ }
+ catch (MessageNotWriteableException mnwe)
+ {
+ Assert.fail("Message should be writeable");
+ }
+
}
assertEqual(messages.iterator(), actual.iterator());
Modified: incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/basic/MapMessageTest.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/basic/MapMessageTest.java?view=diff&rev=480119&r1=480118&r2=480119
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/basic/MapMessageTest.java (original)
+++ incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/basic/MapMessageTest.java Tue Nov 28 08:26:40 2006
@@ -132,16 +132,48 @@
assertEqual(m.getInt("messageNumber"), count);
assertEqual(m.getBoolean("odd"), count / 2 == 0);
-// try
-// {
-// m.setInt("testint", 3);
-// fail("Message should not be writeable");
-// }
-// catch (MessageNotWriteableException mnwe)
-// {
-// //normal execution
-// }
+ try
+ {
+ m.setInt("testint", 3);
+ fail("Message should not be writeable");
+ }
+ catch (MessageNotWriteableException mnwe)
+ {
+ //normal execution
+ }
+ m.clearBody();
+
+ try
+ {
+ m.setInt("testint", 3);
+ }
+ catch (MessageNotWriteableException mnwe)
+ {
+ Assert.fail("Message should be writeable");
+ }
+
+ //Check property write status
+ try
+ {
+ m.setStringProperty("test", "test");
+ Assert.fail("Message should not be writeable");
+ }
+ catch (MessageNotWriteableException mnwe)
+ {
+ //normal execution
+ }
+
+ m.clearProperties();
+
+ try
+ {
+ m.setStringProperty("test", "test");
+ }
+ catch (MessageNotWriteableException mnwe)
+ {
+ Assert.fail("Message should be writeable");
+ }
count++;
}
Modified: incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/basic/ObjectMessageTest.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/basic/ObjectMessageTest.java?view=diff&rev=480119&r1=480118&r2=480119
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/basic/ObjectMessageTest.java (original)
+++ incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/basic/ObjectMessageTest.java Tue Nov 28 08:26:40 2006
@@ -125,19 +125,53 @@
{
actual.add(m.getObject());
-// try
-// {
-// m.setObject("Test text");
-// Assert.fail("Message should not be writeable");
-// }
-// catch (MessageNotWriteableException mnwe)
-// {
-// //normal execution
-// }
+ try
+ {
+ m.setObject("Test text");
+ Assert.fail("Message should not be writeable");
+ }
+ catch (MessageNotWriteableException mnwe)
+ {
+ //normal execution
+ }
+
+ m.clearBody();
+
+ try
+ {
+ m.setObject("Test text");
+ }
+ catch (MessageNotWriteableException mnwe)
+ {
+ Assert.fail("Message should be writeable");
+ }
+
+ //Check property write status
+ try
+ {
+ m.setStringProperty("test", "test");
+ Assert.fail("Message should not be writeable");
+ }
+ catch (MessageNotWriteableException mnwe)
+ {
+ //normal execution
+ }
+
+ m.clearProperties();
+
+ try
+ {
+ m.setStringProperty("test", "test");
+ }
+ catch (MessageNotWriteableException mnwe)
+ {
+ Assert.fail("Message should be writeable");
+ }
}
assertEqual(messages.iterator(), actual.iterator());
+
}
private static void assertEqual(Iterator expected, Iterator actual)
Modified: incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/basic/TextMessageTest.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/basic/TextMessageTest.java?view=diff&rev=480119&r1=480118&r2=480119
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/basic/TextMessageTest.java (original)
+++ incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/basic/TextMessageTest.java Tue Nov 28 08:26:40 2006
@@ -122,15 +122,49 @@
{
actual.add(m.getText());
-// try
-// {
-// m.setText("Test text");
-// Assert.fail("Message should not be writeable");
-// }
-// catch (MessageNotWriteableException mnwe)
-// {
-// //normal execution
-// }
+ //Check body write status
+ try
+ {
+ m.setText("Test text");
+ Assert.fail("Message should not be writeable");
+ }
+ catch (MessageNotWriteableException mnwe)
+ {
+ //normal execution
+ }
+
+ m.clearBody();
+
+ try
+ {
+ m.setText("Test text");
+ }
+ catch (MessageNotWriteableException mnwe)
+ {
+ Assert.fail("Message should be writeable");
+ }
+
+ //Check property write status
+ try
+ {
+ m.setStringProperty("test", "test");
+ Assert.fail("Message should not be writeable");
+ }
+ catch (MessageNotWriteableException mnwe)
+ {
+ //normal execution
+ }
+
+ m.clearProperties();
+
+ try
+ {
+ m.setStringProperty("test", "test");
+ }
+ catch (MessageNotWriteableException mnwe)
+ {
+ Assert.fail("Message should be writeable");
+ }
}