use of org.apache.qpid.server.protocol.v0_10.MessageTransferMessage in project qpid-broker-j by apache.
the class PropertyConverter_Internal_to_v0_10Test method testReplyToConversionWhenReplyToCannotBeResolved.
public void testReplyToConversionWhenReplyToCannotBeResolved() throws IOException {
final AMQMessageHeader header = mock(AMQMessageHeader.class);
final String replyTo = "direct://amq.direct//test?routingkey='test'";
when(header.getReplyTo()).thenReturn(replyTo);
InternalMessage originalMessage = createTestMessage(header);
MessageTransferMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
final ReplyTo convertedReplyTo = convertedMessage.getHeader().getMessageProperties().getReplyTo();
assertEquals("Unexpected exchange", "", convertedReplyTo.getExchange());
assertEquals("Unexpected routing key", replyTo, convertedReplyTo.getRoutingKey());
}
use of org.apache.qpid.server.protocol.v0_10.MessageTransferMessage in project qpid-broker-j by apache.
the class PropertyConverter_Internal_to_v0_10Test method testToConversionWhenDestinationIsSpecifiedButDoesNotExists.
public void testToConversionWhenDestinationIsSpecifiedButDoesNotExists() throws IOException {
final String testDestination = "testDestination";
InternalMessage message = createTestMessage(testDestination);
final MessageTransferMessage convertedMessage = _messageConverter.convert(message, _addressSpace);
final DeliveryProperties deliveryProperties = convertedMessage.getStoredMessage().getMetaData().getDeliveryProperties();
assertEquals("Unexpected exchange", "", deliveryProperties.getExchange());
assertEquals("Unexpected routing key", testDestination, deliveryProperties.getRoutingKey());
}
use of org.apache.qpid.server.protocol.v0_10.MessageTransferMessage in project qpid-broker-j by apache.
the class MessageConverter_v0_10_to_Internal method convertHeader.
private AMQMessageHeader convertHeader(final MessageTransferMessage serverMessage, final NamedAddressSpace addressSpace, final Object convertedBodyObject, final String encoding) {
final String convertedMimeType = getInternalConvertedMimeType(serverMessage, convertedBodyObject);
final AMQMessageHeader messageHeader = serverMessage.getMessageHeader();
Map<String, Object> headers = new HashMap<>();
messageHeader.getHeaderNames().forEach(headerName -> headers.put(headerName, messageHeader.getHeader(headerName)));
final InternalMessageHeader header = new InternalMessageHeader(headers, messageHeader.getCorrelationId(), messageHeader.getExpiration(), messageHeader.getUserId(), messageHeader.getAppId(), messageHeader.getMessageId(), convertedMimeType, messageHeader.getEncoding(), messageHeader.getPriority(), messageHeader.getTimestamp(), messageHeader.getNotValidBefore(), messageHeader.getType(), messageHeader.getReplyTo(), serverMessage.getArrivalTime());
MessageProperties messageProps = serverMessage.getHeader().getMessageProperties();
final ReplyTo replyTo = messageProps == null ? null : messageProps.getReplyTo();
return new DelegatingMessageHeader(header, replyTo, encoding);
}
use of org.apache.qpid.server.protocol.v0_10.MessageTransferMessage in project qpid-broker-j by apache.
the class MessageFormat_0_10 method createMessage.
@Override
public MessageTransferMessage createMessage(final QpidByteBuffer payload, final MessageStore store, final Object connectionReference) {
try {
ServerDecoder serverDecoder = new ServerDecoder(payload);
int headerCount = serverDecoder.readInt32();
DeliveryProperties deliveryProperties = null;
MessageProperties messageProperties = null;
List<Struct> nonStandard = null;
for (int i = 0; i < headerCount; i++) {
final Struct struct = serverDecoder.readStruct32();
switch(struct.getStructType()) {
case DeliveryProperties.TYPE:
deliveryProperties = (DeliveryProperties) struct;
break;
case MessageProperties.TYPE:
messageProperties = (MessageProperties) struct;
break;
default:
if (nonStandard == null) {
nonStandard = new ArrayList<>();
}
nonStandard.add(struct);
}
}
Header header = new Header(deliveryProperties, messageProperties, nonStandard);
MessageMetaData_0_10 metaData = new MessageMetaData_0_10(header, payload.remaining(), System.currentTimeMillis());
final MessageHandle<MessageMetaData_0_10> handle = store.addMessage(metaData);
handle.addContent(payload);
final StoredMessage<MessageMetaData_0_10> storedMessage = handle.allContentAdded();
return new MessageTransferMessage(storedMessage, connectionReference);
} catch (BufferUnderflowException e) {
throw new ConnectionScopedRuntimeException("Error parsing AMQP 0-10 message format", e);
}
}
use of org.apache.qpid.server.protocol.v0_10.MessageTransferMessage in project qpid-broker-j by apache.
the class MessageFormat_0_10 method convertToMessageFormat.
// format: <int header count> <headers> <body>
@Override
public QpidByteBuffer convertToMessageFormat(final MessageTransferMessage message) {
ServerEncoder encoder = new ServerEncoder(4096, true);
Struct[] structs = message.getHeader().getStructs();
encoder.writeInt32(structs.length);
for (Struct struct : structs) {
encoder.writeStruct32(struct);
}
try (QpidByteBuffer headerBuf = encoder.getBuffer();
QpidByteBuffer content = message.getContent()) {
return QpidByteBuffer.concatenate(headerBuf, content);
}
}
Aggregations