Search in sources :

Example 1 with AMQPType

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

the class AMQPValueMapMessageFactory 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 AMQPMap))
        throw new Exception(("verify - AmqpValue does not contain an AmqpMap!"));
    Map map = ((AMQPMap) message.getAmqpValue().getValue()).getValue();
    for (Iterator iter = map.entrySet().iterator(); iter.hasNext(); ) {
        Map.Entry entry = (Map.Entry) iter.next();
        if (!((entry.getKey() instanceof AMQPString && ((AMQPString) entry.getKey()).getValue().equals("key1")) || (entry.getKey() instanceof AMQPString && ((AMQPString) entry.getKey()).getValue().equals("key3")) || (entry.getKey() instanceof AMQPString && ((AMQPString) entry.getKey()).getValue().equals("REPLY")) || (entry.getKey() instanceof AMQPString && ((AMQPString) entry.getKey()).getValue().equals(String.valueOf(Integer.MAX_VALUE + 1))) || (entry.getKey() instanceof AMQPString && ((AMQPString) entry.getKey()).getValue().equals(String.valueOf(Integer.MAX_VALUE + 2))) || (entry.getKey() instanceof AMQPLong && ((AMQPLong) entry.getKey()).getValue() == Integer.MAX_VALUE + 1) || (entry.getKey() instanceof AMQPLong && ((AMQPLong) entry.getKey()).getValue() == Integer.MAX_VALUE + 2))) {
            System.out.println(map);
            throw new Exception("verify - invalid values in map detected: " + map);
        }
    }
}
Also used : AMQPType(com.swiftmq.amqp.v100.types.AMQPType) AMQPMap(com.swiftmq.amqp.v100.types.AMQPMap) AMQPLong(com.swiftmq.amqp.v100.types.AMQPLong) Iterator(java.util.Iterator) AMQPString(com.swiftmq.amqp.v100.types.AMQPString) AMQPMap(com.swiftmq.amqp.v100.types.AMQPMap) Map(java.util.Map) HashMap(java.util.HashMap) AmqpValue(com.swiftmq.amqp.v100.generated.messaging.message_format.AmqpValue)

Example 2 with AMQPType

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

the class TargetLink method handleTransactionRequest.

private void handleTransactionRequest(TransferFrame frame) throws EndWithErrorException {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + "/handleTransactionRequest, frame=" + frame);
    AMQPMessage msg = null;
    try {
        msg = new AMQPMessage(frame.getPayload());
    } catch (Exception e) {
        e.printStackTrace();
        new SessionEndException(AmqpError.DECODE_ERROR, new AMQPString("Exception during decode of a message: " + e));
    }
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + "/handleTransactionRequest, msg=" + msg);
    if (msg.getAmqpValue() == null)
        throw new SessionEndException(AmqpError.NOT_FOUND, new AMQPString("Missing amqp-value message body in transaction request!"));
    AMQPType bare = msg.getAmqpValue().getValue();
    AMQPDescribedConstructor constructor = bare.getConstructor();
    if (constructor == null)
        throw new SessionEndException(AmqpError.DECODE_ERROR, new AMQPString("Missing constructor: " + bare));
    if (!AMQPTypeDecoder.isList(constructor.getFormatCode()))
        throw new SessionEndException(AmqpError.DECODE_ERROR, new AMQPString("Message body is not of a list type, code=0x" + Integer.toHexString(bare.getCode()) + ", bare=" + bare));
    AMQPType descriptor = constructor.getDescriptor();
    int code = descriptor.getCode();
    try {
        if (AMQPTypeDecoder.isULong(code)) {
            long type = ((AMQPUnsignedLong) descriptor).getValue();
            if (type == Declare.DESCRIPTOR_CODE)
                handleDeclare(new Declare(((AMQPList) bare).getValue()));
            else if (type == Discharge.DESCRIPTOR_CODE)
                handleDischarge(new Discharge(((AMQPList) bare).getValue()));
            else
                throw new SessionEndException(AmqpError.DECODE_ERROR, new AMQPString("Invalid descriptor type: " + type + ", bare=" + bare));
        } else if (AMQPTypeDecoder.isSymbol(code)) {
            String type = ((AMQPSymbol) descriptor).getValue();
            if (type.equals(Declare.DESCRIPTOR_NAME))
                handleDeclare(new Declare(((AMQPList) bare).getValue()));
            else if (type.equals(Discharge.DESCRIPTOR_NAME))
                handleDischarge(new Discharge(((AMQPList) bare).getValue()));
            else
                throw new SessionEndException(AmqpError.DECODE_ERROR, new AMQPString("Invalid descriptor type: " + type + ", bare=" + bare));
        } else
            throw new SessionEndException(AmqpError.DECODE_ERROR, new AMQPString("Invalid type of constructor descriptor (actual type=" + code + ", expected=symbold or ulong), bare= " + bare));
    } catch (Exception e) {
        e.printStackTrace();
        throw new SessionEndException(AmqpError.DECODE_ERROR, new AMQPString(e.toString()));
    }
}
Also used : AddressString(com.swiftmq.amqp.v100.generated.messaging.message_format.AddressString) AMQPMessage(com.swiftmq.amqp.v100.messaging.AMQPMessage) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) AuthenticationException(com.swiftmq.swiftlet.auth.AuthenticationException) QueueException(com.swiftmq.swiftlet.queue.QueueException) InvalidSelectorException(javax.jms.InvalidSelectorException) TopicException(com.swiftmq.swiftlet.topic.TopicException)

