Search in sources :

Example 21 with AMQPType

use of com.swiftmq.amqp.v100.types.AMQPType in project swiftmq-client by iitsoftware.

the class Modified method decode.

private void decode() throws Exception {
    List l = getValue();
    AMQPType t = null;
    int idx = 0;
    // Factory  : ./.
    if (idx >= l.size())
        return;
    t = (AMQPType) l.get(idx++);
    try {
        if (t.getCode() != AMQPTypeDecoder.NULL)
            deliveryFailed = (AMQPBoolean) t;
    } catch (ClassCastException e) {
        throw new Exception("Invalid type of field 'deliveryFailed' in 'Modified' type: " + e);
    }
    // Factory  : ./.
    if (idx >= l.size())
        return;
    t = (AMQPType) l.get(idx++);
    try {
        if (t.getCode() != AMQPTypeDecoder.NULL)
            undeliverableHere = (AMQPBoolean) t;
    } catch (ClassCastException e) {
        throw new Exception("Invalid type of field 'undeliverableHere' in 'Modified' type: " + e);
    }
    // Factory  : ./.
    if (idx >= l.size())
        return;
    t = (AMQPType) l.get(idx++);
    try {
        if (t.getCode() != AMQPTypeDecoder.NULL)
            messageAnnotations = new Fields(((AMQPMap) t).getValue());
    } catch (ClassCastException e) {
        throw new Exception("Invalid type of field 'messageAnnotations' in 'Modified' type: " + e);
    }
}
Also used : Fields(com.swiftmq.amqp.v100.generated.transport.definitions.Fields) List(java.util.List) ArrayList(java.util.ArrayList) IOException(java.io.IOException)

Example 22 with AMQPType

use of com.swiftmq.amqp.v100.types.AMQPType in project swiftmq-ce by iitsoftware.

the class AMQPValueByteMessageFactory method verify.

public void verify(AMQPMessage message) throws Exception {
    AmqpValue value = message.getAmqpValue();
    if (value == null)
        throw new Exception(("verify - no AmqpValue section found!"));
    AMQPType t = value.getValue();
    if (!(t instanceof AMQPByte))
        throw new Exception(("verify - AmqpValue does not contain an AmqpByte!"));
    if (((AMQPByte) t).getValue() != (byte) 100)
        throw new Exception("verify - invalid value: " + ((AMQPByte) t).getValue());
}
Also used : AMQPType(com.swiftmq.amqp.v100.types.AMQPType) AMQPByte(com.swiftmq.amqp.v100.types.AMQPByte) AmqpValue(com.swiftmq.amqp.v100.generated.messaging.message_format.AmqpValue)

Example 23 with AMQPType

use of com.swiftmq.amqp.v100.types.AMQPType in project swiftmq-client by iitsoftware.

the class TargetFactory method create.

/**
 * Creates a TargetIF object.
 *
 * @param bare the bare AMQP type
 * @return TargetIF
 */
public static TargetIF create(AMQPType bare) throws Exception {
    if (bare.getCode() == AMQPTypeDecoder.NULL)
        return null;
    AMQPDescribedConstructor constructor = bare.getConstructor();
    if (constructor == null)
        throw new IOException("Missing constructor: " + bare);
    AMQPType descriptor = constructor.getDescriptor();
    int code = descriptor.getCode();
    if (AMQPTypeDecoder.isULong(code)) {
        long type = ((AMQPUnsignedLong) descriptor).getValue();
        if (type == Target.DESCRIPTOR_CODE)
            return new Target(((AMQPList) bare).getValue());
        if (type == Coordinator.DESCRIPTOR_CODE)
            return new Coordinator(((AMQPList) bare).getValue());
        throw new Exception("Invalid descriptor type: " + type + ", bare=" + bare);
    } else if (AMQPTypeDecoder.isSymbol(code)) {
        String type = ((AMQPSymbol) descriptor).getValue();
        if (type.equals(Target.DESCRIPTOR_NAME))
            return new Target(((AMQPList) bare).getValue());
        if (type.equals(Coordinator.DESCRIPTOR_NAME))
            return new Coordinator(((AMQPList) bare).getValue());
        throw new Exception("Invalid descriptor type: " + type + ", bare=" + bare);
    } else
        throw new Exception("Invalid type of constructor descriptor (actual type=" + code + ", expected=symbold or ulong), bare= " + bare);
}
Also used : IOException(java.io.IOException) Coordinator(com.swiftmq.amqp.v100.generated.transactions.coordination.Coordinator) IOException(java.io.IOException)

