use of javax.jms.JMSException in project oxAuth by GluuFederation.
the class ApplicationAuditLogger method loggingThroughJMS.
private void loggingThroughJMS(OAuth2AuditLog oAuth2AuditLog) {
QueueConnection connection = null;
try {
connection = pooledConnectionFactory.createQueueConnection();
connection.start();
QueueSession session = connection.createQueueSession(transacted, ACK_MODE);
MessageProducer producer = session.createProducer(session.createQueue(CLIENT_QUEUE_NAME));
TextMessage txtMessage = session.createTextMessage();
txtMessage.setText(ServerUtil.asPrettyJson(oAuth2AuditLog));
producer.send(txtMessage);
} catch (JMSException e) {
log.error("Can't send message", e);
} catch (IOException e) {
log.error("Can't serialize the audit log", e);
} catch (Exception e) {
log.error("Can't send message, please check your activeMQ configuration.", e);
} finally {
if (connection == null)
return;
try {
connection.close();
} catch (JMSException e) {
log.error("Can't close connection.");
}
}
}
use of javax.jms.JMSException in project adempiere by adempiere.
the class TopicExportProcessor method sendJMSMessage.
private void sendJMSMessage(String host, int port, String msg, String protocol, String topicName, String clientID, String userName, String password, int timeToLive, boolean isDeliveryModePersistent) throws JMSException {
// Create a ConnectionFactory
// network protocol (tcp, ...) set as EXP_ProcessorParameter
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(protocol + "://" + host + ":" + port);
Connection connection = null;
Session session = null;
try {
// Create a Connection
if (userName != null && password != null) {
connection = connectionFactory.createConnection(userName, password);
} else {
connection = connectionFactory.createConnection();
}
// connection.setClientID( clientID ); Commented by Victor as he had issue!
connection.start();
// Create a Session
//TODO - Trifon could be EXP_ProcessorParameter
session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
// Create the destination (Topic or Queue)
Destination destination = session.createTopic(topicName);
// Create a MessageProducer from the Session to the Topic or Queue
MessageProducer producer = session.createProducer(destination);
// EXP_ProcessorParameter
producer.setTimeToLive(timeToLive);
if (isDeliveryModePersistent) {
// EXP_ProcessorParameter
producer.setDeliveryMode(DeliveryMode.PERSISTENT);
} else {
// EXP_ProcessorParameter
producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
}
// How to send to multiple destinations.
//MessageProducer producer = session.createProducer(null);
//producer.send(someDestination, message);
//producer.send(anotherDestination, message);
// Create a message
TextMessage message = session.createTextMessage(msg);
// Tell the producer to send the message
try {
producer.send(message);
session.commit();
log.info("JMS Message sent!");
} catch (JMSException ex) {
session.rollback();
log.info("JMS Can't send the message!");
throw ex;
}
} finally {
// Clean up
if (session != null) {
try {
session.close();
} catch (JMSException ex) {
/* ignored */
}
}
if (connection != null) {
try {
connection.close();
} catch (JMSException ex) {
/* ignored */
}
}
}
}
use of javax.jms.JMSException in project adempiere by adempiere.
the class TopicListener method run.
public void run() throws JMSException {
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(url);
log.finest("ActiveMQConnectionFactory = " + factory);
if (userName != null && password != null) {
conn = factory.createConnection(userName, password);
} else {
conn = factory.createConnection();
}
log.finest("conn = " + conn);
if (conn.getClientID() == null) {
try {
conn.setClientID(clientID);
} catch (Exception e) {
//log.info("Connection with clientID '" + clientID +"' already exists" + e.toString());
conn.close();
return;
}
} else {
if (conn.getClientID().equals(clientID)) {
log.warning("Connection with clientID '" + clientID + "' already exists");
conn.close();
return;
} else {
try {
conn.setClientID(clientID);
} catch (Exception e) {
log.info("Error while invoking setClientID(" + clientID + ")! " + e.getMessage());
conn.close();
return;
}
}
}
// TODO - could be parameter
session = conn.createSession(true, Session.AUTO_ACKNOWLEDGE);
log.finest("session = " + session);
log.finest("topicName = " + topicName);
log.finest("subscriptionName = " + subscriptionName);
topic = session.createTopic(topicName);
log.finest("topic = " + topic);
MessageConsumer consumer = null;
if (isDurableSubscription) {
// http://publib.boulder.ibm.com/infocenter/wasinfo/v6r0/index.jsp?topic=/com.ibm.websphere.pmc.express.doc/tasks/tjn0012_.html
// The subscriptionName assigned to a durable subscription must be unique within a given client ID.
consumer = session.createDurableSubscriber(topic, subscriptionName);
} else {
consumer = session.createConsumer(topic);
}
log.finest("consumer = " + consumer);
consumer.setMessageListener(this);
conn.start();
log.finest("Waiting for JMS messages...");
if (replicationProcessor != null) {
MIMPProcessorLog pLog = new MIMPProcessorLog(replicationProcessor.getMImportProcessor(), "Connected to JMS Server. Waiting for messages!");
StringBuffer logReference = new StringBuffer("topicName = ").append(topicName).append(", subscriptionName = ").append(subscriptionName);
pLog.setReference(logReference.toString());
boolean resultSave = pLog.save();
log.finest("Result Save = " + resultSave);
}
}
use of javax.jms.JMSException in project karaf by apache.
the class PooledConnection method cleanupConnectionTemporaryDestinations.
/**
* Remove all of the temporary destinations created for this connection.
* This is important since the underlying connection may be reused over a
* long period of time, accumulating all of the temporary destinations from
* each use. However, from the perspective of the lifecycle from the
* client's view, close() closes the connection and, therefore, deletes all
* of the temporary destinations created.
*/
protected void cleanupConnectionTemporaryDestinations() {
for (TemporaryQueue tempQueue : connTempQueues) {
try {
tempQueue.delete();
} catch (JMSException ex) {
LOG.info("failed to delete Temporary Queue \"" + tempQueue.toString() + "\" on closing pooled connection: " + ex.getMessage());
}
}
connTempQueues.clear();
for (TemporaryTopic tempTopic : connTempTopics) {
try {
tempTopic.delete();
} catch (JMSException ex) {
LOG.info("failed to delete Temporary Topic \"" + tempTopic.toString() + "\" on closing pooled connection: " + ex.getMessage());
}
}
connTempTopics.clear();
}
use of javax.jms.JMSException in project karaf by apache.
the class PooledConnectionFactory method createJmsException.
private JMSException createJmsException(String msg, Exception cause) {
JMSException exception = new JMSException(msg);
exception.setLinkedException(cause);
exception.initCause(cause);
return exception;
}
Aggregations