Search in sources :

Example 31 with DeliveryProperties

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

the class PropertyConverter_0_10_to_InternalTest method testPersistentDeliveryModeConversion.

public void testPersistentDeliveryModeConversion() {
    MessageDeliveryMode deliveryMode = MessageDeliveryMode.PERSISTENT;
    final DeliveryProperties deliveryProperties = new DeliveryProperties();
    deliveryProperties.setDeliveryMode(deliveryMode);
    MessageTransferMessage message = createTestMessage(deliveryProperties);
    final InternalMessage convertedMessage = _messageConverter.convert(message, _namedAddressSpace);
    assertTrue("Unexpected persistence", convertedMessage.isPersistent());
    assertTrue("Unexpected persistence of meta data", convertedMessage.getStoredMessage().getMetaData().isPersistent());
}
Also used : InternalMessage(org.apache.qpid.server.message.internal.InternalMessage) DeliveryProperties(org.apache.qpid.server.protocol.v0_10.transport.DeliveryProperties) MessageDeliveryMode(org.apache.qpid.server.protocol.v0_10.transport.MessageDeliveryMode)

Example 32 with DeliveryProperties

use of org.apache.qpid.server.protocol.v0_10.transport.DeliveryProperties 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 33 with DeliveryProperties

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

the class MessageConverter_Internal_to_v0_10 method convertMetaData.

private MessageMetaData_0_10 convertMetaData(final InternalMessage serverMsg, final NamedAddressSpace addressSpace, final String bodyMimeType, final int size) {
    DeliveryProperties deliveryProps = new DeliveryProperties();
    MessageProperties messageProps = new MessageProperties();
    deliveryProps.setDeliveryMode(serverMsg.isPersistent() ? MessageDeliveryMode.PERSISTENT : MessageDeliveryMode.NON_PERSISTENT);
    long expiration = serverMsg.getExpiration();
    if (expiration > 0) {
        deliveryProps.setExpiration(expiration);
        deliveryProps.setTtl(Math.max(0, expiration - serverMsg.getArrivalTime()));
    }
    InternalMessageHeader messageHeader = serverMsg.getMessageHeader();
    deliveryProps.setPriority(MessageDeliveryPriority.get(messageHeader.getPriority()));
    convertToAndInitialRoutingKey(serverMsg, deliveryProps, addressSpace);
    deliveryProps.setTimestamp(messageHeader.getTimestamp());
    messageProps.setContentEncoding(ensureStr8("content-encoding", messageHeader.getEncoding()));
    messageProps.setContentLength(size);
    messageProps.setContentType(bodyMimeType);
    if (messageHeader.getCorrelationId() != null) {
        messageProps.setCorrelationId(ensureVBin16("correlation-id", messageHeader.getCorrelationId().getBytes(UTF_8)));
    }
    validateValue(messageHeader.getHeaderMap(), "application-headers");
    messageProps.setApplicationHeaders(messageHeader.getHeaderMap());
    String messageIdAsString = messageHeader.getMessageId();
    if (messageIdAsString != null) {
        try {
            if (messageIdAsString.startsWith("ID:")) {
                messageIdAsString = messageIdAsString.substring(3);
            }
            messageProps.setMessageId(UUID.fromString(messageIdAsString));
        } catch (IllegalArgumentException iae) {
        // ignore message id is not a UUID
        }
    }
    String userId = messageHeader.getUserId();
    if (userId != null) {
        byte[] bytes = userId.getBytes(UTF_8);
        if (bytes.length <= MAX_VBIN16_LENGTH) {
            messageProps.setUserId(bytes);
        }
    }
    final String origReplyTo = messageHeader.getReplyTo();
    if (origReplyTo != null && !origReplyTo.equals("")) {
        messageProps.setReplyTo(getReplyTo(addressSpace, origReplyTo));
    }
    Header header = new Header(deliveryProps, messageProps, null);
    return new MessageMetaData_0_10(header, size, serverMsg.getArrivalTime());
}
Also used : Header(org.apache.qpid.server.protocol.v0_10.transport.Header) InternalMessageHeader(org.apache.qpid.server.message.internal.InternalMessageHeader) MessageProperties(org.apache.qpid.server.protocol.v0_10.transport.MessageProperties) InternalMessageHeader(org.apache.qpid.server.message.internal.InternalMessageHeader) DeliveryProperties(org.apache.qpid.server.protocol.v0_10.transport.DeliveryProperties)

Example 34 with DeliveryProperties

use of org.apache.qpid.server.protocol.v0_10.transport.DeliveryProperties 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 35 with DeliveryProperties

use of org.apache.qpid.server.protocol.v0_10.transport.DeliveryProperties 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)

Aggregations

DeliveryProperties (org.apache.qpid.server.protocol.v0_10.transport.DeliveryProperties)81 MessageTransferMessage (org.apache.qpid.server.protocol.v0_10.MessageTransferMessage)54 MessageProperties (org.apache.qpid.server.protocol.v0_10.transport.MessageProperties)39 Message_1_0 (org.apache.qpid.server.protocol.v1_0.Message_1_0)27 AMQMessage (org.apache.qpid.server.protocol.v0_8.AMQMessage)25 BasicContentHeaderProperties (org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties)21 Properties (org.apache.qpid.server.protocol.v1_0.type.messaging.Properties)20 InternalMessage (org.apache.qpid.server.message.internal.InternalMessage)17 Header (org.apache.qpid.server.protocol.v1_0.type.messaging.Header)16 Matchers.anyString (org.mockito.Matchers.anyString)16 AMQShortString (org.apache.qpid.server.protocol.v0_8.AMQShortString)14 ApplicationProperties (org.apache.qpid.server.protocol.v1_0.type.messaging.ApplicationProperties)14 Header (org.apache.qpid.server.protocol.v0_10.transport.Header)10 MessagePublishInfo (org.apache.qpid.server.protocol.v0_8.transport.MessagePublishInfo)7 Date (java.util.Date)5 MessageAnnotations (org.apache.qpid.server.protocol.v1_0.type.messaging.MessageAnnotations)5 MessageMetaData_0_10 (org.apache.qpid.server.protocol.v0_10.MessageMetaData_0_10)4 MessageDeliveryMode (org.apache.qpid.server.protocol.v0_10.transport.MessageDeliveryMode)4 DeliveryAnnotations (org.apache.qpid.server.protocol.v1_0.type.messaging.DeliveryAnnotations)4 Method (org.apache.qpid.server.protocol.v0_10.transport.Method)3