Search in sources :

Example 16 with ApplicationProperties

use of org.apache.qpid.amqp_1_0.type.messaging.ApplicationProperties in project qpid-broker-j by apache.

the class PropertyConverter_1_0_to_0_8Test method testConversionOfAbsoluteExpiryTimeTakesPrecedenceOverTTL.

public void testConversionOfAbsoluteExpiryTimeTakesPrecedenceOverTTL() {
    long ttl = 10000;
    final long time = System.currentTimeMillis();
    long absoluteExpiryTime = time + ttl;
    long arrivalTime = time + 1;
    Header header = new Header();
    header.setTtl(UnsignedInteger.valueOf(ttl));
    Properties properties = new Properties();
    properties.setAbsoluteExpiryTime(new Date(absoluteExpiryTime));
    Message_1_0 message = createTestMessage(header, new DeliveryAnnotations(Collections.emptyMap()), new MessageAnnotations(Collections.emptyMap()), properties, new ApplicationProperties(Collections.emptyMap()), arrivalTime);
    final AMQMessage convertedMessage = _messageConverter.convert(message, _namedAddressSpace);
    BasicContentHeaderProperties convertedProperties = convertedMessage.getContentHeaderBody().getProperties();
    assertEquals("Unexpected expiration", absoluteExpiryTime, convertedProperties.getExpiration());
}
Also used : Header(org.apache.qpid.server.protocol.v1_0.type.messaging.Header) MessageAnnotations(org.apache.qpid.server.protocol.v1_0.type.messaging.MessageAnnotations) DeliveryAnnotations(org.apache.qpid.server.protocol.v1_0.type.messaging.DeliveryAnnotations) Message_1_0(org.apache.qpid.server.protocol.v1_0.Message_1_0) ApplicationProperties(org.apache.qpid.server.protocol.v1_0.type.messaging.ApplicationProperties) ApplicationProperties(org.apache.qpid.server.protocol.v1_0.type.messaging.ApplicationProperties) BasicContentHeaderProperties(org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties) Properties(org.apache.qpid.server.protocol.v1_0.type.messaging.Properties) BasicContentHeaderProperties(org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties) Date(java.util.Date) AMQMessage(org.apache.qpid.server.protocol.v0_8.AMQMessage)

Example 17 with ApplicationProperties

use of org.apache.qpid.amqp_1_0.type.messaging.ApplicationProperties in project qpid-broker-j by apache.

the class PropertyConverter_1_0_to_0_8Test method testApplicationPropertiesConversionWithDate.

public void testApplicationPropertiesConversionWithDate() {
    Map<String, Object> properties = new HashMap<>();
    final String key = "dateProperty";
    properties.put(key, new Date());
    ApplicationProperties applicationProperties = new ApplicationProperties(properties);
    Message_1_0 message = createTestMessage(applicationProperties);
    final AMQMessage convertedMessage = _messageConverter.convert(message, _namedAddressSpace);
    BasicContentHeaderProperties convertedProperties = convertedMessage.getContentHeaderBody().getProperties();
    final Map<String, Object> headers = FieldTable.convertToMap(convertedProperties.getHeaders());
    assertEquals("Unexpected headers size", properties.size(), headers.size());
    assertEquals("Unexpected headers", properties.get(key), new Date((Long) headers.get(key)));
}
Also used : HashMap(java.util.HashMap) UnsignedLong(org.apache.qpid.server.protocol.v1_0.type.UnsignedLong) ApplicationProperties(org.apache.qpid.server.protocol.v1_0.type.messaging.ApplicationProperties) Message_1_0(org.apache.qpid.server.protocol.v1_0.Message_1_0) Matchers.anyString(org.mockito.Matchers.anyString) AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) BasicContentHeaderProperties(org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties) Date(java.util.Date) AMQMessage(org.apache.qpid.server.protocol.v0_8.AMQMessage)

Example 18 with ApplicationProperties

use of org.apache.qpid.amqp_1_0.type.messaging.ApplicationProperties in project qpid-broker-j by apache.

