Search in sources :

Example 1 with AmqpSequence

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

the class AMQPSequenceMessageFactory method createReplyMessage.

public AMQPMessage createReplyMessage(AMQPMessage request) throws Exception {
    AMQPMessage reply = new AMQPMessage();
    List list = request.getAmqpSequence();
    ((AmqpSequence) list.get(0)).getValue().add(new AMQPString("REPLY"));
    for (int i = 0; i < list.size(); i++) reply.addAmqpSequence(((AmqpSequence) list.get(i)));
    return reply;
}
Also used : List(java.util.List) ArrayList(java.util.ArrayList) AMQPString(com.swiftmq.amqp.v100.types.AMQPString) AMQPMessage(com.swiftmq.amqp.v100.messaging.AMQPMessage)

Example 2 with AmqpSequence

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

the class AMQPSequenceMessageFactory method create.

public AMQPMessage create(int sequenceNo) throws Exception {
    AMQPMessage msg = new AMQPMessage();
    List list = new ArrayList();
    list.add(new AMQPString("key1"));
    list.add(new AMQPLong(Integer.MAX_VALUE + 1));
    list.add(new AMQPString("key3"));
    list.add(new AMQPLong(Integer.MAX_VALUE + 2));
    msg.addAmqpSequence(new AmqpSequence(list));
    return msg;
}
Also used : AMQPLong(com.swiftmq.amqp.v100.types.AMQPLong) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) AMQPString(com.swiftmq.amqp.v100.types.AMQPString) AMQPMessage(com.swiftmq.amqp.v100.messaging.AMQPMessage) AmqpSequence(com.swiftmq.amqp.v100.generated.messaging.message_format.AmqpSequence)

Example 3 with AmqpSequence

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

the class BodyTypeMessageFactory method create.

public MessageImpl create(AMQPMessage source) throws Exception {
    List data = source.getData();
    if (data != null && data.size() > 0) {
        if (data.size() == 1) {
            byte[] b = ((Data) data.get(0)).getValue();
            return new BytesMessageImpl(b, b.length);
        } else {
            BytesMessageImpl msg = new BytesMessageImpl();
            for (int i = 0; i < data.size(); i++) {
                msg.writeBytes(((Data) data.get(i)).getValue());
            }
            return msg;
        }
    }
    List sequenceList = source.getAmqpSequence();
    if (sequenceList != null && sequenceList.size() > 0) {
        StreamMessageImpl msg = new StreamMessageImpl();
        for (int i = 0; i < sequenceList.size(); i++) {
            AmqpSequence seq = (AmqpSequence) sequenceList.get(i);
            List list = seq.getValue();
            if (list != null && list.size() > 0) {
                for (int j = 0; j < list.size(); j++) {
                    try {
                        msg.writeObject(Util.convertAMQPtoJMS((AMQPType) list.get(j)));
                    } catch (Exception e) {
                        msg.setBooleanProperty(PROP_ERROR, true);
                        msg.setStringProperty(PROP_ERROR_CAUSE, e.toString());
                        break;
                    }
                }
            }
        }
        return msg;
    }
    AmqpValue amqpValue = source.getAmqpValue();
    if (amqpValue != null) {
        AMQPType value = amqpValue.getValue();
        AMQPDescribedConstructor constructor = value.getConstructor();
        int code = constructor != null ? constructor.getFormatCode() : value.getCode();
        if (AMQPTypeDecoder.isSymbol(code) || AMQPTypeDecoder.isString(code)) {
            TextMessageImpl msg = new TextMessageImpl();
            msg.setText((String) Util.convertAMQPtoJMS(value));
            return msg;
        }
        if (AMQPTypeDecoder.isBinary(code)) {
            byte[] b = ((AMQPBinary) value).getValue();
            return new BytesMessageImpl(b, b.length);
        }
        if (AMQPTypeDecoder.isList(code)) {
            StreamMessageImpl msg = new StreamMessageImpl();
            List list = ((AMQPList) value).getValue();
            for (int i = 0; i < list.size(); i++) {
                try {
                    msg.writeObject(Util.convertAMQPtoJMS((AMQPType) list.get(i)));
                } catch (Exception e) {
                    msg.setBooleanProperty(PROP_ERROR, true);
                    msg.setStringProperty(PROP_ERROR_CAUSE, e.toString());
                    break;
                }
            }
            return msg;
        }
        if (AMQPTypeDecoder.isMap(code)) {
            MapMessageImpl msg = new MapMessageImpl();
            Map map = ((AMQPMap) value).getValue();
            for (Iterator iter = map.entrySet().iterator(); iter.hasNext(); ) {
                Map.Entry entry = (Map.Entry) iter.next();
                try {
                    String name = Util.convertAMQPtoJMS((AMQPType) entry.getKey()).toString();
                    msg.setObject(name, Util.convertAMQPtoJMS((AMQPType) entry.getValue()));
                } catch (Exception e) {
                    msg.setBooleanProperty(PROP_ERROR, true);
                    msg.setStringProperty(PROP_ERROR_CAUSE, e.toString());
                    break;
                }
            }
            return msg;
        }
        // Everything else is a ObjectMessage
        ObjectMessageImpl msg = new ObjectMessageImpl();
        try {
            msg.setObject((Serializable) Util.convertAMQPtoJMS(value));
        } catch (Exception e) {
            msg.setBooleanProperty(PROP_ERROR, true);
            msg.setStringProperty(PROP_ERROR_CAUSE, e.toString());
        }
        return msg;
    }
    return new MessageImpl();
}
Also used : Data(com.swiftmq.amqp.v100.generated.messaging.message_format.Data) AmqpSequence(com.swiftmq.amqp.v100.generated.messaging.message_format.AmqpSequence) AmqpValue(com.swiftmq.amqp.v100.generated.messaging.message_format.AmqpValue) Iterator(java.util.Iterator) List(java.util.List) Map(java.util.Map)

Example 4 with AmqpSequence

use of com.swiftmq.amqp.v100.generated.messaging.message_format.AmqpSequence 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)

Aggregations

AmqpSequence (com.swiftmq.amqp.v100.generated.messaging.message_format.AmqpSequence)3 AMQPString (com.swiftmq.amqp.v100.types.AMQPString)3 List (java.util.List)3 AmqpValue (com.swiftmq.amqp.v100.generated.messaging.message_format.AmqpValue)2 Data (com.swiftmq.amqp.v100.generated.messaging.message_format.Data)2 AMQPMessage (com.swiftmq.amqp.v100.messaging.AMQPMessage)2 ArrayList (java.util.ArrayList)2 AMQPException (com.swiftmq.amqp.v100.client.AMQPException)1 AMQPLong (com.swiftmq.amqp.v100.types.AMQPLong)1 AMQPMap (com.swiftmq.amqp.v100.types.AMQPMap)1 IOException (java.io.IOException)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 MessageEOFException (javax.jms.MessageEOFException)1