Search in sources :

Example 1 with AMQPInvalidClassException

use of org.apache.qpid.server.protocol.v0_8.AMQPInvalidClassException in project qpid-broker-j by apache.

the class MessageConverter_1_0_to_v0_8 method convertMetaData.

private MessageMetaData convertMetaData(final Message_1_0 serverMsg, final String bodyMimeType, final int size, final NamedAddressSpace addressSpace) {
    final MessageMetaData_1_0.MessageHeader_1_0 header = serverMsg.getMessageHeader();
    final BasicContentHeaderProperties props = new BasicContentHeaderProperties();
    props.setAppId(serverMsg.getMessageHeader().getAppId());
    props.setContentType(bodyMimeType);
    props.setEncoding(convertToShortStringForProperty("content-encoding", serverMsg.getMessageHeader().getEncoding()));
    props.setCorrelationId(getCorrelationIdAsShortString(serverMsg));
    props.setDeliveryMode(serverMsg.isPersistent() ? BasicContentHeaderProperties.PERSISTENT : BasicContentHeaderProperties.NON_PERSISTENT);
    final Date absoluteExpiryTime = getAbsoluteExpiryTime(serverMsg);
    if (absoluteExpiryTime != null) {
        props.setExpiration(absoluteExpiryTime.getTime());
    } else {
        Long ttl = getTtl(serverMsg);
        if (ttl != null) {
            props.setExpiration(ttl + serverMsg.getArrivalTime());
        }
    }
    props.setMessageId(getMessageIdAsShortString(serverMsg));
    props.setPriority(serverMsg.getMessageHeader().getPriority());
    props.setReplyTo(getReplyTo(serverMsg, addressSpace));
    Date timestamp = getCreationTime(serverMsg);
    if (timestamp != null) {
        props.setTimestamp(timestamp.getTime());
    } else {
        props.setTimestamp(serverMsg.getArrivalTime());
    }
    props.setUserId(getUserIdAsShortString(serverMsg));
    Map<String, Object> headerProps = new LinkedHashMap<>();
    if (header.getSubject() != null) {
        headerProps.put("qpid.subject", header.getSubject());
        props.setType(convertToShortStringForProperty("subject", header.getSubject()));
    }
    String groupId = getGroupId(serverMsg);
    if (groupId != null) {
        headerProps.put("JMSXGroupID", groupId);
    }
    UnsignedInteger groupSequence = getGroupSequence(serverMsg);
    if (groupSequence != null) {
        headerProps.put("JMSXGroupSeq", groupSequence.intValue());
    }
    for (String headerName : serverMsg.getMessageHeader().getHeaderNames()) {
        headerProps.put(headerName, convertValue(serverMsg.getMessageHeader().getHeader(headerName)));
    }
    final FieldTable headers;
    try {
        headers = FieldTable.convertToFieldTable(headerProps);
    } catch (IllegalArgumentException | AMQPInvalidClassException e) {
        throw new MessageConversionException("Could not convert message from 1.0 to 0-8 because conversion of 'application-properties' failed.", e);
    }
    props.setHeaders(headers);
    final ContentHeaderBody chb = new ContentHeaderBody(props);
    chb.setBodySize(size);
    MessagePublishInfo publishInfo = createMessagePublishInfo(header, addressSpace);
    return new MessageMetaData(publishInfo, chb, serverMsg.getArrivalTime());
}
Also used : MessagePublishInfo(org.apache.qpid.server.protocol.v0_8.transport.MessagePublishInfo) MessageMetaData(org.apache.qpid.server.protocol.v0_8.MessageMetaData) AMQPInvalidClassException(org.apache.qpid.server.protocol.v0_8.AMQPInvalidClassException) MessageConversionException(org.apache.qpid.server.protocol.converter.MessageConversionException) ContentHeaderBody(org.apache.qpid.server.protocol.v0_8.transport.ContentHeaderBody) FieldTable(org.apache.qpid.server.protocol.v0_8.FieldTable) MessageMetaData_1_0(org.apache.qpid.server.protocol.v1_0.MessageMetaData_1_0) AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) BasicContentHeaderProperties(org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties) Date(java.util.Date) LinkedHashMap(java.util.LinkedHashMap) UnsignedInteger(org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger)

Example 2 with AMQPInvalidClassException

use of org.apache.qpid.server.protocol.v0_8.AMQPInvalidClassException in project qpid-broker-j by apache.

the class MessageConverter_Internal_to_v0_8 method convertMetaData.