the class PropertyConverter_v1_0_to_InternalTest method testApplicationPropertiesConversion.

public void testApplicationPropertiesConversion() {
    Map<String, Object> properties = new HashMap<>();
    properties.put("testProperty1", "testProperty1Value");
    properties.put("intProperty", 1);
    properties.put("nullProperty", null);
    ApplicationProperties applicationProperties = new ApplicationProperties(properties);
    Message_1_0 originalMessage = createTestMessage(applicationProperties);
    final InternalMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
    final Map<String, Object> headers = convertedMessage.getMessageHeader().getHeaderMap();
    assertEquals("Unexpected headers", properties, new HashMap<>(headers));
}
Also used : InternalMessage(org.apache.qpid.server.message.internal.InternalMessage) HashMap(java.util.HashMap) ApplicationProperties(org.apache.qpid.server.protocol.v1_0.type.messaging.ApplicationProperties)

Example 19 with ApplicationProperties

use of org.apache.qpid.amqp_1_0.type.messaging.ApplicationProperties in project qpid-broker-j by apache.

the class MessageConverter_0_10_to_1_0 method convertMetaData.

@Override
protected MessageMetaData_1_0 convertMetaData(MessageTransferMessage serverMessage, final EncodingRetainingSection<?> bodySection, SectionEncoder sectionEncoder) {
    Properties props = new Properties();
    props.setCreationTime(new Date(serverMessage.getArrivalTime()));
    final MessageProperties msgProps = serverMessage.getHeader().getMessageProperties();
    final DeliveryProperties deliveryProps = serverMessage.getHeader().getDeliveryProperties();
    Header header = new Header();
    if (deliveryProps != null) {
        header.setDurable(deliveryProps.hasDeliveryMode() && deliveryProps.getDeliveryMode() == MessageDeliveryMode.PERSISTENT);
        if (deliveryProps.hasPriority()) {
            header.setPriority(UnsignedByte.valueOf((byte) deliveryProps.getPriority().getValue()));
        }
        if (deliveryProps.hasTtl()) {
            header.setTtl(UnsignedInteger.valueOf(deliveryProps.getTtl()));
        } else if (deliveryProps.hasExpiration()) {
            long ttl = Math.max(0, deliveryProps.getExpiration() - serverMessage.getArrivalTime());
            header.setTtl(UnsignedInteger.valueOf(ttl));
        }
        if (deliveryProps.hasTimestamp()) {
            props.setCreationTime(new Date(deliveryProps.getTimestamp()));
        }
        String to = deliveryProps.getExchange();
        if (deliveryProps.getRoutingKey() != null) {
            String routingKey = deliveryProps.getRoutingKey();
            if (to != null && !"".equals(to)) {
                to += "/" + routingKey;
            } else {
                to = routingKey;
            }
        }
        props.setTo(to);
    }
    ApplicationProperties applicationProperties = null;
    String originalContentMimeType = null;
    if (msgProps != null) {
        if (msgProps.hasContentEncoding() && !GZIPUtils.GZIP_CONTENT_ENCODING.equals(msgProps.getContentEncoding()) && bodySection instanceof DataSection) {
            props.setContentEncoding(Symbol.valueOf(msgProps.getContentEncoding()));
        }
        if (msgProps.hasCorrelationId()) {
            CharsetDecoder charsetDecoder = StandardCharsets.UTF_8.newDecoder().onMalformedInput(CodingErrorAction.REPORT).onUnmappableCharacter(CodingErrorAction.REPORT);
            try {
                String correlationIdAsString = charsetDecoder.decode(ByteBuffer.wrap(msgProps.getCorrelationId())).toString();
                props.setCorrelationId(correlationIdAsString);
            } catch (CharacterCodingException e) {
                props.setCorrelationId(new Binary(msgProps.getCorrelationId()));
            }
        }
        if (msgProps.hasMessageId()) {
            props.setMessageId(msgProps.getMessageId());
        }
        if (msgProps.hasReplyTo()) {
            ReplyTo replyTo = msgProps.getReplyTo();
            String to = null;
            if (replyTo.hasExchange() && !"".equals(replyTo.getExchange())) {
                to = replyTo.getExchange();
            }
            if (replyTo.hasRoutingKey()) {
                if (to != null) {
                    to += "/" + replyTo.getRoutingKey();
                } else {
                    to = replyTo.getRoutingKey();
                }
            }
            props.setReplyTo(to);
        }
        if (msgProps.hasContentType()) {
            originalContentMimeType = msgProps.getContentType();
            final Symbol contentType = MessageConverter_to_1_0.getContentType(originalContentMimeType);
            props.setContentType(contentType);
        }
        if (msgProps.hasUserId()) {
            props.setUserId(new Binary(msgProps.getUserId()));
        }
        Map<String, Object> applicationPropertiesMap = msgProps.getApplicationHeaders();
        if (applicationPropertiesMap != null) {
            applicationPropertiesMap = new LinkedHashMap<>(applicationPropertiesMap);
            if (applicationPropertiesMap.containsKey("x-jms-type")) {
                props.setSubject(String.valueOf(applicationPropertiesMap.get("x-jms-type")));
                applicationPropertiesMap.remove("x-jms-type");
            }
            if (applicationPropertiesMap.containsKey("qpid.subject")) {
                props.setSubject(String.valueOf(applicationPropertiesMap.get("qpid.subject")));
                applicationPropertiesMap.remove("qpid.subject");
            }
            if (applicationPropertiesMap.containsKey("JMSXGroupID")) {
                props.setGroupId(String.valueOf(applicationPropertiesMap.get("JMSXGroupID")));
                applicationPropertiesMap.remove("JMSXGroupID");
            }
            if (applicationPropertiesMap.containsKey("JMSXGroupSeq")) {
                Object jmsxGroupSeq = applicationPropertiesMap.get("JMSXGroupSeq");
                if (jmsxGroupSeq instanceof Integer) {
                    props.setGroupSequence(UnsignedInteger.valueOf((Integer) jmsxGroupSeq));
                    applicationPropertiesMap.remove("JMSXGroupSeq");
                }
            }
            try {
                applicationProperties = new ApplicationProperties(applicationPropertiesMap);
            } catch (IllegalArgumentException e) {
                throw new MessageConversionException("Could not convert message from 0-10 to 1.0 because application headers conversion failed.", e);
            }
        }
    }
    final MessageAnnotations messageAnnotation = MessageConverter_to_1_0.createMessageAnnotation(bodySection, originalContentMimeType);
    return new MessageMetaData_1_0(header.createEncodingRetainingSection(), null, messageAnnotation == null ? null : messageAnnotation.createEncodingRetainingSection(), props.createEncodingRetainingSection(), applicationProperties == null ? null : applicationProperties.createEncodingRetainingSection(), null, serverMessage.getArrivalTime(), bodySection.getEncodedSize());
}
Also used : CharsetDecoder(java.nio.charset.CharsetDecoder) MessageConversionException(org.apache.qpid.server.protocol.converter.MessageConversionException) Symbol(org.apache.qpid.server.protocol.v1_0.type.Symbol) MessageMetaData_1_0(org.apache.qpid.server.protocol.v1_0.MessageMetaData_1_0) DeliveryProperties(org.apache.qpid.server.protocol.v0_10.transport.DeliveryProperties) CharacterCodingException(java.nio.charset.CharacterCodingException) 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) Date(java.util.Date) ReplyTo(org.apache.qpid.server.protocol.v0_10.transport.ReplyTo) UnsignedInteger(org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger) Header(org.apache.qpid.server.protocol.v1_0.type.messaging.Header) DataSection(org.apache.qpid.server.protocol.v1_0.type.messaging.DataSection) MessageProperties(org.apache.qpid.server.protocol.v0_10.transport.MessageProperties) MessageAnnotations(org.apache.qpid.server.protocol.v1_0.type.messaging.MessageAnnotations) ApplicationProperties(org.apache.qpid.server.protocol.v1_0.type.messaging.ApplicationProperties) Binary(org.apache.qpid.server.protocol.v1_0.type.Binary)

