Search in sources :

Example 26 with Properties

use of com.swiftmq.amqp.v100.generated.messaging.message_format.Properties in project swiftmq-ce by iitsoftware.

the class JMSMappingInboundTransformer method transform.

public MessageImpl transform(TransferFrame frame, DestinationFactory destinationFactory) throws AMQPException, JMSException {
    jmsTypeProp = getValue(PROP_JMS_TYPE, null);
    MessageImpl jmsMessage = null;
    try {
        AMQPMessage amqpMessage = null;
        if (frame.getMorePayloads() != null) {
            List morePayloads = frame.getMorePayloads();
            byte[][] b = new byte[morePayloads.size() + 1][];
            b[0] = frame.getPayload();
            for (int i = 0; i < morePayloads.size(); i++) b[i + 1] = (byte[]) morePayloads.get(i);
            amqpMessage = new AMQPMessage(b, frame.getPayloadLength());
        } else
            amqpMessage = new AMQPMessage(frame.getPayload());
        jmsMessage = messageFactory.create(amqpMessage);
        jmsMessage.setLongProperty(prefixVendor + Util.PROP_MESSAGE_FORMAT, frame.getMessageFormat().getValue());
        jmsMessage.setBooleanProperty(amqpNative, false);
        Header header = amqpMessage.getHeader();
        if (header != null)
            transformHeader(header, jmsMessage);
        DeliveryAnnotations deliveryAnnotations = amqpMessage.getDeliveryAnnotations();
        if (deliveryAnnotations != null)
            transformMap(deliveryAnnotations.getValue(), jmsMessage, prefixDA);
        MessageAnnotations messageAnnotations = amqpMessage.getMessageAnnotations();
        if (messageAnnotations != null)
            transformMap(messageAnnotations.getValue(), jmsMessage, prefixMA);
        Properties properties = amqpMessage.getProperties();
        if (properties != null)
            transformProperties(properties, jmsMessage, destinationFactory);
        ApplicationProperties applicationProperties = amqpMessage.getApplicationProperties();
        if (applicationProperties != null)
            transformApplicationProperties(applicationProperties, jmsMessage);
        Footer footer = amqpMessage.getFooter();
        if (footer != null)
            transformMap(footer.getValue(), jmsMessage, prefixFT);
    } catch (Exception e) {
        throw new AMQPException(e.toString());
    }
    jmsMessage.reset();
    return jmsMessage;
}
Also used : AMQPException(com.swiftmq.amqp.v100.client.AMQPException) AMQPMessage(com.swiftmq.amqp.v100.messaging.AMQPMessage) AMQPException(com.swiftmq.amqp.v100.client.AMQPException) JMSException(javax.jms.JMSException) List(java.util.List) MessageImpl(com.swiftmq.jms.MessageImpl)

Example 27 with Properties

use of com.swiftmq.amqp.v100.generated.messaging.message_format.Properties in project swiftmq-ce by iitsoftware.

the class JMSMappingInboundTransformer method transformProperties.

