Search in sources :

Example 86 with MessageProperties

use of org.apache.qpid.server.protocol.v0_10.transport.MessageProperties in project qpid-broker-j by apache.

the class PropertyConverter_1_0_to_0_10Test method testCorrelationIdBinaryConversion.

public void testCorrelationIdBinaryConversion() {
    final String testCorrelationId = "testCorrelationId";
    final Binary correlationId = new Binary(testCorrelationId.getBytes(UTF_8));
    Properties properties = new Properties();
    properties.setCorrelationId(correlationId);
    Message_1_0 message = createTestMessage(properties);
    final MessageTransferMessage convertedMessage = _messageConverter.convert(message, _namedAddressSpace);
    final MessageProperties messageProperties = convertedMessage.getStoredMessage().getMetaData().getMessageProperties();
    assertTrue("Unexpected correlationId", Arrays.equals(testCorrelationId.getBytes(), messageProperties.getCorrelationId()));
}
Also used : MessageTransferMessage(org.apache.qpid.server.protocol.v0_10.MessageTransferMessage) MessageProperties(org.apache.qpid.server.protocol.v0_10.transport.MessageProperties) Message_1_0(org.apache.qpid.server.protocol.v1_0.Message_1_0) Matchers.anyString(org.mockito.Matchers.anyString) Binary(org.apache.qpid.server.protocol.v1_0.type.Binary) ApplicationProperties(org.apache.qpid.server.protocol.v1_0.type.messaging.ApplicationProperties) Properties(org.apache.qpid.server.protocol.v1_0.type.messaging.Properties) DeliveryProperties(org.apache.qpid.server.protocol.v0_10.transport.DeliveryProperties) MessageProperties(org.apache.qpid.server.protocol.v0_10.transport.MessageProperties)

Example 87 with MessageProperties

use of org.apache.qpid.server.protocol.v0_10.transport.MessageProperties in project qpid-broker-j by apache.

the class PropertyConverter_1_0_to_0_10Test method testMessageIdUUIDConversion.

public void testMessageIdUUIDConversion() {
    final UUID messageId = UUID.randomUUID();
    Properties properties = new Properties();
    properties.setMessageId(messageId);
    Message_1_0 message = createTestMessage(properties);
    final MessageTransferMessage convertedMessage = _messageConverter.convert(message, _namedAddressSpace);
    final MessageProperties messageProperties = convertedMessage.getStoredMessage().getMetaData().getMessageProperties();
    assertEquals("Unexpected messageId", messageId, messageProperties.getMessageId());
}
Also used : MessageTransferMessage(org.apache.qpid.server.protocol.v0_10.MessageTransferMessage) MessageProperties(org.apache.qpid.server.protocol.v0_10.transport.MessageProperties) Message_1_0(org.apache.qpid.server.protocol.v1_0.Message_1_0) UUID(java.util.UUID) ApplicationProperties(org.apache.qpid.server.protocol.v1_0.type.messaging.ApplicationProperties) Properties(org.apache.qpid.server.protocol.v1_0.type.messaging.Properties) DeliveryProperties(org.apache.qpid.server.protocol.v0_10.transport.DeliveryProperties) MessageProperties(org.apache.qpid.server.protocol.v0_10.transport.MessageProperties)

Example 88 with MessageProperties

use of org.apache.qpid.server.protocol.v0_10.transport.MessageProperties in project qpid-broker-j by apache.

the class MessageConverter_0_10_to_0_8 method convertContentHeaderProperties.