Example 20 with ApplicationProperties

use of org.apache.qpid.amqp_1_0.type.messaging.ApplicationProperties in project qpid-broker-j by apache.

the class PropertyConverter_1_0_to_0_10Test method testGroupSequenceDoesNotReplaceApplicationPropertiesJMSXGroupSeq.

public void testGroupSequenceDoesNotReplaceApplicationPropertiesJMSXGroupSeq() {
    int testGroupSequence = 1;
    Properties properties = new Properties();
    properties.setGroupSequence(UnsignedInteger.valueOf(testGroupSequence));
    final int JMSXGroupSeq = 2;
    Map<String, Object> applicationPropertiesMap = Collections.singletonMap("JMSXGroupSeq", JMSXGroupSeq);
    ApplicationProperties applicationProperties = new ApplicationProperties(applicationPropertiesMap);
    Message_1_0 message = createTestMessage(new Header(), new DeliveryAnnotations(Collections.emptyMap()), new MessageAnnotations(Collections.emptyMap()), properties, applicationProperties, 0, null);
    final MessageTransferMessage convertedMessage = _messageConverter.convert(message, _namedAddressSpace);
    final MessageProperties messageProperties = convertedMessage.getStoredMessage().getMetaData().getMessageProperties();
    final Map<String, Object> applicationHeaders = messageProperties.getApplicationHeaders();
    assertEquals("Unexpected JMSXGroupSeq", JMSXGroupSeq, applicationHeaders.get("JMSXGroupSeq"));
}
Also used : Header(org.apache.qpid.server.protocol.v1_0.type.messaging.Header) MessageTransferMessage(org.apache.qpid.server.protocol.v0_10.MessageTransferMessage) MessageProperties(org.apache.qpid.server.protocol.v0_10.transport.MessageProperties) MessageAnnotations(org.apache.qpid.server.protocol.v1_0.type.messaging.MessageAnnotations) DeliveryAnnotations(org.apache.qpid.server.protocol.v1_0.type.messaging.DeliveryAnnotations) ApplicationProperties(org.apache.qpid.server.protocol.v1_0.type.messaging.ApplicationProperties) Message_1_0(org.apache.qpid.server.protocol.v1_0.Message_1_0) Matchers.anyString(org.mockito.Matchers.anyString) 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)

