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);
}
}
}
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()));
}
}
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);
}
}
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);
}
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);
}
Aggregations