Search in sources :

Example 41 with Exchange

use of org.apache.qpid.server.model.Exchange in project qpid-broker-j by apache.

the class PropertyConverter_Internal_to_v0_8Test method testReplyToConversionWhenExchangeAndRoutingKeyAreSpecified.

@Test
public void testReplyToConversionWhenExchangeAndRoutingKeyAreSpecified() {
    final String exchangeName = "testExchange";
    final String routingKey = "testKey";
    final String replyTo = String.format("%s/%s", exchangeName, routingKey);
    final AMQMessageHeader header = mock(AMQMessageHeader.class);
    when(header.getReplyTo()).thenReturn(replyTo);
    Exchange exchange = mock(Exchange.class);
    when(exchange.getName()).thenReturn(exchangeName);
    when(exchange.getType()).thenReturn(ExchangeDefaults.TOPIC_EXCHANGE_CLASS);
    doReturn(exchange).when(_addressSpace).getAttainedMessageDestination(eq(exchangeName), anyBoolean());
    InternalMessage originalMessage = createTestMessage(header);
    AMQMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
    assertEquals("Unexpected reply-to", "topic://" + exchangeName + "//?routingkey='" + routingKey + "'", convertedMessage.getContentHeaderBody().getProperties().getReplyToAsString());
}
Also used : Exchange(org.apache.qpid.server.model.Exchange) InternalMessage(org.apache.qpid.server.message.internal.InternalMessage) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) AMQMessageHeader(org.apache.qpid.server.message.AMQMessageHeader) Test(org.junit.Test)

Example 42 with Exchange

use of org.apache.qpid.server.model.Exchange in project qpid-broker-j by apache.

the class PropertyConverter_Internal_to_v0_8Test method testConversionWhenToIsUnsetButInitialRoutingKeyIsSet.

@Test
public void testConversionWhenToIsUnsetButInitialRoutingKeyIsSet() {
    final String testExchange = "testExchange";
    final String testRoutingKey = "testRoutingKey";
    InternalMessage message = createTestMessage("");
    final String testInitialRoutingAddress = testExchange + "/" + testRoutingKey;
    message.setInitialRoutingAddress(testInitialRoutingAddress);
    final Exchange exchange = mock(Exchange.class);
    when(exchange.getName()).thenReturn(testExchange);
    doReturn(exchange).when(_addressSpace).getAttainedMessageDestination(eq(testExchange), anyBoolean());
    final AMQMessage convertedMessage = _messageConverter.convert(message, _addressSpace);
    final MessagePublishInfo messagePublishInfo = convertedMessage.getMessagePublishInfo();
    assertEquals("Unexpected exchange", testExchange, messagePublishInfo.getExchange().toString());
    assertEquals("Unexpected routing key", testRoutingKey, messagePublishInfo.getRoutingKey().toString());
}
Also used : Exchange(org.apache.qpid.server.model.Exchange) MessagePublishInfo(org.apache.qpid.server.protocol.v0_8.transport.MessagePublishInfo) InternalMessage(org.apache.qpid.server.message.internal.InternalMessage) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 43 with Exchange

use of org.apache.qpid.server.model.Exchange in project qpid-broker-j by apache.

the class PropertyConverter_Internal_to_v0_8Test method testToConversionWhenExchangeIsSpecified.

@Test
public void testToConversionWhenExchangeIsSpecified() {
    final String testExchange = "testExchange";
    InternalMessage message = createTestMessage(testExchange);
    final Exchange exchange = mock(Exchange.class);
    when(exchange.getName()).thenReturn(testExchange);
    doReturn(exchange).when(_addressSpace).getAttainedMessageDestination(eq(testExchange), anyBoolean());
    final AMQMessage convertedMessage = _messageConverter.convert(message, _addressSpace);
    final MessagePublishInfo messagePublishInfo = convertedMessage.getMessagePublishInfo();
    assertEquals("Unexpected exchange", testExchange, messagePublishInfo.getExchange().toString());
    assertEquals("Unexpected routing key", "", messagePublishInfo.getRoutingKey().toString());
}
Also used : Exchange(org.apache.qpid.server.model.Exchange) MessagePublishInfo(org.apache.qpid.server.protocol.v0_8.transport.MessagePublishInfo) InternalMessage(org.apache.qpid.server.message.internal.InternalMessage) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 44 with Exchange

use of org.apache.qpid.server.model.Exchange in project qpid-broker-j by apache.

the class MessageConverter_1_0_to_v0_8 method getReplyTo.

