Search in sources :

Example 96 with MessageTransferMessage

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());
}
Also used : ReplyTo(org.apache.qpid.server.protocol.v0_10.transport.ReplyTo) InternalMessage(org.apache.qpid.server.message.internal.InternalMessage) AMQMessageHeader(org.apache.qpid.server.message.AMQMessageHeader) Matchers.anyString(org.mockito.Matchers.anyString) AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString)

Example 97 with MessageTransferMessage

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());
}
Also used : InternalMessage(org.apache.qpid.server.message.internal.InternalMessage) Matchers.anyString(org.mockito.Matchers.anyString) AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) DeliveryProperties(org.apache.qpid.server.protocol.v0_10.transport.DeliveryProperties)

Example 98 with MessageTransferMessage

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);
}
Also used : ReplyTo(org.apache.qpid.server.protocol.v0_10.transport.ReplyTo) HashMap(java.util.HashMap) MessageProperties(org.apache.qpid.server.protocol.v0_10.transport.MessageProperties) InternalMessageHeader(org.apache.qpid.server.message.internal.InternalMessageHeader) AMQMessageHeader(org.apache.qpid.server.message.AMQMessageHeader)

Example 99 with MessageTransferMessage

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);
    }
}
Also used : DeliveryProperties(org.apache.qpid.server.protocol.v0_10.transport.DeliveryProperties) Struct(org.apache.qpid.server.protocol.v0_10.transport.Struct) Header(org.apache.qpid.server.protocol.v0_10.transport.Header) MessageProperties(org.apache.qpid.server.protocol.v0_10.transport.MessageProperties) ConnectionScopedRuntimeException(org.apache.qpid.server.util.ConnectionScopedRuntimeException) BufferUnderflowException(java.nio.BufferUnderflowException)

Example 100 with MessageTransferMessage

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);
    }
}
Also used : QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) Struct(org.apache.qpid.server.protocol.v0_10.transport.Struct)

Aggregations

MessageTransferMessage (org.apache.qpid.server.protocol.v0_10.MessageTransferMessage)182 MessageProperties (org.apache.qpid.server.protocol.v0_10.transport.MessageProperties)128 Message_1_0 (org.apache.qpid.server.protocol.v1_0.Message_1_0)116 DeliveryProperties (org.apache.qpid.server.protocol.v0_10.transport.DeliveryProperties)115 Properties (org.apache.qpid.server.protocol.v1_0.type.messaging.Properties)80 AMQMessage (org.apache.qpid.server.protocol.v0_8.AMQMessage)58 ApplicationProperties (org.apache.qpid.server.protocol.v1_0.type.messaging.ApplicationProperties)58 BasicContentHeaderProperties (org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties)53 NamedAddressSpace (org.apache.qpid.server.model.NamedAddressSpace)46 AMQShortString (org.apache.qpid.server.protocol.v0_8.AMQShortString)45 Matchers.anyString (org.mockito.Matchers.anyString)37 InternalMessage (org.apache.qpid.server.message.internal.InternalMessage)34 QpidByteBuffer (org.apache.qpid.server.bytebuffer.QpidByteBuffer)31 ReplyTo (org.apache.qpid.server.protocol.v0_10.transport.ReplyTo)28 Binary (org.apache.qpid.server.protocol.v1_0.type.Binary)23 Header (org.apache.qpid.server.protocol.v1_0.type.messaging.Header)19 AmqpValue (org.apache.qpid.server.protocol.v1_0.type.messaging.AmqpValue)17 Data (org.apache.qpid.server.protocol.v1_0.type.messaging.Data)14 HashMap (java.util.HashMap)13 MessageAnnotations (org.apache.qpid.server.protocol.v1_0.type.messaging.MessageAnnotations)10