Example 3 with AMQPType

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

the class Properties method decode.

private void decode() throws Exception {
    List l = getValue();
    AMQPType t = null;
    int idx = 0;
    // Factory  : MessageIdFactory
    if (idx >= l.size())
        return;
    t = (AMQPType) l.get(idx++);
    if (t.getCode() != AMQPTypeDecoder.NULL)
        messageId = MessageIdFactory.create(t);
    // Factory  : ./.
    if (idx >= l.size())
        return;
    t = (AMQPType) l.get(idx++);
    try {
        if (t.getCode() != AMQPTypeDecoder.NULL)
            userId = (AMQPBinary) t;
    } catch (ClassCastException e) {
        throw new Exception("Invalid type of field 'userId' in 'Properties' type: " + e);
    }
    // Factory  : AddressFactory
    if (idx >= l.size())
        return;
    t = (AMQPType) l.get(idx++);
    if (t.getCode() != AMQPTypeDecoder.NULL)
        to = AddressFactory.create(t);
    // Factory  : ./.
    if (idx >= l.size())
        return;
    t = (AMQPType) l.get(idx++);
    try {
        if (t.getCode() != AMQPTypeDecoder.NULL)
            subject = (AMQPString) t;
    } catch (ClassCastException e) {
        throw new Exception("Invalid type of field 'subject' in 'Properties' type: " + e);
    }
    // Factory  : AddressFactory
    if (idx >= l.size())
        return;
    t = (AMQPType) l.get(idx++);
    if (t.getCode() != AMQPTypeDecoder.NULL)
        replyTo = AddressFactory.create(t);
    // Factory  : MessageIdFactory
    if (idx >= l.size())
        return;
    t = (AMQPType) l.get(idx++);
    if (t.getCode() != AMQPTypeDecoder.NULL)
        correlationId = MessageIdFactory.create(t);
    // Factory  : ./.
    if (idx >= l.size())
        return;
    t = (AMQPType) l.get(idx++);
    try {
        if (t.getCode() != AMQPTypeDecoder.NULL)
            contentType = (AMQPSymbol) t;
    } catch (ClassCastException e) {
        throw new Exception("Invalid type of field 'contentType' in 'Properties' type: " + e);
    }
    // Factory  : ./.
    if (idx >= l.size())
        return;
    t = (AMQPType) l.get(idx++);
    try {
        if (t.getCode() != AMQPTypeDecoder.NULL)
            contentEncoding = (AMQPSymbol) t;
    } catch (ClassCastException e) {
        throw new Exception("Invalid type of field 'contentEncoding' in 'Properties' type: " + e);
    }
    // Factory  : ./.
    if (idx >= l.size())
        return;
    t = (AMQPType) l.get(idx++);
    try {
        if (t.getCode() != AMQPTypeDecoder.NULL)
            absoluteExpiryTime = (AMQPTimestamp) t;
    } catch (ClassCastException e) {
        throw new Exception("Invalid type of field 'absoluteExpiryTime' in 'Properties' type: " + e);
    }
    // Factory  : ./.
    if (idx >= l.size())
        return;
    t = (AMQPType) l.get(idx++);
    try {
        if (t.getCode() != AMQPTypeDecoder.NULL)
            creationTime = (AMQPTimestamp) t;
    } catch (ClassCastException e) {
        throw new Exception("Invalid type of field 'creationTime' in 'Properties' type: " + e);
    }
    // Factory  : ./.
    if (idx >= l.size())
        return;
    t = (AMQPType) l.get(idx++);
    try {
        if (t.getCode() != AMQPTypeDecoder.NULL)
            groupId = (AMQPString) t;
    } catch (ClassCastException e) {
        throw new Exception("Invalid type of field 'groupId' in 'Properties' type: " + e);
    }
    // Factory  : ./.
    if (idx >= l.size())
        return;
    t = (AMQPType) l.get(idx++);
    try {
        if (t.getCode() != AMQPTypeDecoder.NULL)
            groupSequence = new SequenceNo(((AMQPUnsignedInt) t).getValue());
    } catch (ClassCastException e) {
        throw new Exception("Invalid type of field 'groupSequence' in 'Properties' type: " + e);
    }
    // Factory  : ./.
    if (idx >= l.size())
        return;
    t = (AMQPType) l.get(idx++);
    try {
        if (t.getCode() != AMQPTypeDecoder.NULL)
            replyToGroupId = (AMQPString) t;
    } catch (ClassCastException e) {
        throw new Exception("Invalid type of field 'replyToGroupId' in 'Properties' type: " + e);
    }
}
Also used : SequenceNo(com.swiftmq.amqp.v100.generated.transport.definitions.SequenceNo) List(java.util.List) ArrayList(java.util.ArrayList) IOException(java.io.IOException)