private AMQShortString getReplyTo(final Message_1_0 serverMsg, final NamedAddressSpace addressSpace) {
    final String replyTo = serverMsg.getMessageHeader().getReplyTo();
    if (replyTo != null) {
        DestinationAddress destinationAddress = new DestinationAddress(addressSpace, replyTo);
        MessageDestination messageDestination = destinationAddress.getMessageDestination();
        final String replyToBindingUrl;
        if (messageDestination instanceof Exchange) {
            Exchange<?> exchange = (Exchange<?>) messageDestination;
            final String routingKeyOption = "".equals(destinationAddress.getRoutingKey()) ? "" : String.format("?routingkey='%s'", destinationAddress.getRoutingKey());
            replyToBindingUrl = String.format("%s://%s//%s", exchange.getType(), exchange.getName(), routingKeyOption);
        } else if (messageDestination instanceof Queue) {
            replyToBindingUrl = String.format("%s:////%s", ExchangeDefaults.DIRECT_EXCHANGE_CLASS, messageDestination.getName());
        } else {
            replyToBindingUrl = String.format("%s:////?routingkey='%s'", ExchangeDefaults.DIRECT_EXCHANGE_CLASS, destinationAddress.getRoutingKey());
        }
        try {
            return AMQShortString.valueOf(replyToBindingUrl);
        } catch (IllegalArgumentException e) {
            throw new MessageConversionException("Could not convert message from 1.0 to 0-8 because conversion of 'reply-to' failed.", e);
        }
    }
    return null;
}
Also used : Exchange(org.apache.qpid.server.model.Exchange) MessageDestination(org.apache.qpid.server.message.MessageDestination) MessageConversionException(org.apache.qpid.server.protocol.converter.MessageConversionException) AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) Queue(org.apache.qpid.server.model.Queue) DestinationAddress(org.apache.qpid.server.model.DestinationAddress)

Example 45 with Exchange

use of org.apache.qpid.server.model.Exchange in project qpid-broker-j by apache.

the class MessageConverter_1_0_to_v0_8 method createMessagePublishInfo.

private MessagePublishInfo createMessagePublishInfo(final MessageMetaData_1_0.MessageHeader_1_0 header, final NamedAddressSpace addressSpace) {
    final String to = header.getTo();
    final String subject = header.getSubject() == null ? "" : header.getSubject();
    final String exchangeName;
    final String routingKey;
    if (to != null && !"".equals(to)) {
        DestinationAddress destinationAddress = new DestinationAddress(addressSpace, to);
        MessageDestination messageDestination = destinationAddress.getMessageDestination();
        if (messageDestination instanceof Queue) {
            exchangeName = "";
            routingKey = messageDestination.getName();
        } else if (messageDestination instanceof Exchange) {
            exchangeName = messageDestination.getName();
            routingKey = "".equals(destinationAddress.getRoutingKey()) ? subject : destinationAddress.getRoutingKey();
        } else {
            exchangeName = "";
            routingKey = to;
        }
    } else {
        exchangeName = "";
        routingKey = subject;
    }
    return new MessagePublishInfo(convertToShortStringForProperty("to", exchangeName), false, false, convertToShortStringForProperty("to' or 'subject", routingKey));
}
Also used : Exchange(org.apache.qpid.server.model.Exchange) MessagePublishInfo(org.apache.qpid.server.protocol.v0_8.transport.MessagePublishInfo) MessageDestination(org.apache.qpid.server.message.MessageDestination) AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) Queue(org.apache.qpid.server.model.Queue) DestinationAddress(org.apache.qpid.server.model.DestinationAddress)

Aggregations

Exchange (org.apache.qpid.server.model.Exchange)53 Test (org.junit.Test)29 HashMap (java.util.HashMap)24 ServerMessage (org.apache.qpid.server.message.ServerMessage)15 Queue (org.apache.qpid.server.model.Queue)15 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)14 MessageDestination (org.apache.qpid.server.message.MessageDestination)13 DestinationAddress (org.apache.qpid.server.model.DestinationAddress)8 ReplyTo (org.apache.qpid.server.protocol.v0_10.transport.ReplyTo)8 AMQShortString (org.apache.qpid.server.protocol.v0_8.AMQShortString)8 Message_1_0 (org.apache.qpid.server.protocol.v1_0.Message_1_0)8 ApplicationProperties (org.apache.qpid.server.protocol.v1_0.type.messaging.ApplicationProperties)8 Properties (org.apache.qpid.server.protocol.v1_0.type.messaging.Properties)8 NamedAddressSpace (org.apache.qpid.server.model.NamedAddressSpace)7 AccessControlException (java.security.AccessControlException)6 LinkedHashMap (java.util.LinkedHashMap)6 InternalMessage (org.apache.qpid.server.message.internal.InternalMessage)6 BasicContentHeaderProperties (org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties)6 MessagePublishInfo (org.apache.qpid.server.protocol.v0_8.transport.MessagePublishInfo)6 IllegalConfigurationException (org.apache.qpid.server.configuration.IllegalConfigurationException)5