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