public static BasicContentHeaderProperties convertContentHeaderProperties(MessageTransferMessage messageTransferMessage, NamedAddressSpace addressSpace) {
    BasicContentHeaderProperties props = new BasicContentHeaderProperties();
    Header header = messageTransferMessage.getHeader();
    DeliveryProperties deliveryProps = header.getDeliveryProperties();
    MessageProperties messageProps = header.getMessageProperties();
    if (deliveryProps != null) {
        if (deliveryProps.hasDeliveryMode()) {
            props.setDeliveryMode((deliveryProps.getDeliveryMode() == MessageDeliveryMode.PERSISTENT ? BasicContentHeaderProperties.PERSISTENT : BasicContentHeaderProperties.NON_PERSISTENT));
        }
        if (deliveryProps.hasTtl()) {
            props.setExpiration(messageTransferMessage.getArrivalTime() + deliveryProps.getTtl());
        } else if (deliveryProps.hasExpiration()) {
            props.setExpiration(deliveryProps.getExpiration());
        }
        if (deliveryProps.hasPriority()) {
            props.setPriority((byte) deliveryProps.getPriority().getValue());
        }
        if (deliveryProps.hasTimestamp()) {
            props.setTimestamp(deliveryProps.getTimestamp());
        } else {
            props.setTimestamp(messageTransferMessage.getArrivalTime());
        }
    }
    if (messageProps != null) {
        if (messageProps.hasAppId()) {
            try {
                props.setAppId(new AMQShortString(messageProps.getAppId()));
            } catch (IllegalArgumentException e) {
            // pass
            }
        }
        if (messageProps.hasContentType()) {
            props.setContentType(messageProps.getContentType());
        }
        if (messageProps.hasCorrelationId()) {
            try {
                props.setCorrelationId(new AMQShortString(messageProps.getCorrelationId()));
            } catch (IllegalArgumentException e) {
                throw new MessageConversionException("Could not convert message from 0-10 to 0-8 because conversion of 'correlationId' failed.", e);
            }
        }
        if (messageProps.hasContentEncoding()) {
            props.setEncoding(messageProps.getContentEncoding());
        }
        if (messageProps.hasMessageId()) {
            // Add prefix 'ID:' to workaround broken 0-8..0-9-1 Qpid JMS client
            props.setMessageId("ID:" + messageProps.getMessageId().toString());
        }
        if (messageProps.hasReplyTo()) {
            ReplyTo replyTo = messageProps.getReplyTo();
            String exchangeName = replyTo.getExchange();
            String routingKey = replyTo.getRoutingKey();
            if (exchangeName == null) {
                exchangeName = "";
            }
            if (!"".equals(exchangeName) || (routingKey != null && !"".equals(routingKey))) {
                MessageDestination destination = addressSpace.getAttainedMessageDestination(exchangeName);
                Exchange<?> exchange = destination instanceof Exchange ? (Exchange<?>) destination : null;
                String exchangeClass = exchange == null ? ExchangeDefaults.DIRECT_EXCHANGE_CLASS : exchange.getType();
                String routingKeyOption = routingKey == null ? "" : "?routingkey='" + routingKey + "'";
                final String replyToBindingUrl = String.format("%s://%s//%s", exchangeClass, exchangeName, routingKeyOption);
                try {
                    props.setReplyTo(replyToBindingUrl);
                } catch (IllegalArgumentException e) {
                    throw new MessageConversionException("Could not convert message from 0-10 to 0-8 because conversion of 'reply-to' failed.", e);
                }
            }
        }
        if (messageProps.hasUserId()) {
            try {
                props.setUserId(new AMQShortString(messageProps.getUserId()));
            } catch (IllegalArgumentException e) {
            // ignore
            }
        }
        if (messageProps.hasApplicationHeaders()) {
            Map<String, Object> appHeaders = new HashMap<String, Object>(messageProps.getApplicationHeaders());
            if (messageProps.getApplicationHeaders().containsKey("x-jms-type")) {
                String jmsType = String.valueOf(appHeaders.remove("x-jms-type"));
                try {
                    props.setType(jmsType);
                } catch (IllegalArgumentException e) {
                    throw new MessageConversionException("Could not convert message from 0-10 to 0-8 because x-jms-type conversion failed.", e);
                }
            }
            FieldTable ft = new FieldTable();
            for (Map.Entry<String, Object> entry : appHeaders.entrySet()) {
                String headerName = entry.getKey();
                try {
                    ft.put(AMQShortString.validValueOf(headerName), entry.getValue());
                } catch (AMQPInvalidClassException e) {
                    throw new MessageConversionException(String.format("Could not convert message from 0-10 to 0-8 because conversion of application header '%s' failed.", headerName), e);
                }
            }
            props.setHeaders(ft);
        }
    }
    return props;
}
Also used : AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) MessageConversionException(org.apache.qpid.server.protocol.converter.MessageConversionException) MessageDestination(org.apache.qpid.server.message.MessageDestination) AMQPInvalidClassException(org.apache.qpid.server.protocol.v0_8.AMQPInvalidClassException) FieldTable(org.apache.qpid.server.protocol.v0_8.FieldTable) HashMap(java.util.HashMap) DeliveryProperties(org.apache.qpid.server.protocol.v0_10.transport.DeliveryProperties) AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) BasicContentHeaderProperties(org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties) ReplyTo(org.apache.qpid.server.protocol.v0_10.transport.ReplyTo) Exchange(org.apache.qpid.server.model.Exchange) Header(org.apache.qpid.server.protocol.v0_10.transport.Header) MessageProperties(org.apache.qpid.server.protocol.v0_10.transport.MessageProperties) HashMap(java.util.HashMap) Map(java.util.Map)

