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