Add check for unmarshalled text body and handle that case.
This commit is contained in:
Timothy Bish 2016-08-23 09:58:05 -04:00
parent 8447e1af2d
commit 1030fb1842
2 changed files with 40 additions and 0 deletions

View File

@ -17,6 +17,7 @@
package org.apache.activemq.transport.amqp.message;
import java.io.DataInputStream;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
@ -343,6 +344,8 @@ public class ActiveMQJMSVendor {
// Message includes a size prefix of four bytes for the OpenWire marshaler
result = new Binary(contents.getData(), contents.getOffset() + 4, contents.getLength() - 4);
}
} else if (textMessage.getText() != null) {
result = new Binary(textMessage.getText().getBytes(StandardCharsets.UTF_8));
}
return result;

View File

@ -605,6 +605,27 @@ public class JMSMappingOutboundTransformerTest {
assertEquals(contentString, contents);
}
@Test
public void testConvertTextMessageContentNotStoredCreatesBodyUsingOriginalEncodingWithDataSection() throws Exception {
String contentString = "myTextMessageContent";
ActiveMQTextMessage outbound = createTextMessage(contentString);
outbound.setShortProperty(AMQP_ORIGINAL_ENCODING_KEY, AMQP_DATA);
outbound.onSend();
ActiveMQJMSVendor vendor = createVendor();
JMSMappingOutboundTransformer transformer = new JMSMappingOutboundTransformer(vendor);
Message amqp = transformer.convert(outbound);
assertNotNull(amqp.getBody());
assertTrue(amqp.getBody() instanceof Data);
assertTrue(((Data) amqp.getBody()).getValue() instanceof Binary);
Binary data = ((Data) amqp.getBody()).getValue();
String contents = new String(data.getArray(), data.getArrayOffset(), data.getLength(), StandardCharsets.UTF_8);
assertEquals(contentString, contents);
}
@Test
public void testConvertTextMessageCreatesAmqpValueStringBody() throws Exception {
String contentString = "myTextMessageContent";
@ -622,6 +643,22 @@ public class JMSMappingOutboundTransformerTest {
assertEquals(contentString, ((AmqpValue) amqp.getBody()).getValue());
}
@Test
public void testConvertTextMessageContentNotStoredCreatesAmqpValueStringBody() throws Exception {
String contentString = "myTextMessageContent";
ActiveMQTextMessage outbound = createTextMessage(contentString);
outbound.onSend();
ActiveMQJMSVendor vendor = createVendor();
JMSMappingOutboundTransformer transformer = new JMSMappingOutboundTransformer(vendor);
Message amqp = transformer.convert(outbound);
assertNotNull(amqp.getBody());
assertTrue(amqp.getBody() instanceof AmqpValue);
assertEquals(contentString, ((AmqpValue) amqp.getBody()).getValue());
}
@Test
public void testConvertCompressedTextMessageCreatesDataSectionBody() throws Exception {
String contentString = "myTextMessageContent";