Search in sources :

Example 6 with AMQPException

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"));
    }
}
Also used : DeliveryStateIF(com.swiftmq.amqp.v100.generated.messaging.delivery_state.DeliveryStateIF) Rejected(com.swiftmq.amqp.v100.generated.messaging.delivery_state.Rejected) AMQPBoolean(com.swiftmq.amqp.v100.types.AMQPBoolean) AMQPMessage(com.swiftmq.amqp.v100.messaging.AMQPMessage) AmqpValue(com.swiftmq.amqp.v100.generated.messaging.message_format.AmqpValue)

Example 7 with AMQPException

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());
}
Also used : Semaphore(com.swiftmq.tools.concurrent.Semaphore) POCloseLink(com.swiftmq.amqp.v100.client.po.POCloseLink)

Example 8 with AMQPException

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;
}
Also used : AMQPException(com.swiftmq.amqp.v100.client.AMQPException) AMQPMessage(com.swiftmq.amqp.v100.messaging.AMQPMessage) AMQPException(com.swiftmq.amqp.v100.client.AMQPException) JMSException(javax.jms.JMSException) List(java.util.List) MessageImpl(com.swiftmq.jms.MessageImpl)

Example 9 with AMQPException

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());
        }
    }
}
Also used : AMQPException(com.swiftmq.amqp.v100.client.AMQPException) AMQPMap(com.swiftmq.amqp.v100.types.AMQPMap) MessageEOFException(javax.jms.MessageEOFException) Data(com.swiftmq.amqp.v100.generated.messaging.message_format.Data) AMQPString(com.swiftmq.amqp.v100.types.AMQPString) IOException(java.io.IOException) AmqpSequence(com.swiftmq.amqp.v100.generated.messaging.message_format.AmqpSequence) AmqpValue(com.swiftmq.amqp.v100.generated.messaging.message_format.AmqpValue) AMQPString(com.swiftmq.amqp.v100.types.AMQPString) AMQPMap(com.swiftmq.amqp.v100.types.AMQPMap)

Aggregations

AMQPException (com.swiftmq.amqp.v100.client.AMQPException)4 AMQPMessage (com.swiftmq.amqp.v100.messaging.AMQPMessage)4 AmqpValue (com.swiftmq.amqp.v100.generated.messaging.message_format.AmqpValue)3 Semaphore (com.swiftmq.tools.concurrent.Semaphore)3 IOException (java.io.IOException)3 JMSException (javax.jms.JMSException)3 Milliseconds (com.swiftmq.amqp.v100.generated.transport.definitions.Milliseconds)2 MessageImpl (com.swiftmq.jms.MessageImpl)2 List (java.util.List)2 POAttachDurableConsumer (com.swiftmq.amqp.v100.client.po.POAttachDurableConsumer)1 POCloseLink (com.swiftmq.amqp.v100.client.po.POCloseLink)1 POSendMessage (com.swiftmq.amqp.v100.client.po.POSendMessage)1 DeliveryStateIF (com.swiftmq.amqp.v100.generated.messaging.delivery_state.DeliveryStateIF)1 Rejected (com.swiftmq.amqp.v100.generated.messaging.delivery_state.Rejected)1 AddressString (com.swiftmq.amqp.v100.generated.messaging.message_format.AddressString)1 AmqpSequence (com.swiftmq.amqp.v100.generated.messaging.message_format.AmqpSequence)1 Data (com.swiftmq.amqp.v100.generated.messaging.message_format.Data)1 Header (com.swiftmq.amqp.v100.generated.messaging.message_format.Header)1 MessageIdString (com.swiftmq.amqp.v100.generated.messaging.message_format.MessageIdString)1 Properties (com.swiftmq.amqp.v100.generated.messaging.message_format.Properties)1