Example 89 with MessageProperties

use of org.apache.qpid.server.protocol.v0_10.transport.MessageProperties in project qpid-broker-j by apache.

the class PropertyConverter_0_10_to_0_8Test method testApplicationHeadersConversionWhenQpidSubjectIsPresent.

public void testApplicationHeadersConversionWhenQpidSubjectIsPresent() {
    String testSubject = "testSubject";
    Map<String, Object> headers = new HashMap<>();
    headers.put("qpid.subject", testSubject);
    final MessageProperties messageProperties = new MessageProperties();
    messageProperties.setApplicationHeaders(headers);
    MessageTransferMessage message = createTestMessage(messageProperties);
    final AMQMessage convertedMessage = _messageConverter.convert(message, _namedAddressSpace);
    BasicContentHeaderProperties properties = convertedMessage.getContentHeaderBody().getProperties();
    Map<String, Object> applicationProperties = FieldTable.convertToMap(properties.getHeaders());
    assertEquals("Unexpected subject in application properties", testSubject, applicationProperties.get("qpid.subject"));
}
Also used : HashMap(java.util.HashMap) MessageProperties(org.apache.qpid.server.protocol.v0_10.transport.MessageProperties) MessageTransferMessage(org.apache.qpid.server.protocol.v0_10.MessageTransferMessage) AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) BasicContentHeaderProperties(org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties) AMQMessage(org.apache.qpid.server.protocol.v0_8.AMQMessage)

Example 90 with MessageProperties

use of org.apache.qpid.server.protocol.v0_10.transport.MessageProperties in project qpid-broker-j by apache.

the class PropertyConverter_0_10_to_0_8Test method testJmsTypeConversion.

public void testJmsTypeConversion() {
    final String type = "test-type";
    final Map<String, Object> headers = Collections.singletonMap("x-jms-type", type);
    final MessageProperties messageProperties = new MessageProperties();
    messageProperties.setApplicationHeaders(headers);
    MessageTransferMessage message = createTestMessage(messageProperties);
    final AMQMessage convertedMessage = _messageConverter.convert(message, _namedAddressSpace);
    BasicContentHeaderProperties properties = convertedMessage.getContentHeaderBody().getProperties();
    assertEquals("Unexpected subject", type, properties.getType().toString());
    Map<String, Object> applicationProperties = FieldTable.convertToMap(properties.getHeaders());
    assertFalse("Unexpected x-jms-type in application properties", applicationProperties.containsKey("x-jms-type"));
}
Also used : MessageProperties(org.apache.qpid.server.protocol.v0_10.transport.MessageProperties) MessageTransferMessage(org.apache.qpid.server.protocol.v0_10.MessageTransferMessage) AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) BasicContentHeaderProperties(org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties) AMQMessage(org.apache.qpid.server.protocol.v0_8.AMQMessage)

Aggregations

MessageProperties (org.apache.qpid.server.protocol.v0_10.transport.MessageProperties)121 MessageTransferMessage (org.apache.qpid.server.protocol.v0_10.MessageTransferMessage)90 DeliveryProperties (org.apache.qpid.server.protocol.v0_10.transport.DeliveryProperties)63 Message_1_0 (org.apache.qpid.server.protocol.v1_0.Message_1_0)45 Properties (org.apache.qpid.server.protocol.v1_0.type.messaging.Properties)44 BasicContentHeaderProperties (org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties)39 AMQMessage (org.apache.qpid.server.protocol.v0_8.AMQMessage)37 AMQShortString (org.apache.qpid.server.protocol.v0_8.AMQShortString)31 ApplicationProperties (org.apache.qpid.server.protocol.v1_0.type.messaging.ApplicationProperties)24 ReplyTo (org.apache.qpid.server.protocol.v0_10.transport.ReplyTo)20 InternalMessage (org.apache.qpid.server.message.internal.InternalMessage)18 Matchers.anyString (org.mockito.Matchers.anyString)15 HashMap (java.util.HashMap)10 UUID (java.util.UUID)10 Header (org.apache.qpid.server.protocol.v0_10.transport.Header)10 Header (org.apache.qpid.server.protocol.v1_0.type.messaging.Header)9 MessageConversionException (org.apache.qpid.server.protocol.converter.MessageConversionException)8 Binary (org.apache.qpid.server.protocol.v1_0.type.Binary)7 MessageAnnotations (org.apache.qpid.server.protocol.v1_0.type.messaging.MessageAnnotations)6 DeliveryAnnotations (org.apache.qpid.server.protocol.v1_0.type.messaging.DeliveryAnnotations)5