Example 4 with AMQPType

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

the class DeliveryStateFactory method create.

/**
 * Creates a DeliveryStateIF object.
 *
 * @param bare the bare AMQP type
 * @return DeliveryStateIF
 */
public static DeliveryStateIF 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 == Received.DESCRIPTOR_CODE)
            return new Received(((AMQPList) bare).getValue());
        if (type == Accepted.DESCRIPTOR_CODE)
            return new Accepted(((AMQPList) bare).getValue());
        if (type == Rejected.DESCRIPTOR_CODE)
            return new Rejected(((AMQPList) bare).getValue());
        if (type == Released.DESCRIPTOR_CODE)
            return new Released(((AMQPList) bare).getValue());
        if (type == Modified.DESCRIPTOR_CODE)
            return new Modified(((AMQPList) bare).getValue());
        if (type == Declared.DESCRIPTOR_CODE)
            return new Declared(((AMQPList) bare).getValue());
        if (type == TransactionalState.DESCRIPTOR_CODE)
            return new TransactionalState(((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(Received.DESCRIPTOR_NAME))
            return new Received(((AMQPList) bare).getValue());
        if (type.equals(Accepted.DESCRIPTOR_NAME))
            return new Accepted(((AMQPList) bare).getValue());
        if (type.equals(Rejected.DESCRIPTOR_NAME))
            return new Rejected(((AMQPList) bare).getValue());
        if (type.equals(Released.DESCRIPTOR_NAME))
            return new Released(((AMQPList) bare).getValue());
        if (type.equals(Modified.DESCRIPTOR_NAME))
            return new Modified(((AMQPList) bare).getValue());
        if (type.equals(Declared.DESCRIPTOR_NAME))
            return new Declared(((AMQPList) bare).getValue());
        if (type.equals(TransactionalState.DESCRIPTOR_NAME))
            return new TransactionalState(((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) Declared(com.swiftmq.amqp.v100.generated.transactions.coordination.Declared) IOException(java.io.IOException) TransactionalState(com.swiftmq.amqp.v100.generated.transactions.coordination.TransactionalState)

Example 5 with AMQPType

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

the class OutcomeFactory method create.

/**
 * Creates a OutcomeIF object.
 *
 * @param bare the bare AMQP type
 * @return OutcomeIF
 */
public static OutcomeIF 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 == Accepted.DESCRIPTOR_CODE)
            return new Accepted(((AMQPList) bare).getValue());
        if (type == Rejected.DESCRIPTOR_CODE)
            return new Rejected(((AMQPList) bare).getValue());
        if (type == Released.DESCRIPTOR_CODE)
            return new Released(((AMQPList) bare).getValue());
        if (type == Modified.DESCRIPTOR_CODE)
            return new Modified(((AMQPList) bare).getValue());
        if (type == Declared.DESCRIPTOR_CODE)
            return new Declared(((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(Accepted.DESCRIPTOR_NAME))
            return new Accepted(((AMQPList) bare).getValue());
        if (type.equals(Rejected.DESCRIPTOR_NAME))
            return new Rejected(((AMQPList) bare).getValue());
        if (type.equals(Released.DESCRIPTOR_NAME))
            return new Released(((AMQPList) bare).getValue());
        if (type.equals(Modified.DESCRIPTOR_NAME))
            return new Modified(((AMQPList) bare).getValue());
        if (type.equals(Declared.DESCRIPTOR_NAME))
            return new Declared(((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) Declared(com.swiftmq.amqp.v100.generated.transactions.coordination.Declared) IOException(java.io.IOException)

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