use of com.swiftmq.amqp.v100.client.AMQPException in project swiftmq-client by iitsoftware.
the class TransactionController method discharge.
private synchronized void discharge(TxnIdIF txnId, boolean fail) throws AMQPException {
AMQPMessage msg = new AMQPMessage();
Discharge discharge = new Discharge();
discharge.setTxnId(txnId);
discharge.setFail(new AMQPBoolean(fail));
msg.setAmqpValue(new AmqpValue(discharge));
DeliveryStateIF deliveryState = producer.send(msg);
if (deliveryState instanceof Rejected) {
Rejected rejected = (Rejected) deliveryState;
com.swiftmq.amqp.v100.generated.transport.definitions.Error error = rejected.getError();
if (error != null)
throw new AMQPException(error.getValueString());
else
throw new AMQPException(("Unknown transactiom error"));
}
}
use of com.swiftmq.amqp.v100.client.AMQPException in project swiftmq-client by iitsoftware.
the class Link method close.
/**
* Close this link.
*
* @throws AMQPException on error
*/
public void close() throws AMQPException {
if (closed)
return;
Semaphore sem = new Semaphore();
POCloseLink po = new POCloseLink(sem, this);
mySession.getSessionDispatcher().dispatch(po);
sem.waitHere();
mySession.detach(this);
closed = true;
if (!po.isSuccess())
throw new AMQPException(po.getException());
}
use of com.swiftmq.amqp.v100.client.AMQPException in project swiftmq-ce by iitsoftware.
the class JMSMappingInboundTransformer method transform.
public MessageImpl transform(TransferFrame frame, DestinationFactory destinationFactory) throws AMQPException, JMSException {
jmsTypeProp = getValue(PROP_JMS_TYPE, null);
MessageImpl jmsMessage = null;
try {
AMQPMessage amqpMessage = null;
if (frame.getMorePayloads() != null) {
List morePayloads = frame.getMorePayloads();
byte[][] b = new byte[morePayloads.size() + 1][];
b[0] = frame.getPayload();
for (int i = 0; i < morePayloads.size(); i++) b[i + 1] = (byte[]) morePayloads.get(i);
amqpMessage = new AMQPMessage(b, frame.getPayloadLength());
} else
amqpMessage = new AMQPMessage(frame.getPayload());
jmsMessage = messageFactory.create(amqpMessage);
jmsMessage.setLongProperty(prefixVendor + Util.PROP_MESSAGE_FORMAT, frame.getMessageFormat().getValue());
jmsMessage.setBooleanProperty(amqpNative, false);
Header header = amqpMessage.getHeader();
if (header != null)
transformHeader(header, jmsMessage);
DeliveryAnnotations deliveryAnnotations = amqpMessage.getDeliveryAnnotations();
if (deliveryAnnotations != null)
transformMap(deliveryAnnotations.getValue(), jmsMessage, prefixDA);
MessageAnnotations messageAnnotations = amqpMessage.getMessageAnnotations();
if (messageAnnotations != null)
transformMap(messageAnnotations.getValue(), jmsMessage, prefixMA);
Properties properties = amqpMessage.getProperties();
if (properties != null)
transformProperties(properties, jmsMessage, destinationFactory);
ApplicationProperties applicationProperties = amqpMessage.getApplicationProperties();
if (applicationProperties != null)
transformApplicationProperties(applicationProperties, jmsMessage);
Footer footer = amqpMessage.getFooter();
if (footer != null)
transformMap(footer.getValue(), jmsMessage, prefixFT);
} catch (Exception e) {
throw new AMQPException(e.toString());
}
jmsMessage.reset();
return jmsMessage;
}
use of com.swiftmq.amqp.v100.client.AMQPException in project swiftmq-ce by iitsoftware.
the class MessageTypeBodyFactory method createBody.
public void createBody(MessageImpl jmsMessage, AMQPMessage amqpMessage) throws JMSException, AMQPException {
jmsMessage.reset();
if (jmsMessage instanceof TextMessageImpl) {
amqpMessage.setAmqpValue(new AmqpValue(new AMQPString(((TextMessageImpl) jmsMessage).getText())));
} else if (jmsMessage instanceof MapMessageImpl) {
MapMessageImpl msg = (MapMessageImpl) jmsMessage;
Map map = new HashMap();
for (Enumeration _enum = msg.getMapNames(); _enum.hasMoreElements(); ) {
String name = (String) _enum.nextElement();
map.put(new AMQPString(name), Util.convertJMStoAMQP(msg.getObject(name)));
}
try {
amqpMessage.setAmqpValue(new AmqpValue(new AMQPMap(map)));
} catch (IOException e) {
throw new AMQPException(e.toString());
}
} else if (jmsMessage instanceof BytesMessageImpl) {
BytesMessageImpl msg = (BytesMessageImpl) jmsMessage;
byte[] b = new byte[(int) msg.getBodyLength()];
msg.readBytes(b);
amqpMessage.addData(new Data(b));
} else if (jmsMessage instanceof ObjectMessageImpl) {
amqpMessage.setAmqpValue(new AmqpValue(Util.convertJMStoAMQP(((ObjectMessageImpl) jmsMessage).getObject())));
} else if (jmsMessage instanceof StreamMessageImpl) {
List list = new ArrayList();
StreamMessageImpl msg = (StreamMessageImpl) jmsMessage;
try {
for (; ; ) {
list.add(Util.convertJMStoAMQP(msg.readObject()));
}
} catch (MessageEOFException e) {
}
try {
amqpMessage.addAmqpSequence(new AmqpSequence(list));
} catch (IOException e) {
throw new AMQPException(e.toString());
}
}
}
Aggregations