protected void transformProperties(Properties properties, final MessageImpl jmsMessage, final DestinationFactory destinationFactory) throws Exception {
    if (overwriteMessageId) {
        jmsMessage.setJMSMessageID(nextMsgId());
    } else {
        MessageIdIF messageIdIF = properties.getMessageId();
        if (messageIdIF != null)
            messageIdIF.accept(new MessageIdVisitor() {

                public void visit(MessageIdUlong messageIdUlong) {
                    try {
                        jmsMessage.setJMSMessageID(String.valueOf(messageIdUlong.getValue()));
                    } catch (JMSException e) {
                    }
                }

                public void visit(MessageIdUuid messageIdUuid) {
                    try {
                        jmsMessage.setJMSMessageID(String.valueOf(messageIdUuid.getValue()));
                    } catch (JMSException e) {
                    }
                }

                public void visit(MessageIdBinary messageIdBinary) {
                    try {
                        jmsMessage.setJMSMessageID(new String(messageIdBinary.getValue()));
                    } catch (JMSException e) {
                    }
                }

                public void visit(MessageIdString messageIdString) {
                    try {
                        jmsMessage.setJMSMessageID(messageIdString.getValue());
                    } catch (JMSException e) {
                    }
                }
            });
    }
    AMQPBinary userId = properties.getUserId();
    if (userId != null)
        jmsMessage.setStringProperty(MessageImpl.PROP_USER_ID, new String(userId.getValue(), "ISO-8859-1"));
    AddressIF to = properties.getTo();
    if (to != null) {
        jmsMessage.setJMSDestination(destinationFactory.create(to));
        to.accept(new AddressVisitor() {

            public void visit(AddressString addressString) {
                try {
                    jmsMessage.setStringProperty(Util.PROP_AMQP_TO_ADDRESS, addressString.getValue());
                } catch (JMSException e) {
                }
            }
        });
    }
    AMQPString subject = properties.getSubject();
    if (subject != null)
        jmsMessage.setStringProperty(prefixVendor + "Subject", subject.getValue());
    AddressIF replyTo = properties.getReplyTo();
    if (replyTo != null)
        jmsMessage.setJMSReplyTo(destinationFactory.create(replyTo));
    MessageIdIF correlationIdIF = properties.getCorrelationId();
    if (correlationIdIF != null)
        correlationIdIF.accept(new MessageIdVisitor() {

            public void visit(MessageIdUlong messageIdUlong) {
                try {
                    jmsMessage.setJMSCorrelationID(String.valueOf(messageIdUlong.getValue()));
                } catch (JMSException e) {
                }
            }

            public void visit(MessageIdUuid messageIdUuid) {
                try {
                    jmsMessage.setJMSCorrelationID(String.valueOf(messageIdUuid.getValue()));
                } catch (JMSException e) {
                }
            }

            public void visit(MessageIdBinary messageIdBinary) {
                try {
                    jmsMessage.setJMSCorrelationID(new String(messageIdBinary.getValue()));
                } catch (JMSException e) {
                }
            }

            public void visit(MessageIdString messageIdString) {
                try {
                    jmsMessage.setJMSCorrelationID(messageIdString.getValue());
                } catch (JMSException e) {
                }
            }
        });
    AMQPSymbol contentType = properties.getContentType();
    if (contentType != null)
        jmsMessage.setStringProperty(prefixVendor + "ContentType", contentType.getValue());
    AMQPSymbol contentEncoding = properties.getContentEncoding();
    if (contentEncoding != null)
        jmsMessage.setStringProperty(prefixVendor + "ContentEncoding", contentEncoding.getValue());
    AMQPTimestamp ts = properties.getAbsoluteExpiryTime();
    if (ts != null)
        jmsMessage.setJMSExpiration(ts.getValue());
    AMQPTimestamp ct = properties.getCreationTime();
    if (ct != null)
        jmsMessage.setJMSTimestamp(ct.getValue());
    AMQPString groupId = properties.getGroupId();
    if (groupId != null)
        jmsMessage.setStringProperty(Util.PROP_GROUP_ID, groupId.getValue());
    SequenceNo groupSeq = properties.getGroupSequence();
    if (groupSeq != null)
        jmsMessage.setLongProperty(Util.PROP_GROUP_SEQ, groupSeq.getValue());
    AMQPString replyToGroupId = properties.getReplyToGroupId();
    if (replyToGroupId != null)
        jmsMessage.setStringProperty(prefixVendor + "ReplyToGroupID", replyToGroupId.getValue());
}
Also used : SequenceNo(com.swiftmq.amqp.v100.generated.transport.definitions.SequenceNo) JMSException(javax.jms.JMSException)

Example 28 with Properties

use of com.swiftmq.amqp.v100.generated.messaging.message_format.Properties in project rabbitmq-stream-java-client by rabbitmq.

the class SwiftMqCodec method createMessage.

protected Message createMessage(byte[] data) {
    AMQPMessage amqpMessage;
    try {
        amqpMessage = new AMQPMessage(data);
    } catch (Exception e) {
        throw new StreamException("Error while decoding AMQP 1.0 message");
    }
    Object body = extractBody(amqpMessage);
    com.rabbitmq.stream.Properties properties = createProperties(amqpMessage);
    Map<String, Object> applicationProperties = createApplicationProperties(amqpMessage);
    Map<String, Object> messageAnnotations = createMessageAnnotations(amqpMessage);
    return new SwiftMqMessage(amqpMessage, body, properties, applicationProperties, messageAnnotations);
}
Also used : AMQPMessage(com.swiftmq.amqp.v100.messaging.AMQPMessage) IOException(java.io.IOException) StreamException(com.rabbitmq.stream.StreamException) StreamException(com.rabbitmq.stream.StreamException)

Aggregations

AMQPMessage (com.swiftmq.amqp.v100.messaging.AMQPMessage)22 Properties (com.swiftmq.amqp.v100.generated.messaging.message_format.Properties)19 AddressIF (com.swiftmq.amqp.v100.generated.messaging.message_format.AddressIF)12 TxnIdIF (com.swiftmq.amqp.v100.generated.transactions.coordination.TxnIdIF)8 IOException (java.io.IOException)8 AMQPString (com.swiftmq.amqp.v100.types.AMQPString)6 Map (java.util.Map)6 Producer (com.swiftmq.amqp.v100.client.Producer)5 SequenceNo (com.swiftmq.amqp.v100.generated.transport.definitions.SequenceNo)5 HashMap (java.util.HashMap)5 List (java.util.List)5 ApplicationProperties (com.swiftmq.amqp.v100.generated.messaging.message_format.ApplicationProperties)4 AMQPBoolean (com.swiftmq.amqp.v100.types.AMQPBoolean)4 AMQPMap (com.swiftmq.amqp.v100.types.AMQPMap)4 ArrayList (java.util.ArrayList)4 AmqpValue (com.swiftmq.amqp.v100.generated.messaging.message_format.AmqpValue)3 Fields (com.swiftmq.amqp.v100.generated.transport.definitions.Fields)3 Milliseconds (com.swiftmq.amqp.v100.generated.transport.definitions.Milliseconds)3 JMSException (javax.jms.JMSException)3 StreamException (com.rabbitmq.stream.StreamException)2