use of javax.jms.TextMessage 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.TextMessage 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.TextMessage in project karaf by apache.
the class ArtemisDestinationSourceFactory method getNames.
private List<String> getNames(Connection connection, DestinationSource.DestinationType type) {
try {
QueueSession session = ((QueueConnection) connection).createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
Queue managementQueue = session.createQueue("activemq.management");
QueueRequestor requestor = new QueueRequestor(session, managementQueue);
connection.start();
TextMessage m = session.createTextMessage();
m.setStringProperty("_AMQ_ResourceName", "broker");
m.setStringProperty("_AMQ_OperationName", "getQueueNames");
String routing = type == DestinationSource.DestinationType.Queue ? "ANYCAST" : "MULTICAST";
m.setText("[\"" + routing + "\"]");
Message reply = requestor.request(m);
String json = ((TextMessage) reply).getText();
List<?> array = (List<?>) JsonReader.read(new StringReader(json));
return (List<String>) array.get(0);
} catch (Exception e) {
return Collections.emptyList();
}
}
use of javax.jms.TextMessage in project jmeter by apache.
the class JMSSampler method sample.
/**
* {@inheritDoc}
*/
@Override
public SampleResult sample(Entry entry) {
SampleResult res = new SampleResult();
res.setSampleLabel(getName());
res.setSamplerData(getContent());
// Assume failure
res.setSuccessful(false);
res.setDataType(SampleResult.TEXT);
res.sampleStart();
try {
TextMessage msg = createMessage();
if (isOneway()) {
int deliveryMode = isNonPersistent() ? DeliveryMode.NON_PERSISTENT : DeliveryMode.PERSISTENT;
producer.send(msg, deliveryMode, Integer.parseInt(getPriority()), Long.parseLong(getExpiration()));
res.setRequestHeaders(Utils.messageProperties(msg));
res.setResponseOK();
res.setResponseData("Oneway request has no response data", null);
} else {
if (!useTemporyQueue()) {
msg.setJMSReplyTo(receiveQueue);
}
Message replyMsg = executor.sendAndReceive(msg, isNonPersistent() ? DeliveryMode.NON_PERSISTENT : DeliveryMode.PERSISTENT, Integer.parseInt(getPriority()), Long.parseLong(getExpiration()));
res.setRequestHeaders(Utils.messageProperties(msg));
if (replyMsg == null) {
res.setResponseMessage("No reply message received");
} else {
if (replyMsg instanceof TextMessage) {
res.setResponseData(((TextMessage) replyMsg).getText(), null);
} else {
res.setResponseData(replyMsg.toString(), null);
}
res.setResponseHeaders(Utils.messageProperties(replyMsg));
res.setResponseOK();
}
}
} catch (Exception e) {
LOGGER.warn(e.getLocalizedMessage(), e);
if (thrown != null) {
res.setResponseMessage(thrown.toString());
} else {
res.setResponseMessage(e.getLocalizedMessage());
}
}
res.sampleEnd();
return res;
}
use of javax.jms.TextMessage in project jmeter by apache.
the class SubscriberSampler method extractContent.
private void extractContent(StringBuilder buffer, StringBuilder propBuffer, Message msg, boolean isLast) {
if (msg != null) {
try {
if (msg instanceof TextMessage) {
buffer.append(((TextMessage) msg).getText());
} else if (msg instanceof ObjectMessage) {
ObjectMessage objectMessage = (ObjectMessage) msg;
if (objectMessage.getObject() != null) {
buffer.append(objectMessage.getObject().getClass());
} else {
buffer.append("object is null");
}
} else if (msg instanceof BytesMessage) {
BytesMessage bytesMessage = (BytesMessage) msg;
buffer.append(bytesMessage.getBodyLength() + " bytes received in BytesMessage");
} else if (msg instanceof MapMessage) {
MapMessage mapm = (MapMessage) msg;
// MapNames are Strings
@SuppressWarnings("unchecked") Enumeration<String> enumb = mapm.getMapNames();
while (enumb.hasMoreElements()) {
String name = enumb.nextElement();
Object obj = mapm.getObject(name);
buffer.append(name);
buffer.append(",");
buffer.append(obj.getClass().getCanonicalName());
buffer.append(",");
buffer.append(obj);
buffer.append("\n");
}
}
Utils.messageProperties(propBuffer, msg);
if (!isLast && !StringUtils.isEmpty(separator)) {
propBuffer.append(separator);
buffer.append(separator);
}
} catch (JMSException e) {
log.error(e.getMessage());
}
}
}
Aggregations