use of com.swiftmq.amqp.v100.types.AMQPMap in project swiftmq-client by iitsoftware.
the class BeginFrame method decode.
private void decode() throws Exception {
List l = body.getValue();
AMQPType t = null;
int idx = 0;
// Factory : ./.
if (idx >= l.size())
return;
t = (AMQPType) l.get(idx++);
try {
if (t.getCode() != AMQPTypeDecoder.NULL)
remoteChannel = (AMQPUnsignedShort) t;
} catch (ClassCastException e) {
throw new Exception("Invalid type of field 'remoteChannel' in 'Begin' frame: " + e);
}
// Factory : ./.
if (idx >= l.size())
return;
t = (AMQPType) l.get(idx++);
if (t.getCode() == AMQPTypeDecoder.NULL)
throw new Exception("Mandatory field 'nextOutgoingId' in 'Begin' frame is NULL");
try {
nextOutgoingId = new TransferNumber(((AMQPUnsignedInt) t).getValue());
} catch (ClassCastException e) {
throw new Exception("Invalid type of field 'nextOutgoingId' in 'Begin' frame: " + e);
}
// Factory : ./.
if (idx >= l.size())
return;
t = (AMQPType) l.get(idx++);
if (t.getCode() == AMQPTypeDecoder.NULL)
throw new Exception("Mandatory field 'incomingWindow' in 'Begin' frame is NULL");
try {
incomingWindow = (AMQPUnsignedInt) t;
} catch (ClassCastException e) {
throw new Exception("Invalid type of field 'incomingWindow' in 'Begin' frame: " + e);
}
// Factory : ./.
if (idx >= l.size())
return;
t = (AMQPType) l.get(idx++);
if (t.getCode() == AMQPTypeDecoder.NULL)
throw new Exception("Mandatory field 'outgoingWindow' in 'Begin' frame is NULL");
try {
outgoingWindow = (AMQPUnsignedInt) t;
} catch (ClassCastException e) {
throw new Exception("Invalid type of field 'outgoingWindow' in 'Begin' frame: " + e);
}
// Factory : ./.
if (idx >= l.size())
return;
t = (AMQPType) l.get(idx++);
try {
if (t.getCode() != AMQPTypeDecoder.NULL)
handleMax = new Handle(((AMQPUnsignedInt) t).getValue());
} catch (ClassCastException e) {
throw new Exception("Invalid type of field 'handleMax' in 'Begin' frame: " + e);
}
// Factory : ./.
if (idx >= l.size())
return;
t = (AMQPType) l.get(idx++);
try {
if (t.getCode() != AMQPTypeDecoder.NULL)
offeredCapabilities = AMQPTypeDecoder.isArray(t.getCode()) ? (AMQPArray) t : singleToArray(t);
} catch (ClassCastException e) {
throw new Exception("Invalid type of field 'offeredCapabilities' in 'Begin' frame: " + e);
}
// Factory : ./.
if (idx >= l.size())
return;
t = (AMQPType) l.get(idx++);
try {
if (t.getCode() != AMQPTypeDecoder.NULL)
desiredCapabilities = AMQPTypeDecoder.isArray(t.getCode()) ? (AMQPArray) t : singleToArray(t);
} catch (ClassCastException e) {
throw new Exception("Invalid type of field 'desiredCapabilities' in 'Begin' frame: " + e);
}
// Factory : ./.
if (idx >= l.size())
return;
t = (AMQPType) l.get(idx++);
try {
if (t.getCode() != AMQPTypeDecoder.NULL)
properties = new Fields(((AMQPMap) t).getValue());
} catch (ClassCastException e) {
throw new Exception("Invalid type of field 'properties' in 'Begin' frame: " + e);
}
}
use of com.swiftmq.amqp.v100.types.AMQPMap 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.AMQPMap in project swiftmq-client by iitsoftware.
the class AMQPRepo method remove.
AMQPRepo remove(String appname) throws Exception {
AMQPMessage request = new AMQPMessage();
Map propMap = new HashMap();
propMap.put(new AMQPString("app"), new AMQPString(appname));
propMap.put(new AMQPString("operation"), new AMQPString("remove"));
request.setApplicationProperties(new ApplicationProperties(propMap));
Properties properties = new Properties();
properties.setReplyTo(replyQueue);
request.setProperties(properties);
producer.send(request);
AMQPMessage reply = consumer.receive(TIMEOUT);
if (reply == null)
throw new Exception("Timeout occurred while waiting for a reply!");
AMQPMap body = (AMQPMap) reply.getAmqpValue().getValue();
boolean success = ((AMQPBoolean) (body.getValue().get(new AMQPString("success")))).getValue();
if (success)
System.out.println("Removed repository " + appname);
else {
String result = ((AMQPString) (body.getValue().get(new AMQPString("result")))).getValue();
System.out.println(result);
}
return this;
}
use of com.swiftmq.amqp.v100.types.AMQPMap in project swiftmq-ce by iitsoftware.
the class AMQPValueMapMessageFactory method createReplyMessage.
public AMQPMessage createReplyMessage(AMQPMessage request) throws Exception {
AMQPMessage reply = new AMQPMessage();
Map map = ((AMQPMap) request.getAmqpValue().getValue()).getValue();
map.put(new AMQPString("REPLY"), new AMQPString("REPLY"));
reply.setAmqpValue(new AmqpValue(new AMQPMap(map)));
return reply;
}
use of com.swiftmq.amqp.v100.types.AMQPMap 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();
}
Aggregations