Search in sources :

Example 1 with JmsMessageException

use of com.axway.ats.action.exceptions.JmsMessageException in project ats-framework by Axway.

the class JmsClient method sendTextMessage.

private void sendTextMessage(final Connection connection, final Destination destination, final String textMessage, final Map<String, ?> properties) {
    try {
        final Session session = loadSession(false, Session.AUTO_ACKNOWLEDGE);
        doSendTextMessage(session, destination, textMessage, properties);
    } catch (Exception e) {
        throw new JmsMessageException("Failed to send message", e);
    }
}
Also used : JmsMessageException(com.axway.ats.action.exceptions.JmsMessageException) NamingException(javax.naming.NamingException) JMSException(javax.jms.JMSException) JmsMessageException(com.axway.ats.action.exceptions.JmsMessageException) Session(javax.jms.Session) ManagedSession(com.axway.ats.action.jms.model.sessions.ManagedSession)

Example 2 with JmsMessageException

use of com.axway.ats.action.exceptions.JmsMessageException in project ats-framework by Axway.

the class JmsClient method createTopic.

/**
     * Create a topic
     * 
     * @param topicName the topic name
     */
@PublicAtsApi
public void createTopic(final String topicName) {
    try {
        final Session session = loadSession(false, Session.AUTO_ACKNOWLEDGE);
        final Topic topic = session.createTopic(topicName);
        session.createConsumer(topic).close();
    } catch (JMSException e) {
        throw new JmsMessageException("Could not start listening for messages on topic " + topicName, e);
    } finally {
        releaseSession(false);
    }
}
Also used : JmsMessageException(com.axway.ats.action.exceptions.JmsMessageException) JMSException(javax.jms.JMSException) Topic(javax.jms.Topic) Session(javax.jms.Session) ManagedSession(com.axway.ats.action.jms.model.sessions.ManagedSession) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 3 with JmsMessageException

use of com.axway.ats.action.exceptions.JmsMessageException in project ats-framework by Axway.

the class JmsClient method startListeningToTopic.

/**
     * Start listening for messages on topic
     * 
     * @param topicName the topic name
     */
@PublicAtsApi
public void startListeningToTopic(final String topicName) {
    final TopicInfo topicInfo = getTopicInfo(topicName);
    if (topicInfo.isListening()) {
        throw new JmsMessageException("We are already listening for messages on topic " + topicName);
    }
    try {
        final Session session = loadSession(false, Session.AUTO_ACKNOWLEDGE);
        final Topic topic = session.createTopic(topicName);
        topicInfo.topicConsumer = session.createConsumer(topic);
        topicInfo.topicConsumer.setMessageListener(new MessageListener() {

            @Override
            public void onMessage(Message message) {
                topicInfo.addMessage(message);
            }
        });
    } catch (JMSException e) {
        throw new JmsMessageException("Could not start listening for messages on topic " + topicName, e);
    }
}
Also used : JmsMessageException(com.axway.ats.action.exceptions.JmsMessageException) Message(javax.jms.Message) BytesMessage(javax.jms.BytesMessage) MessageListener(javax.jms.MessageListener) JMSException(javax.jms.JMSException) Topic(javax.jms.Topic) Session(javax.jms.Session) ManagedSession(com.axway.ats.action.jms.model.sessions.ManagedSession) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 4 with JmsMessageException

use of com.axway.ats.action.exceptions.JmsMessageException in project ats-framework by Axway.

the class JmsMessageVerification method getBodyHash.

private byte[] getBodyHash(final String algorithm) {
    isNotNull();
    MessageDigest digest;
    try {
        digest = MessageDigest.getInstance(algorithm);
    } catch (final NoSuchAlgorithmException e) {
        throw new JmsMessageException("Failed to load " + algorithm + " algorithm: " + e);
    }
    try {
        if (actualMessage instanceof TextMessage) {
            digest.update(((TextMessage) actualMessage).getText().getBytes());
        } else if (actualMessage instanceof BytesMessage) {
            final BytesMessage m = (BytesMessage) actualMessage;
            final byte[] tmp = new byte[2048];
            int r;
            while ((r = m.readBytes(tmp)) >= 0) {
                if (r != 0) {
                    digest.update(tmp, 0, r);
                }
            }
        } else if (actualMessage instanceof StreamMessage) {
            final StreamMessage m = (StreamMessage) actualMessage;
            final byte[] tmp = new byte[2048];
            int r;
            while ((r = m.readBytes(tmp)) >= 0) {
                if (r != 0) {
                    digest.update(tmp, 0, r);
                }
            }
        } else {
            throw new JmsMessageException("Cannot determind content hash for message type : " + actualMessage.getClass());
        }
    } catch (final JMSException e) {
        throw new JmsMessageException("Failed to determine message " + algorithm + " hash", e);
    }
    return digest.digest();
}
Also used : JmsMessageException(com.axway.ats.action.exceptions.JmsMessageException) BytesMessage(javax.jms.BytesMessage) StreamMessage(javax.jms.StreamMessage) JMSException(javax.jms.JMSException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) MessageDigest(java.security.MessageDigest) TextMessage(javax.jms.TextMessage)

Example 5 with JmsMessageException

use of com.axway.ats.action.exceptions.JmsMessageException in project ats-framework by Axway.

the class JmsClient method sendBinaryMessageToQueue.

/**
     * Send a binary message to a queue
     * 
     * @param queueName queue name
     * @param bytes message content
     * @param properties message properties or null if none
     */
@PublicAtsApi
public void sendBinaryMessageToQueue(final String queueName, final byte[] bytes, final Map<String, ?> properties) {
    try {
        final Session session = loadSession(false, Session.AUTO_ACKNOWLEDGE);
        doSendBinaryMessage(session, session.createQueue(queueName), bytes, properties);
    } catch (Exception e) {
        throw new JmsMessageException("Failed to send binary message to queue " + queueName, e);
    }
}
Also used : JmsMessageException(com.axway.ats.action.exceptions.JmsMessageException) NamingException(javax.naming.NamingException) JMSException(javax.jms.JMSException) JmsMessageException(com.axway.ats.action.exceptions.JmsMessageException) Session(javax.jms.Session) ManagedSession(com.axway.ats.action.jms.model.sessions.ManagedSession) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Aggregations

JmsMessageException (com.axway.ats.action.exceptions.JmsMessageException)10 JMSException (javax.jms.JMSException)10 ManagedSession (com.axway.ats.action.jms.model.sessions.ManagedSession)7 Session (javax.jms.Session)7 PublicAtsApi (com.axway.ats.common.PublicAtsApi)6 NamingException (javax.naming.NamingException)5 ManagedConnection (com.axway.ats.action.jms.model.connections.ManagedConnection)2 BytesMessage (javax.jms.BytesMessage)2 Topic (javax.jms.Topic)2 MessageDigest (java.security.MessageDigest)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 ConnectionFactory (javax.jms.ConnectionFactory)1 Message (javax.jms.Message)1 MessageListener (javax.jms.MessageListener)1 StreamMessage (javax.jms.StreamMessage)1 TextMessage (javax.jms.TextMessage)1