Search in sources :

Example 16 with ReplyTo

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

the class PropertyConverter_Internal_to_v0_10Test method testReplyToConversionWhenExchangeAndRoutingKeyAreSpecified.

public void testReplyToConversionWhenExchangeAndRoutingKeyAreSpecified() throws IOException {
    final AMQMessageHeader header = mock(AMQMessageHeader.class);
    final String exchangeName = "testExchnageName";
    final String routingKey = "testRoutingKey";
    final String replyTo = String.format("%s/%s", exchangeName, routingKey);
    final Exchange exchange = mock(Exchange.class);
    when(exchange.getName()).thenReturn(exchangeName);
    when(_addressSpace.getAttainedMessageDestination(exchangeName)).thenReturn(exchange);
    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", exchangeName, convertedReplyTo.getExchange());
    assertEquals("Unexpected routing key", routingKey, convertedReplyTo.getRoutingKey());
}
Also used : Exchange(org.apache.qpid.server.model.Exchange) 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 17 with ReplyTo

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

the class PropertyConverter_Internal_to_v0_10Test method testReplyToConversionWhenExchangeIsSpecified.

public void testReplyToConversionWhenExchangeIsSpecified() throws IOException {
    final AMQMessageHeader header = mock(AMQMessageHeader.class);
    final String replyTo = "myTestExchange";
    final Exchange exchange = mock(Exchange.class);
    when(exchange.getName()).thenReturn(replyTo);
    when(_addressSpace.getAttainedMessageDestination(replyTo)).thenReturn(exchange);
    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", replyTo, convertedReplyTo.getExchange());
    assertEquals("Unexpected routing key", "", convertedReplyTo.getRoutingKey());
}
Also used : Exchange(org.apache.qpid.server.model.Exchange) 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 18 with ReplyTo

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

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

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

MessageProperties (org.apache.qpid.server.protocol.v0_10.transport.MessageProperties)31 ReplyTo (org.apache.qpid.server.protocol.v0_10.transport.ReplyTo)31 MessageTransferMessage (org.apache.qpid.server.protocol.v0_10.MessageTransferMessage)21 AMQShortString (org.apache.qpid.server.protocol.v0_8.AMQShortString)15 DeliveryProperties (org.apache.qpid.server.protocol.v0_10.transport.DeliveryProperties)14 BasicContentHeaderProperties (org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties)12 Properties (org.apache.qpid.server.protocol.v1_0.type.messaging.Properties)12 Message_1_0 (org.apache.qpid.server.protocol.v1_0.Message_1_0)11 AMQMessage (org.apache.qpid.server.protocol.v0_8.AMQMessage)10 Matchers.anyString (org.mockito.Matchers.anyString)10 InternalMessage (org.apache.qpid.server.message.internal.InternalMessage)9 Exchange (org.apache.qpid.server.model.Exchange)8 ApplicationProperties (org.apache.qpid.server.protocol.v1_0.type.messaging.ApplicationProperties)7 AMQMessageHeader (org.apache.qpid.server.message.AMQMessageHeader)5 Queue (org.apache.qpid.server.model.Queue)4 MessageConversionException (org.apache.qpid.server.protocol.converter.MessageConversionException)4 MessageDestination (org.apache.qpid.server.message.MessageDestination)3 HashMap (java.util.HashMap)2 DestinationAddress (org.apache.qpid.server.model.DestinationAddress)2 Header (org.apache.qpid.server.protocol.v0_10.transport.Header)2