Search in sources :

Example 1 with InstanceProperties

use of org.apache.qpid.server.message.InstanceProperties in project qpid-broker-j by apache.

the class TopicExchangeTest method testUpdateBindingRemovingSelector.

public void testUpdateBindingRemovingSelector() throws Exception {
    String bindingKey = "mybinding";
    Queue<?> queue = _vhost.createChild(Queue.class, Collections.singletonMap(Queue.NAME, getTestName() + "_queue"));
    InstanceProperties instanceProperties = mock(InstanceProperties.class);
    ServerMessage<?> message = createTestMessage(Collections.singletonMap("prop", false));
    boolean bind = _exchange.bind(queue.getName(), bindingKey, Collections.singletonMap(JMS_SELECTOR.toString(), "prop = True"), false);
    assertTrue("Bind operation should be successful", bind);
    RoutingResult<ServerMessage<?>> result = _exchange.route(message, bindingKey, instanceProperties);
    assertFalse("Message that does not match selector routed to queue", result.hasRoutes());
    _exchange.replaceBinding(bindingKey, queue, Collections.emptyMap());
    result = _exchange.route(message, bindingKey, instanceProperties);
    assertTrue("Message not routed to queue after rebind", result.hasRoutes());
}
Also used : InstanceProperties(org.apache.qpid.server.message.InstanceProperties) ServerMessage(org.apache.qpid.server.message.ServerMessage)

Example 2 with InstanceProperties

use of org.apache.qpid.server.message.InstanceProperties in project qpid-broker-j by apache.

the class TopicExchangeTest method testUpdateBindingReplacingSelector.

public void testUpdateBindingReplacingSelector() throws Exception {
    String bindingKey = "mybinding";
    Queue<?> queue = _vhost.createChild(Queue.class, Collections.singletonMap(Queue.NAME, getTestName() + "_queue"));
    InstanceProperties instanceProperties = mock(InstanceProperties.class);
    ServerMessage<?> matchingMessage = createTestMessage(Collections.singletonMap("prop", true));
    boolean bind = _exchange.bind(queue.getName(), bindingKey, Collections.singletonMap(JMS_SELECTOR.toString(), "prop = True"), false);
    assertTrue("Bind operation should be successful", bind);
    RoutingResult<ServerMessage<?>> result = _exchange.route(matchingMessage, bindingKey, instanceProperties);
    assertTrue("Message with matching selector not routed to queue", result.hasRoutes());
    _exchange.replaceBinding(bindingKey, queue, Collections.singletonMap(JMS_SELECTOR.toString(), "prop = False"));
    result = _exchange.route(matchingMessage, bindingKey, instanceProperties);
    assertFalse("Message unexpectedly routed to queue after rebind", result.hasRoutes());
    result = _exchange.route(matchingMessage, bindingKey, instanceProperties);
    assertFalse(result.hasRoutes());
    matchingMessage = createTestMessage(Collections.singletonMap("prop", false));
    result = _exchange.route(matchingMessage, bindingKey, instanceProperties);
    assertTrue("Message not routed to queue", result.hasRoutes());
}
Also used : InstanceProperties(org.apache.qpid.server.message.InstanceProperties) ServerMessage(org.apache.qpid.server.message.ServerMessage)

Example 3 with InstanceProperties

use of org.apache.qpid.server.message.InstanceProperties in project qpid-broker-j by apache.

the class AbstractVirtualHost method publishMessage.

@Override
public int publishMessage(@Param(name = "message") final ManageableMessage message) {
    final String address = message.getAddress();
    MessageDestination destination = address == null ? getDefaultDestination() : getAttainedMessageDestination(address);
    if (destination == null) {
        destination = getDefaultDestination();
    }
    final AMQMessageHeader header = new MessageHeaderImpl(message);
    Serializable body = null;
    Object messageContent = message.getContent();
    if (messageContent != null) {
        if (messageContent instanceof Map || messageContent instanceof List) {
            if (message.getMimeType() != null || message.getEncoding() != null) {
                throw new IllegalArgumentException("If the message content is provided as map or list, the mime type and encoding must be left unset");
            }
            body = (Serializable) messageContent;
        } else if (messageContent instanceof String) {
            String contentTransferEncoding = message.getContentTransferEncoding();
            if ("base64".equalsIgnoreCase(contentTransferEncoding)) {
                body = Strings.decodeBase64((String) messageContent);
            } else if (contentTransferEncoding == null || contentTransferEncoding.trim().equals("") || contentTransferEncoding.trim().equalsIgnoreCase("identity")) {
                String mimeType = message.getMimeType();
                if (mimeType != null && !(mimeType = mimeType.trim().toLowerCase()).equals("")) {
                    if (!(mimeType.startsWith("text/") || Arrays.asList("application/json", "application/xml").contains(mimeType))) {
                        throw new IllegalArgumentException(message.getMimeType() + " is invalid as a MIME type for this message. " + "Only MIME types of the text type can be used if a string is supplied as the content");
                    } else if (mimeType.matches(".*;\\s*charset\\s*=.*")) {
                        throw new IllegalArgumentException(message.getMimeType() + " is invalid as a MIME type for this message. " + "If a string is supplied as the content, the MIME type must not include a charset parameter");
                    }
                }
                body = (String) messageContent;
            } else {
                throw new IllegalArgumentException("contentTransferEncoding value '" + contentTransferEncoding + "' is invalid.  The only valid values are base64 and identity");
            }
        } else {
            throw new IllegalArgumentException("The message content (if present) can only be a string, map or list");
        }
    }
    InternalMessage internalMessage = InternalMessage.createMessage(getMessageStore(), header, body, message.isPersistent(), address);
    AutoCommitTransaction txn = new AutoCommitTransaction(getMessageStore());
    final InstanceProperties instanceProperties = new InstanceProperties() {

        @Override
        public Object getProperty(final Property prop) {
            switch(prop) {
                case EXPIRATION:
                    Date expiration = message.getExpiration();
                    return expiration == null ? 0 : expiration.getTime();
                case IMMEDIATE:
                    return false;
                case PERSISTENT:
                    return message.isPersistent();
                case MANDATORY:
                    return false;
                case REDELIVERED:
                    return false;
                default:
                    return null;
            }
        }
    };
    final RoutingResult<InternalMessage> result = destination.route(internalMessage, address, instanceProperties);
    return result.send(txn, null);
}
Also used : AutoCommitTransaction(org.apache.qpid.server.txn.AutoCommitTransaction) Serializable(java.io.Serializable) MessageDestination(org.apache.qpid.server.message.MessageDestination) InternalMessage(org.apache.qpid.server.message.internal.InternalMessage) InstanceProperties(org.apache.qpid.server.message.InstanceProperties) AMQMessageHeader(org.apache.qpid.server.message.AMQMessageHeader) Date(java.util.Date) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Collections.newSetFromMap(java.util.Collections.newSetFromMap)