private MessageMetaData convertMetaData(final InternalMessage serverMsg, final NamedAddressSpace addressSpace, final String bodyMimeType, final int size) {
    MessagePublishInfo publishInfo = createMessagePublishInfo(serverMsg, addressSpace);
    final BasicContentHeaderProperties props = new BasicContentHeaderProperties();
    props.setAppId(serverMsg.getMessageHeader().getAppId());
    props.setContentType(bodyMimeType);
    props.setCorrelationId(convertToShortStringForProperty("correlation-id", serverMsg.getMessageHeader().getCorrelationId()));
    props.setDeliveryMode(serverMsg.isPersistent() ? BasicContentHeaderProperties.PERSISTENT : BasicContentHeaderProperties.NON_PERSISTENT);
    props.setExpiration(serverMsg.getExpiration());
    props.setMessageId(convertToOptionalAMQPShortString(serverMsg.getMessageHeader().getMessageId()));
    props.setPriority(serverMsg.getMessageHeader().getPriority());
    props.setReplyTo(convertToShortStringForProperty("reply-to", getReplyTo(serverMsg, addressSpace)));
    props.setTimestamp(serverMsg.getMessageHeader().getTimestamp());
    props.setUserId(convertToOptionalAMQPShortString(serverMsg.getMessageHeader().getUserId()));
    props.setEncoding(convertToShortStringForProperty("encoding", serverMsg.getMessageHeader().getEncoding()));
    Map<String, Object> headerProps = new LinkedHashMap<String, Object>();
    for (String headerName : serverMsg.getMessageHeader().getHeaderNames()) {
        headerProps.put(headerName, serverMsg.getMessageHeader().getHeader(headerName));
    }
    try {
        props.setHeaders(FieldTable.convertToFieldTable(headerProps));
    } catch (IllegalArgumentException | AMQPInvalidClassException e) {
        throw new MessageConversionException("Could not convert message from internal to 0-8 because headers conversion failed.", e);
    }
    final ContentHeaderBody chb = new ContentHeaderBody(props);
    chb.setBodySize(size);
    return new MessageMetaData(publishInfo, chb, serverMsg.getArrivalTime());
}
Also used : MessagePublishInfo(org.apache.qpid.server.protocol.v0_8.transport.MessagePublishInfo) MessageConversionException(org.apache.qpid.server.protocol.converter.MessageConversionException) ContentHeaderBody(org.apache.qpid.server.protocol.v0_8.transport.ContentHeaderBody) BasicContentHeaderProperties(org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties) LinkedHashMap(java.util.LinkedHashMap)

Example 3 with AMQPInvalidClassException

use of org.apache.qpid.server.protocol.v0_8.AMQPInvalidClassException 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(AMQShortString.createAMQShortString(messageProps.getAppId()));
            } catch (IllegalArgumentException e) {
            // pass
            }
        }
        if (messageProps.hasContentType()) {
            props.setContentType(messageProps.getContentType());
        }
        if (messageProps.hasCorrelationId()) {
            try {
                props.setCorrelationId(AMQShortString.createAMQShortString(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, false);
                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(AMQShortString.createAMQShortString(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;
            try {
                ft = FieldTableFactory.createFieldTable(appHeaders);
            } catch (IllegalArgumentException | AMQPInvalidClassException e) {
                throw new MessageConversionException("Could not convert message from 0-10 to 0-8 because conversion of application headers failed.", e);
            }
            props.setHeaders(ft);
        }
    }
    return props;
}
Also used : 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)

Aggregations

MessageConversionException (org.apache.qpid.server.protocol.converter.MessageConversionException)3 BasicContentHeaderProperties (org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties)3 LinkedHashMap (java.util.LinkedHashMap)2 AMQPInvalidClassException (org.apache.qpid.server.protocol.v0_8.AMQPInvalidClassException)2 AMQShortString (org.apache.qpid.server.protocol.v0_8.AMQShortString)2 FieldTable (org.apache.qpid.server.protocol.v0_8.FieldTable)2 ContentHeaderBody (org.apache.qpid.server.protocol.v0_8.transport.ContentHeaderBody)2 MessagePublishInfo (org.apache.qpid.server.protocol.v0_8.transport.MessagePublishInfo)2 Date (java.util.Date)1 HashMap (java.util.HashMap)1 MessageDestination (org.apache.qpid.server.message.MessageDestination)1 Exchange (org.apache.qpid.server.model.Exchange)1 DeliveryProperties (org.apache.qpid.server.protocol.v0_10.transport.DeliveryProperties)1 Header (org.apache.qpid.server.protocol.v0_10.transport.Header)1 MessageProperties (org.apache.qpid.server.protocol.v0_10.transport.MessageProperties)1 ReplyTo (org.apache.qpid.server.protocol.v0_10.transport.ReplyTo)1 MessageMetaData (org.apache.qpid.server.protocol.v0_8.MessageMetaData)1 MessageMetaData_1_0 (org.apache.qpid.server.protocol.v1_0.MessageMetaData_1_0)1 UnsignedInteger (org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger)1