Aggregations

ApplicationProperties (org.apache.qpid.server.protocol.v1_0.type.messaging.ApplicationProperties)21 Message_1_0 (org.apache.qpid.server.protocol.v1_0.Message_1_0)15 MessageAnnotations (org.apache.qpid.server.protocol.v1_0.type.messaging.MessageAnnotations)13 Properties (org.apache.qpid.server.protocol.v1_0.type.messaging.Properties)13 Header (org.apache.qpid.server.protocol.v1_0.type.messaging.Header)12 DeliveryAnnotations (org.apache.qpid.server.protocol.v1_0.type.messaging.DeliveryAnnotations)10 Matchers.anyString (org.mockito.Matchers.anyString)10 MessageProperties (org.apache.qpid.server.protocol.v0_10.transport.MessageProperties)9 Date (java.util.Date)8 MessageTransferMessage (org.apache.qpid.server.protocol.v0_10.MessageTransferMessage)8 DeliveryProperties (org.apache.qpid.server.protocol.v0_10.transport.DeliveryProperties)8 HashMap (java.util.HashMap)7 BasicContentHeaderProperties (org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties)6 MessageConversionException (org.apache.qpid.server.protocol.converter.MessageConversionException)5 AMQMessage (org.apache.qpid.server.protocol.v0_8.AMQMessage)5 AMQShortString (org.apache.qpid.server.protocol.v0_8.AMQShortString)5 ArrayList (java.util.ArrayList)3 Binary (org.apache.qpid.server.protocol.v1_0.type.Binary)3 Symbol (org.apache.qpid.server.protocol.v1_0.type.Symbol)3 Map (java.util.Map)2