use of org.apache.qpid.server.protocol.v0_8.AMQMessage in project qpid-broker-j by apache.
the class MessageConverter_1_0_to_v0_8Test method testAmqpValueWithNullWithObjectMessageAnnotation.
@Test
public void testAmqpValueWithNullWithObjectMessageAnnotation() throws Exception {
final Object expected = null;
final AmqpValue amqpValue = new AmqpValue(expected);
Message_1_0 sourceMessage = createTestMessage(OBJECT_MESSAGE_MESSAGE_ANNOTATION, amqpValue.createEncodingRetainingSection());
final AMQMessage convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
final QpidByteBuffer content = convertedMessage.getContent(0, (int) convertedMessage.getSize());
assertEquals("Unexpected mime type", "application/java-object-stream", convertedMessage.getMessageHeader().getMimeType());
assertArrayEquals("Unexpected content size", getObjectBytes(null), getBytes(content));
}
use of org.apache.qpid.server.protocol.v0_8.AMQMessage in project qpid-broker-j by apache.
the class MessageConverter_1_0_to_v0_8Test method testDataWithContentTypeJmsStreamMessage.
@Test
public void testDataWithContentTypeJmsStreamMessage() throws Exception {
List<Object> originalMap = Collections.singletonList("testValue");
byte[] bytes = new ListToJmsStreamMessage().toMimeContent(originalMap);
final Data value = new Data(new Binary(bytes));
Properties properties = new Properties();
properties.setContentType(Symbol.valueOf("jms/stream-message"));
Message_1_0 sourceMessage = createTestMessage(properties, value.createEncodingRetainingSection());
final AMQMessage convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
assertEquals("Unexpected mime type", "jms/stream-message", convertedMessage.getMessageHeader().getMimeType());
final QpidByteBuffer content = convertedMessage.getContent(0, (int) convertedMessage.getSize());
assertArrayEquals("Unexpected content", bytes, getBytes(content));
}
use of org.apache.qpid.server.protocol.v0_8.AMQMessage in project qpid-broker-j by apache.
the class MessageConverter_1_0_to_v0_8Test method testAmqpValueWithNullWithJmsMapContentType.
@Test
public void testAmqpValueWithNullWithJmsMapContentType() throws Exception {
final Properties properties = new Properties();
properties.setContentType(Symbol.valueOf("jms/map-message"));
final Object expected = null;
final AmqpValue amqpValue = new AmqpValue(expected);
Message_1_0 sourceMessage = createTestMessage(properties, amqpValue.createEncodingRetainingSection());
final AMQMessage convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
final QpidByteBuffer content = convertedMessage.getContent(0, (int) convertedMessage.getSize());
assertEquals("Unexpected mime type", "jms/map-message", convertedMessage.getMessageHeader().getMimeType());
assertArrayEquals("Unexpected content size", new MapToJmsMapMessage().toMimeContent(Collections.emptyMap()), getBytes(content));
}
use of org.apache.qpid.server.protocol.v0_8.AMQMessage in project qpid-broker-j by apache.
the class MessageConverter_1_0_to_v0_8Test method testAmqpValueWithList.
@Test
public void testAmqpValueWithList() throws Exception {
final List<Object> originalList = new ArrayList<>();
originalList.add(new Binary(new byte[] { 0x00, (byte) 0xFF }));
originalList.add(42);
originalList.add(null);
final AmqpValue amqpValue = new AmqpValue(originalList);
Message_1_0 sourceMessage = createTestMessage(amqpValue.createEncodingRetainingSection());
final AMQMessage convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
assertEquals("Unexpected mime type", "jms/stream-message", convertedMessage.getMessageHeader().getMimeType());
final QpidByteBuffer content = convertedMessage.getContent(0, (int) convertedMessage.getSize());
List<Object> convertedList = new JmsStreamMessageToList().toObject(getBytes(content));
assertEquals("Unexpected size", (long) originalList.size(), (long) convertedList.size());
assertArrayEquals("Unexpected binary item", ((Binary) originalList.get(0)).getArray(), (byte[]) convertedList.get(0));
assertEquals("Unexpected int item", originalList.get(1), convertedList.get(1));
assertEquals("Unexpected null item", originalList.get(2), convertedList.get(2));
}
use of org.apache.qpid.server.protocol.v0_8.AMQMessage in project qpid-broker-j by apache.
the class MessageConverter_0_8_to_0_10 method convertMetaData.
private MessageMetaData_0_10 convertMetaData(AMQMessage message_0_8) {
DeliveryProperties deliveryProps = new DeliveryProperties();
MessageProperties messageProps = new MessageProperties();
int size = (int) message_0_8.getSize();
BasicContentHeaderProperties properties = message_0_8.getContentHeaderBody().getProperties();
final AMQShortString exchange = message_0_8.getMessagePublishInfo().getExchange();
if (exchange != null) {
deliveryProps.setExchange(exchange.toString());
}
deliveryProps.setExpiration(message_0_8.getExpiration());
if (message_0_8.getExpiration() != 0) {
deliveryProps.setTtl(message_0_8.getExpiration() - message_0_8.getArrivalTime());
}
deliveryProps.setImmediate(message_0_8.isImmediate());
deliveryProps.setDiscardUnroutable(!message_0_8.isMandatory());
deliveryProps.setPriority(MessageDeliveryPriority.get(properties.getPriority()));
deliveryProps.setRoutingKey(message_0_8.getInitialRoutingAddress());
deliveryProps.setTimestamp(properties.getTimestamp());
if (properties.getDeliveryMode() == BasicContentHeaderProperties.PERSISTENT) {
deliveryProps.setDeliveryMode(MessageDeliveryMode.PERSISTENT);
} else {
deliveryProps.setDeliveryMode(MessageDeliveryMode.NON_PERSISTENT);
}
messageProps.setContentEncoding(properties.getEncodingAsString());
messageProps.setContentLength(size);
if (properties.getAppId() != null) {
messageProps.setAppId(properties.getAppId().getBytes());
}
messageProps.setContentType(properties.getContentTypeAsString());
if (properties.getCorrelationId() != null) {
messageProps.setCorrelationId(properties.getCorrelationId().getBytes());
}
if (properties.getReplyTo() != null && properties.getReplyTo().length() != 0) {
String origReplyToString = properties.getReplyTo().toString();
ReplyTo replyTo = new ReplyTo();
// if the string looks like a binding URL, then attempt to parse it...
try {
AMQBindingURL burl = new AMQBindingURL(origReplyToString);
String routingKey = burl.getRoutingKey();
if (routingKey != null) {
replyTo.setRoutingKey(routingKey);
}
String exchangeName = burl.getExchangeName();
if (exchangeName != null && !"".equals(exchangeName)) {
replyTo.setExchange(exchangeName);
}
} catch (URISyntaxException e) {
replyTo.setRoutingKey(origReplyToString);
}
messageProps.setReplyTo(replyTo);
}
if (properties.getMessageId() != null) {
UUID uuid;
String messageIdAsString = properties.getMessageIdAsString();
if (messageIdAsString.startsWith("ID:")) {
messageIdAsString = messageIdAsString.substring(3);
}
try {
uuid = UUID.fromString(messageIdAsString);
} catch (IllegalArgumentException e) {
uuid = UUID.nameUUIDFromBytes(messageIdAsString.getBytes(UTF_8));
}
messageProps.setMessageId(uuid);
}
if (properties.getUserId() != null) {
messageProps.setUserId(properties.getUserId().getBytes());
}
final Map<String, Object> appHeaders = new LinkedHashMap<>(properties.getHeadersAsMap());
if (properties.getType() != null) {
appHeaders.put("x-jms-type", properties.getTypeAsString());
}
messageProps.setApplicationHeaders(appHeaders);
Header header = new Header(deliveryProps, messageProps, null);
return new MessageMetaData_0_10(header, size, message_0_8.getArrivalTime());
}
Aggregations