Search in sources :

Example 61 with AMQPMessage

use of com.swiftmq.amqp.v100.messaging.AMQPMessage 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 62 with AMQPMessage

use of com.swiftmq.amqp.v100.messaging.AMQPMessage in project swiftmq-ce by iitsoftware.

the class MessageTypeBodyFactory method createBody.

public void createBody(MessageImpl jmsMessage, AMQPMessage amqpMessage) throws JMSException, AMQPException {
    jmsMessage.reset();
    if (jmsMessage instanceof TextMessageImpl) {
        amqpMessage.setAmqpValue(new AmqpValue(new AMQPString(((TextMessageImpl) jmsMessage).getText())));
    } else if (jmsMessage instanceof MapMessageImpl) {
        MapMessageImpl msg = (MapMessageImpl) jmsMessage;
        Map map = new HashMap();
        for (Enumeration _enum = msg.getMapNames(); _enum.hasMoreElements(); ) {
            String name = (String) _enum.nextElement();
            map.put(new AMQPString(name), Util.convertJMStoAMQP(msg.getObject(name)));
        }
        try {
            amqpMessage.setAmqpValue(new AmqpValue(new AMQPMap(map)));
        } catch (IOException e) {
            throw new AMQPException(e.toString());
        }
    } else if (jmsMessage instanceof BytesMessageImpl) {
        BytesMessageImpl msg = (BytesMessageImpl) jmsMessage;
        byte[] b = new byte[(int) msg.getBodyLength()];
        msg.readBytes(b);
        amqpMessage.addData(new Data(b));
    } else if (jmsMessage instanceof ObjectMessageImpl) {
        amqpMessage.setAmqpValue(new AmqpValue(Util.convertJMStoAMQP(((ObjectMessageImpl) jmsMessage).getObject())));
    } else if (jmsMessage instanceof StreamMessageImpl) {
        List list = new ArrayList();
        StreamMessageImpl msg = (StreamMessageImpl) jmsMessage;
        try {
            for (; ; ) {
                list.add(Util.convertJMStoAMQP(msg.readObject()));
            }
        } catch (MessageEOFException e) {
        }
        try {
            amqpMessage.addAmqpSequence(new AmqpSequence(list));
        } catch (IOException e) {
            throw new AMQPException(e.toString());
        }
    }
}
Also used : AMQPException(com.swiftmq.amqp.v100.client.AMQPException) AMQPMap(com.swiftmq.amqp.v100.types.AMQPMap) MessageEOFException(javax.jms.MessageEOFException) Data(com.swiftmq.amqp.v100.generated.messaging.message_format.Data) AMQPString(com.swiftmq.amqp.v100.types.AMQPString) IOException(java.io.IOException) AmqpSequence(com.swiftmq.amqp.v100.generated.messaging.message_format.AmqpSequence) AmqpValue(com.swiftmq.amqp.v100.generated.messaging.message_format.AmqpValue) AMQPString(com.swiftmq.amqp.v100.types.AMQPString) AMQPMap(com.swiftmq.amqp.v100.types.AMQPMap)

Example 63 with AMQPMessage

use of com.swiftmq.amqp.v100.messaging.AMQPMessage 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)56 AMQPString (com.swiftmq.amqp.v100.types.AMQPString)24 AmqpValue (com.swiftmq.amqp.v100.generated.messaging.message_format.AmqpValue)23 TxnIdIF (com.swiftmq.amqp.v100.generated.transactions.coordination.TxnIdIF)20 Properties (com.swiftmq.amqp.v100.generated.messaging.message_format.Properties)19 Map (java.util.Map)13 AddressIF (com.swiftmq.amqp.v100.generated.messaging.message_format.AddressIF)12 HashMap (java.util.HashMap)10 AMQPContext (com.swiftmq.amqp.AMQPContext)9 Data (com.swiftmq.amqp.v100.generated.messaging.message_format.Data)8 AMQPMap (com.swiftmq.amqp.v100.types.AMQPMap)8 JSSESocketFactory (com.swiftmq.net.JSSESocketFactory)8 IOException (java.io.IOException)8 Producer (com.swiftmq.amqp.v100.client.Producer)6 ApplicationProperties (com.swiftmq.amqp.v100.generated.messaging.message_format.ApplicationProperties)6 AMQPBoolean (com.swiftmq.amqp.v100.types.AMQPBoolean)5 List (java.util.List)4 AMQPException (com.swiftmq.amqp.v100.client.AMQPException)3 Connection (com.swiftmq.amqp.v100.client.Connection)3 Session (com.swiftmq.amqp.v100.client.Session)3