Example 24 with AMQPType

use of com.swiftmq.amqp.v100.types.AMQPType 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 25 with AMQPType

use of com.swiftmq.amqp.v100.types.AMQPType in project swiftmq-ce by iitsoftware.

the class JMSMappingInboundTransformer method transformApplicationProperties.

protected void transformApplicationProperties(ApplicationProperties applicationProperties, MessageImpl jmsMessage) throws Exception {
    Map map = applicationProperties.getValue();
    for (Iterator iter = map.entrySet().iterator(); iter.hasNext(); ) {
        Map.Entry entry = (Map.Entry) iter.next();
        AMQPType key = (AMQPType) entry.getKey();
        AMQPDescribedConstructor constructor = key.getConstructor();
        int code = constructor != null ? constructor.getFormatCode() : key.getCode();
        String propName = null;
        if (AMQPTypeDecoder.isString(code))
            propName = nameTranslator.translate(((AMQPString) key).getValue());
        else if (AMQPTypeDecoder.isSymbol(code))
            propName = nameTranslator.translate(((AMQPSymbol) key).getValue());
        if (propName != null) {
            if (jmsTypeProp != null && propName.equals(jmsTypeProp)) {
                AMQPType t = (AMQPType) entry.getValue();
                if (AMQPTypeDecoder.isString(t.getCode()))
                    jmsMessage.setJMSType(((AMQPString) entry.getValue()).getValue());
                else
                    jmsMessage.setStringProperty("JMS_TYPE_ERROR", jmsTypeProp + " must be of String value");
            } else {
                try {
                    jmsMessage.setObjectProperty(propName, Util.convertAMQPtoJMS((AMQPType) entry.getValue()));
                } catch (Exception e) {
                    jmsMessage.setStringProperty(propName + "_ERROR", e.getMessage());
                }
            }
        }
    }
}
Also used : Iterator(java.util.Iterator) Map(java.util.Map) AMQPException(com.swiftmq.amqp.v100.client.AMQPException) JMSException(javax.jms.JMSException)

Aggregations

IOException (java.io.IOException)20 List (java.util.List)14 ArrayList (java.util.ArrayList)13 Map (java.util.Map)6 Iterator (java.util.Iterator)5 AmqpValue (com.swiftmq.amqp.v100.generated.messaging.message_format.AmqpValue)4 Error (com.swiftmq.amqp.v100.generated.transport.definitions.Error)4 Fields (com.swiftmq.amqp.v100.generated.transport.definitions.Fields)4 AMQPMessage (com.swiftmq.amqp.v100.messaging.AMQPMessage)4 Handle (com.swiftmq.amqp.v100.generated.transport.definitions.Handle)3 SequenceNo (com.swiftmq.amqp.v100.generated.transport.definitions.SequenceNo)3 AMQPType (com.swiftmq.amqp.v100.types.AMQPType)3 AMQPException (com.swiftmq.amqp.v100.client.AMQPException)2 AddressString (com.swiftmq.amqp.v100.generated.messaging.message_format.AddressString)2 Coordinator (com.swiftmq.amqp.v100.generated.transactions.coordination.Coordinator)2 Declared (com.swiftmq.amqp.v100.generated.transactions.coordination.Declared)2 Milliseconds (com.swiftmq.amqp.v100.generated.transport.definitions.Milliseconds)2 Seconds (com.swiftmq.amqp.v100.generated.transport.definitions.Seconds)2 TransferNumber (com.swiftmq.amqp.v100.generated.transport.definitions.TransferNumber)2 AMQPString (com.swiftmq.amqp.v100.types.AMQPString)2