Example 4 with InstanceProperties

use of org.apache.qpid.server.message.InstanceProperties in project qpid-broker-j by apache.

the class DirectExchangeTest method testRouteToQueueWithSelector.

public void testRouteToQueueWithSelector() {
    String boundKey = "key";
    Queue<?> queue = _vhost.createChild(Queue.class, Collections.singletonMap(Queue.NAME, getTestName() + "_queue"));
    InstanceProperties instanceProperties = mock(InstanceProperties.class);
    ServerMessage<?> matchingMessage = createTestMessage(Collections.singletonMap("prop", true));
    ServerMessage<?> unmatchingMessage = createTestMessage(Collections.singletonMap("prop", false));
    boolean bind = _exchange.bind(queue.getName(), boundKey, Collections.singletonMap(JMS_SELECTOR.toString(), "prop = True"), false);
    assertTrue("Bind operation should be successful", bind);
    RoutingResult<ServerMessage<?>> result = _exchange.route(matchingMessage, boundKey, instanceProperties);
    assertTrue("Message with matching selector not routed to queue", result.hasRoutes());
    result = _exchange.route(unmatchingMessage, boundKey, instanceProperties);
    assertFalse("Message with matching selector unexpectedly routed to queue", result.hasRoutes());
    boolean unbind = _exchange.unbind(queue.getName(), boundKey);
    assertTrue("Unbind operation should be successful", unbind);
    result = _exchange.route(matchingMessage, boundKey, instanceProperties);
    assertFalse("Message with matching selector unexpectedly routed to queue after unbind", result.hasRoutes());
}
Also used : InstanceProperties(org.apache.qpid.server.message.InstanceProperties) ServerMessage(org.apache.qpid.server.message.ServerMessage)

Example 5 with InstanceProperties

use of org.apache.qpid.server.message.InstanceProperties in project qpid-broker-j by apache.

the class FanoutExchangeTest method testRouteToQueueWithSelector.

public void testRouteToQueueWithSelector() {
    String bindingKey = "mybinding";
    Queue<?> queue = _vhost.createChild(Queue.class, Collections.singletonMap(Queue.NAME, getTestName() + "_queue"));
    InstanceProperties instanceProperties = mock(InstanceProperties.class);
    ServerMessage<?> matchingMessage = createTestMessage(Collections.singletonMap("prop", true));
    ServerMessage<?> unmatchingMessage = createTestMessage(Collections.singletonMap("prop", false));
    boolean bind = _exchange.bind(queue.getName(), bindingKey, Collections.singletonMap(JMS_SELECTOR.toString(), "prop = True"), false);
    assertTrue("Bind operation should be successful", bind);
    RoutingResult<ServerMessage<?>> result = _exchange.route(matchingMessage, null, instanceProperties);
    assertTrue("Message with matching selector not routed to queue", result.hasRoutes());
    result = _exchange.route(unmatchingMessage, null, instanceProperties);
    assertFalse("Message without matching selector unexpectedly routed to queue", result.hasRoutes());
    boolean unbind = _exchange.unbind(queue.getName(), bindingKey);
    assertTrue("Unbind operation should be successful", unbind);
    result = _exchange.route(matchingMessage, null, instanceProperties);
    assertFalse("Message with matching selector unexpectedly routed to queue after unbind", result.hasRoutes());
}
Also used : InstanceProperties(org.apache.qpid.server.message.InstanceProperties) ServerMessage(org.apache.qpid.server.message.ServerMessage)

Aggregations

InstanceProperties (org.apache.qpid.server.message.InstanceProperties)10 ServerMessage (org.apache.qpid.server.message.ServerMessage)6 MessageDestination (org.apache.qpid.server.message.MessageDestination)3 AccessControlException (java.security.AccessControlException)2 MessageReference (org.apache.qpid.server.message.MessageReference)2 RoutingResult (org.apache.qpid.server.message.RoutingResult)2 Serializable (java.io.Serializable)1 ArrayList (java.util.ArrayList)1 Collections.newSetFromMap (java.util.Collections.newSetFromMap)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 AMQMessageHeader (org.apache.qpid.server.message.AMQMessageHeader)1 InternalMessage (org.apache.qpid.server.message.internal.InternalMessage)1 AbstractConfiguredObject (org.apache.qpid.server.model.AbstractConfiguredObject)1 NamedAddressSpace (org.apache.qpid.server.model.NamedAddressSpace)1 AmqpError (org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError)1 MessageStore (org.apache.qpid.server.store.MessageStore)1