diff options
author | Rajith Muditha Attapattu <rajith@apache.org> | 2010-01-28 00:58:15 +0000 |
---|---|---|
committer | Rajith Muditha Attapattu <rajith@apache.org> | 2010-01-28 00:58:15 +0000 |
commit | 1b680b84389cfdc5873e7fcc7bf41e8e06355304 (patch) | |
tree | 28749e0cf87bcae1412358ca944b4c4ed90668a4 | |
parent | c15ed6d672cc8ab5f439038ae657ca05d3fb91cc (diff) | |
download | qpid-python-1b680b84389cfdc5873e7fcc7bf41e8e06355304.tar.gz |
This commit contains the changes agreed upon in QPID-2363 except for the connection parameter which will be added shortly
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@903924 13f79535-47bb-0310-9956-ffa450edef68
6 files changed, 74 insertions, 108 deletions
diff --git a/java/client/src/main/java/org/apache/qpid/client/AMQSession.java b/java/client/src/main/java/org/apache/qpid/client/AMQSession.java index fc1778f0a1..2f9ddd81ad 100644 --- a/java/client/src/main/java/org/apache/qpid/client/AMQSession.java +++ b/java/client/src/main/java/org/apache/qpid/client/AMQSession.java @@ -71,6 +71,7 @@ import org.apache.qpid.client.failover.FailoverNoopSupport; import org.apache.qpid.client.failover.FailoverProtectedOperation; import org.apache.qpid.client.failover.FailoverRetrySupport; import org.apache.qpid.client.message.AMQMessageDelegateFactory; +import org.apache.qpid.client.message.AMQPEncodedMapMessage; import org.apache.qpid.client.message.AbstractJMSMessage; import org.apache.qpid.client.message.CloseConsumerMessage; import org.apache.qpid.client.message.JMSBytesMessage; @@ -226,6 +227,8 @@ public abstract class AMQSession<C extends BasicMessageConsumer, P extends Basic protected final boolean DECLARE_EXCHANGES = Boolean.parseBoolean(System.getProperty("qpid.declare_exchanges", "true")); + protected boolean USE_AMQP_ENCODED_MAP_MESSAGE = !Boolean.getBoolean("qpid.use_legacy_map_message"); + /** System property to enable strict AMQP compliance. */ public static final String STRICT_AMQP = "STRICT_AMQP"; @@ -995,7 +998,14 @@ public abstract class AMQSession<C extends BasicMessageConsumer, P extends Basic public MapMessage createMapMessage() throws JMSException { checkNotClosed(); - return new JMSMapMessage(getMessageDelegateFactory()); + if (USE_AMQP_ENCODED_MAP_MESSAGE) + { + return new AMQPEncodedMapMessage(getMessageDelegateFactory()); + } + else + { + return new JMSMapMessage(getMessageDelegateFactory()); + } } public javax.jms.Message createMessage() throws JMSException diff --git a/java/client/src/main/java/org/apache/qpid/client/message/AMQMessageDelegate.java b/java/client/src/main/java/org/apache/qpid/client/message/AMQMessageDelegate.java index fe919ddd9e..c2821591d8 100644 --- a/java/client/src/main/java/org/apache/qpid/client/message/AMQMessageDelegate.java +++ b/java/client/src/main/java/org/apache/qpid/client/message/AMQMessageDelegate.java @@ -137,8 +137,4 @@ public interface AMQMessageDelegate long getDeliveryTag(); void setJMSMessageID(final UUID messageId) throws JMSException; - - ByteBuffer encodeMap(Map<String,Object> map); - - Map<String,Object> decodeMap(ByteBuffer buf); } diff --git a/java/client/src/main/java/org/apache/qpid/client/message/AMQMessageDelegate_0_10.java b/java/client/src/main/java/org/apache/qpid/client/message/AMQMessageDelegate_0_10.java index 053bfe095d..228123aa78 100644 --- a/java/client/src/main/java/org/apache/qpid/client/message/AMQMessageDelegate_0_10.java +++ b/java/client/src/main/java/org/apache/qpid/client/message/AMQMessageDelegate_0_10.java @@ -921,19 +921,4 @@ public class AMQMessageDelegate_0_10 extends AbstractAMQMessageDelegate { return _deliveryProps; } - - - public java.nio.ByteBuffer encodeMap(Map<String,Object> map) - { - BBEncoder encoder = new BBEncoder(1024); - encoder.writeMap(map); - return encoder.segment(); - } - - public Map<String,Object> decodeMap(java.nio.ByteBuffer buf) - { - BBDecoder decoder = new BBDecoder(); - decoder.init(buf); - return decoder.readMap(); - } } diff --git a/java/client/src/main/java/org/apache/qpid/client/message/AMQMessageDelegate_0_8.java b/java/client/src/main/java/org/apache/qpid/client/message/AMQMessageDelegate_0_8.java index 2a3bd20f11..b59599e722 100644 --- a/java/client/src/main/java/org/apache/qpid/client/message/AMQMessageDelegate_0_8.java +++ b/java/client/src/main/java/org/apache/qpid/client/message/AMQMessageDelegate_0_8.java @@ -573,25 +573,4 @@ public class AMQMessageDelegate_0_8 extends AbstractAMQMessageDelegate return _deliveryTag; } - - public java.nio.ByteBuffer encodeMap(Map<String,Object> map) - { - String errorMsg = "There is no support for encoding maps"; - if (_session != null) - { - errorMsg = errorMsg + " in AMQP " + _session.getAMQConnection().getProtocolVersion(); - } - throw new UnsupportedOperationException(errorMsg); - } - - public Map<String,Object> decodeMap(java.nio.ByteBuffer buf) - { - String errorMsg = "There is no support for encoding maps"; - if (_session != null) - { - errorMsg = errorMsg + " in AMQP " + _session.getAMQConnection().getProtocolVersion(); - } - throw new UnsupportedOperationException(errorMsg); - } - } diff --git a/java/client/src/main/java/org/apache/qpid/client/message/AMQPEncodedMapMessage.java b/java/client/src/main/java/org/apache/qpid/client/message/AMQPEncodedMapMessage.java index 4412476b45..2e9d932e40 100644 --- a/java/client/src/main/java/org/apache/qpid/client/message/AMQPEncodedMapMessage.java +++ b/java/client/src/main/java/org/apache/qpid/client/message/AMQPEncodedMapMessage.java @@ -6,6 +6,8 @@ import javax.jms.JMSException; import org.apache.mina.common.ByteBuffer; import org.apache.qpid.AMQException; +import org.apache.qpid.transport.codec.BBDecoder; +import org.apache.qpid.transport.codec.BBEncoder; public class AMQPEncodedMapMessage extends JMSMapMessage { @@ -46,7 +48,9 @@ public class AMQPEncodedMapMessage extends JMSMapMessage if (_data != null) { _data.rewind(); - _map = _delegate.decodeMap(_data.buf()); + BBDecoder decoder = new BBDecoder(); + decoder.init(_data.buf()); + _map = decoder.readMap(); } else { @@ -57,7 +61,9 @@ public class AMQPEncodedMapMessage extends JMSMapMessage @ Override protected void writeMapToData() { - _data = ByteBuffer.wrap(_delegate.encodeMap(_map)); + BBEncoder encoder = new BBEncoder(1024); + encoder.writeMap(_map); + _data = ByteBuffer.wrap(encoder.segment()); } // for testing diff --git a/java/systests/src/main/java/org/apache/qpid/client/message/AMQPEncodedMapMessageTest.java b/java/systests/src/main/java/org/apache/qpid/client/message/AMQPEncodedMapMessageTest.java index 8852ff82cd..8265b75201 100644 --- a/java/systests/src/main/java/org/apache/qpid/client/message/AMQPEncodedMapMessageTest.java +++ b/java/systests/src/main/java/org/apache/qpid/client/message/AMQPEncodedMapMessageTest.java @@ -53,79 +53,69 @@ public class AMQPEncodedMapMessageTest extends QpidTestCase public void testEmptyMessage() throws JMSException { - if (((AMQConnection)_connection).getProtocolVersion() == ProtocolVersion.v0_10) - { - MapMessage m = _session.createMapMessage(); - _producer.send(m); - AMQPEncodedMapMessage msg = (AMQPEncodedMapMessage)_consumer.receive(RECEIVE_TIMEOUT); - assertNotNull("Message was not received on time",msg); - assertEquals("Message content-type is incorrect", - AMQPEncodedMapMessage.MIME_TYPE, - ((AbstractJMSMessage)msg).getContentType()); - - assertEquals("Message content should be an empty map", - Collections.EMPTY_MAP, - ((AMQPEncodedMapMessage)msg).getMap()); - - } + MapMessage m = _session.createMapMessage(); + _producer.send(m); + AMQPEncodedMapMessage msg = (AMQPEncodedMapMessage)_consumer.receive(RECEIVE_TIMEOUT); + assertNotNull("Message was not received on time",msg); + assertEquals("Message content-type is incorrect", + AMQPEncodedMapMessage.MIME_TYPE, + ((AbstractJMSMessage)msg).getContentType()); + + assertEquals("Message content should be an empty map", + Collections.EMPTY_MAP, + ((AMQPEncodedMapMessage)msg).getMap()); } public void testNullMessage() throws JMSException { - if (((AMQConnection)_connection).getProtocolVersion() == ProtocolVersion.v0_10) - { - MapMessage m = _session.createMapMessage(); - ((AMQPEncodedMapMessage)m).setMap(null); - _producer.send(m); - AMQPEncodedMapMessage msg = (AMQPEncodedMapMessage)_consumer.receive(RECEIVE_TIMEOUT); - assertNotNull("Message was not received on time",msg); - assertEquals("Message content-type is incorrect", - AMQPEncodedMapMessage.MIME_TYPE, - ((AbstractJMSMessage)msg).getContentType()); - - assertEquals("Message content should be null", - null, - ((AMQPEncodedMapMessage)msg).getMap()); - - } + MapMessage m = _session.createMapMessage(); + ((AMQPEncodedMapMessage)m).setMap(null); + _producer.send(m); + AMQPEncodedMapMessage msg = (AMQPEncodedMapMessage)_consumer.receive(RECEIVE_TIMEOUT); + assertNotNull("Message was not received on time",msg); + assertEquals("Message content-type is incorrect", + AMQPEncodedMapMessage.MIME_TYPE, + ((AbstractJMSMessage)msg).getContentType()); + + assertEquals("Message content should be null", + null, + ((AMQPEncodedMapMessage)msg).getMap()); + } public void testMessageWithContent() throws JMSException { - if (((AMQConnection)_connection).getProtocolVersion() == ProtocolVersion.v0_10) - { - MapMessage m = _session.createMapMessage(); - m.setBoolean("Boolean", true); - m.setByte("Byte", (byte)5); - byte[] bytes = new byte[]{(byte)5,(byte)8}; - m.setBytes("Bytes", bytes); - m.setChar("Char", 'X'); - m.setDouble("Double", 56.84); - m.setFloat("Float", Integer.MAX_VALUE + 5000); - m.setInt("Int", Integer.MAX_VALUE - 5000); - m.setShort("Short", (short)58); - m.setString("String", "Hello"); - _producer.send(m); - - AMQPEncodedMapMessage msg = (AMQPEncodedMapMessage)_consumer.receive(RECEIVE_TIMEOUT); - assertNotNull("Message was not received on time",msg); - assertEquals("Message content-type is incorrect", - AMQPEncodedMapMessage.MIME_TYPE, - ((AbstractJMSMessage)msg).getContentType()); - - assertEquals(true,m.getBoolean("Boolean")); - assertEquals((byte)5,m.getByte("Byte")); - byte[] bytesRcv = m.getBytes("Bytes"); - assertNotNull("Byte array is null",bytesRcv); - assertEquals((byte)5,bytesRcv[0]); - assertEquals((byte)8,bytesRcv[1]); - assertEquals('X',m.getChar("Char")); - assertEquals(56.84,m.getDouble("Double")); - //assertEquals(Integer.MAX_VALUE + 5000,m.getFloat("Float")); - assertEquals(Integer.MAX_VALUE - 5000,m.getInt("Int")); - assertEquals((short)58,m.getShort("Short")); - assertEquals("Hello",m.getString("String")); - } + MapMessage m = _session.createMapMessage(); + m.setBoolean("Boolean", true); + m.setByte("Byte", (byte)5); + byte[] bytes = new byte[]{(byte)5,(byte)8}; + m.setBytes("Bytes", bytes); + m.setChar("Char", 'X'); + m.setDouble("Double", 56.84); + m.setFloat("Float", Integer.MAX_VALUE + 5000); + m.setInt("Int", Integer.MAX_VALUE - 5000); + m.setShort("Short", (short)58); + m.setString("String", "Hello"); + _producer.send(m); + + AMQPEncodedMapMessage msg = (AMQPEncodedMapMessage)_consumer.receive(RECEIVE_TIMEOUT); + assertNotNull("Message was not received on time",msg); + assertEquals("Message content-type is incorrect", + AMQPEncodedMapMessage.MIME_TYPE, + ((AbstractJMSMessage)msg).getContentType()); + + assertEquals(true,m.getBoolean("Boolean")); + assertEquals((byte)5,m.getByte("Byte")); + byte[] bytesRcv = m.getBytes("Bytes"); + assertNotNull("Byte array is null",bytesRcv); + assertEquals((byte)5,bytesRcv[0]); + assertEquals((byte)8,bytesRcv[1]); + assertEquals('X',m.getChar("Char")); + assertEquals(56.84,m.getDouble("Double")); + //assertEquals(Integer.MAX_VALUE + 5000,m.getFloat("Float")); + assertEquals(Integer.MAX_VALUE - 5000,m.getInt("Int")); + assertEquals((short)58,m.getShort("Short")); + assertEquals("Hello",m.getString("String")); } public void tearDown() throws Exception |