Search in sources :

Example 21 with InternalMessage

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

the class PropertyConverter_v1_0_to_InternalTest method testUserIdConversion.

public void testUserIdConversion() {
    final byte[] data = new byte[] { (byte) 0xc3, 0x28 };
    final Binary userId = new Binary(data);
    Properties properties = new Properties();
    properties.setUserId(userId);
    Message_1_0 originalMessage = createTestMessage(properties);
    InternalMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
    assertEquals("Unexpected userId", new String(data, UTF_8), convertedMessage.getMessageHeader().getUserId());
}
Also used : InternalMessage(org.apache.qpid.server.message.internal.InternalMessage) Binary(org.apache.qpid.server.protocol.v1_0.type.Binary) ApplicationProperties(org.apache.qpid.server.protocol.v1_0.type.messaging.ApplicationProperties) Properties(org.apache.qpid.server.protocol.v1_0.type.messaging.Properties)

Example 22 with InternalMessage

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

the class PropertyConverter_v1_0_to_InternalTest method testReplyToConversion.

public void testReplyToConversion() {
    final String replyTo = "amq.direct/test";
    Properties properties = new Properties();
    properties.setReplyTo(replyTo);
    Message_1_0 originalMessage = createTestMessage(properties);
    InternalMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
    assertEquals("Unexpected replyTo", replyTo, convertedMessage.getMessageHeader().getReplyTo());
}
Also used : InternalMessage(org.apache.qpid.server.message.internal.InternalMessage) ApplicationProperties(org.apache.qpid.server.protocol.v1_0.type.messaging.ApplicationProperties) Properties(org.apache.qpid.server.protocol.v1_0.type.messaging.Properties)

Example 23 with InternalMessage

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

the class PropertyConverter_v1_0_to_InternalTest method testCorrelationIdUnsignedLongConversion.

public void testCorrelationIdUnsignedLongConversion() {
    final UnsignedLong correlationId = UnsignedLong.valueOf(-1L);
    Properties properties = new Properties();
    properties.setCorrelationId(correlationId);
    Message_1_0 originalMessage = createTestMessage(properties);
    InternalMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
    assertEquals("Unexpected correlationId", correlationId.toString(), convertedMessage.getMessageHeader().getCorrelationId());
}
Also used : InternalMessage(org.apache.qpid.server.message.internal.InternalMessage) UnsignedLong(org.apache.qpid.server.protocol.v1_0.type.UnsignedLong) ApplicationProperties(org.apache.qpid.server.protocol.v1_0.type.messaging.ApplicationProperties) Properties(org.apache.qpid.server.protocol.v1_0.type.messaging.Properties)

Example 24 with InternalMessage

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

the class PropertyConverter_v1_0_to_InternalTest method testMessageIdUuidConversion.

public void testMessageIdUuidConversion() {
    final UUID messageId = UUID.randomUUID();
    Properties properties = new Properties();
    properties.setMessageId(messageId);
    Message_1_0 originalMessage = createTestMessage(properties);
    InternalMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
    assertEquals("Unexpected messageId", messageId.toString(), convertedMessage.getMessageHeader().getMessageId());
}
Also used : InternalMessage(org.apache.qpid.server.message.internal.InternalMessage) UUID(java.util.UUID) ApplicationProperties(org.apache.qpid.server.protocol.v1_0.type.messaging.ApplicationProperties) Properties(org.apache.qpid.server.protocol.v1_0.type.messaging.Properties)

Example 25 with InternalMessage

use of org.apache.qpid.server.message.internal.InternalMessage 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)

Aggregations

InternalMessage (org.apache.qpid.server.message.internal.InternalMessage)185 AMQMessageHeader (org.apache.qpid.server.message.AMQMessageHeader)60 Matchers.anyString (org.mockito.Matchers.anyString)45 NamedAddressSpace (org.apache.qpid.server.model.NamedAddressSpace)36 ApplicationProperties (org.apache.qpid.server.protocol.v1_0.type.messaging.ApplicationProperties)25 Properties (org.apache.qpid.server.protocol.v1_0.type.messaging.Properties)24 AMQShortString (org.apache.qpid.server.protocol.v0_8.AMQShortString)23 MessageProperties (org.apache.qpid.server.protocol.v0_10.transport.MessageProperties)18 BasicContentHeaderProperties (org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties)18 DeliveryProperties (org.apache.qpid.server.protocol.v0_10.transport.DeliveryProperties)17 AmqpValue (org.apache.qpid.server.protocol.v1_0.type.messaging.AmqpValue)15 HashMap (java.util.HashMap)13 MessageConversionException (org.apache.qpid.server.protocol.converter.MessageConversionException)12 ReplyTo (org.apache.qpid.server.protocol.v0_10.transport.ReplyTo)9 UUID (java.util.UUID)8 Binary (org.apache.qpid.server.protocol.v1_0.type.Binary)8 MessagePublishInfo (org.apache.qpid.server.protocol.v0_8.transport.MessagePublishInfo)7 Map (java.util.Map)6 Exchange (org.apache.qpid.server.model.Exchange)6 ArrayList (java.util.ArrayList)5