use of javax.jms.QueueSender in project rabbitmq-jms-client by rabbitmq.
the class StreamMessageSerializationIT method testReceiveStreamMessageWithValue.
protected void testReceiveStreamMessageWithValue(Object value) throws Exception {
try {
queueConn.start();
QueueSession queueSession = queueConn.createQueueSession(false, Session.DUPS_OK_ACKNOWLEDGE);
Queue queue = queueSession.createQueue(QUEUE_NAME);
drainQueue(queueSession, queue);
QueueSender queueSender = queueSession.createSender(queue);
StreamMessage message = (StreamMessage) MessageTestType.STREAM.gen(queueSession, null);
// we simulate an attack from the sender by calling writeObject with a non-primitive value
// (StreamMessage supports only primitive types)
// the value is then sent to the destination and the consumer will have to
// deserialize it and can potentially execute malicious code
Method writeObjectMethod = RMQStreamMessage.class.getDeclaredMethod("writeObject", Object.class, boolean.class);
writeObjectMethod.setAccessible(true);
writeObjectMethod.invoke(message, value, true);
queueSender.send(message);
} finally {
reconnect(TRUSTED_PACKAGES);
}
queueConn.start();
QueueSession queueSession = queueConn.createQueueSession(false, Session.DUPS_OK_ACKNOWLEDGE);
Queue queue = queueSession.createQueue(QUEUE_NAME);
QueueReceiver queueReceiver = queueSession.createReceiver(queue);
RMQStreamMessage m = (RMQStreamMessage) queueReceiver.receive(TEST_RECEIVE_TIMEOUT);
MessageTestType.STREAM.check(m, null);
assertEquals(m.readObject(), value);
}
use of javax.jms.QueueSender in project rabbitmq-jms-client by rabbitmq.
the class SimpleQueueMessageIT method messageTestBase.
private void messageTestBase(MessageTestType mtt) throws Exception {
try {
queueConn.start();
QueueSession queueSession = queueConn.createQueueSession(false, Session.DUPS_OK_ACKNOWLEDGE);
Queue queue = queueSession.createQueue(QUEUE_NAME);
drainQueue(queueSession, queue);
QueueSender queueSender = queueSession.createSender(queue);
queueSender.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
queueSender.send(mtt.gen(queueSession, (Serializable) queue));
} finally {
reconnect();
}
queueConn.start();
QueueSession queueSession = queueConn.createQueueSession(false, Session.DUPS_OK_ACKNOWLEDGE);
Queue queue = queueSession.createQueue(QUEUE_NAME);
QueueReceiver queueReceiver = queueSession.createReceiver(queue);
mtt.check(queueReceiver.receive(TEST_RECEIVE_TIMEOUT), (Serializable) queue);
}
use of javax.jms.QueueSender in project iaf by ibissource.
the class IfsaFacade method sendReply.
/**
* Intended for server-side reponse sending and implies that the received
* message *always* contains a reply-to address.
*/
public void sendReply(QueueSession session, Message received_message, String response) throws IfsaException {
QueueSender tqs = null;
try {
TextMessage answer = session.createTextMessage();
answer.setText(response);
Queue replyQueue = (Queue) received_message.getJMSReplyTo();
tqs = session.createSender(replyQueue);
if (log.isDebugEnabled())
log.debug(getLogPrefix() + "sending reply to [" + received_message.getJMSReplyTo() + "]");
((IFSAServerQueueSender) tqs).sendReply(received_message, answer);
} catch (Throwable t) {
throw new IfsaException(t);
} finally {
if (tqs != null) {
try {
tqs.close();
} catch (JMSException e) {
log.warn(getLogPrefix() + "exception closing reply queue sender", e);
}
}
}
}
use of javax.jms.QueueSender in project iaf by ibissource.
the class IfsaRequesterSender method sendMessage.
/**
* Execute a request to the IFSA service.
* @return in Request/Reply, the retrieved message or TIMEOUT, otherwise null
*/
public String sendMessage(String message, Map<String, String> params, String bifName, byte[] btcData) throws SenderException, TimeoutException {
String result = null;
QueueSession session = null;
QueueSender sender = null;
Map udzMap = null;
try {
log.debug(getLogPrefix() + "creating session and sender");
session = createSession();
IFSAQueue queue;
if (params != null && params.size() > 0) {
// Use first param as serviceId
String serviceId = params.get("serviceId");
if (serviceId == null) {
serviceId = getServiceId();
}
String occurrence = params.get("occurrence");
if (occurrence != null) {
int i = serviceId.indexOf('/', serviceId.indexOf('/', serviceId.indexOf('/', serviceId.indexOf('/') + 1) + 1) + 1);
int j = serviceId.indexOf('/', i + 1);
serviceId = serviceId.substring(0, i + 1) + occurrence + serviceId.substring(j);
}
queue = getMessagingSource().lookupService(getMessagingSource().polishServiceId(serviceId));
if (queue == null) {
throw new SenderException(getLogPrefix() + "got null as queue for serviceId [" + serviceId + "]");
}
if (log.isDebugEnabled()) {
log.info(getLogPrefix() + "got Queue to send messages on [" + queue.getQueueName() + "]");
}
// Use remaining params as outgoing UDZs
udzMap = new HashMap();
udzMap.putAll(params);
udzMap.remove("serviceId");
udzMap.remove("occurrence");
} else {
queue = getServiceQueue();
}
sender = createSender(session, queue);
log.debug(getLogPrefix() + "sending message with bifName [" + bifName + "]");
TextMessage sentMessage = sendMessage(session, sender, message, udzMap, bifName, btcData);
log.debug(getLogPrefix() + "message sent");
if (isSynchronous()) {
log.debug(getLogPrefix() + "waiting for reply");
javax.jms.Message msg = getRawReplyMessage(session, queue, sentMessage);
try {
long tsReplyReceived = System.currentTimeMillis();
long tsRequestSent = sentMessage.getJMSTimestamp();
long tsReplySent = msg.getJMSTimestamp();
// }
if (log.isInfoEnabled()) {
log.info(getLogPrefix() + "A) RequestSent [" + DateUtils.format(tsRequestSent) + "]");
log.info(getLogPrefix() + "B) ReplySent [" + DateUtils.format(tsReplySent) + "] diff (~queing + processing) [" + (tsReplySent - tsRequestSent) + "]");
log.info(getLogPrefix() + "C) ReplyReceived [" + DateUtils.format(tsReplyReceived) + "] diff (transport of reply )[" + (tsReplyReceived - tsReplySent) + "]");
// log.info(getLogPrefix()+"C2) msgRcvd.businessProcStartRcvd ["+DateUtils.format(businessProcStartRcvd) +"] ");
// log.info(getLogPrefix()+"D) msgRcvd.jmsTimestamp ["+DateUtils.format(jmsTimestampRcvd) +"] diff ["+(jmsTimestampRcvd-businessProcStartSent)+"]");
// log.info(getLogPrefix()+"E) msgRcvd.businessProcFinishRcvd ["+DateUtils.format(businessProcFinishRcvd)+"] diff ["+(businessProcFinishRcvd-jmsTimestampRcvd)+"] (=time spend on IFSA bus sending result?)");
// log.info(getLogPrefix()+"F) timestampAfterRcvd ["+DateUtils.format(timestampAfterRcvd) +"] diff ["+(timestampAfterRcvd-businessProcFinishRcvd)+"] ");
// log.info(getLogPrefix()+"business processing time (E-C1) ["+(businessProcFinishRcvd-businessProcStartSent)+"] ");
}
// if (businessProcessTimes!=null) {
// businessProcessTimes.addValue(businessProcFinishRcvd-businessProcStartSent);
// }
} catch (JMSException e) {
log.warn(getLogPrefix() + "exception determining processing times", e);
}
if (msg instanceof TextMessage) {
result = ((TextMessage) msg).getText();
} else {
if (msg.getClass().getName().endsWith("IFSAReportMessage")) {
if (msg instanceof IFSAReportMessage) {
IFSAReportMessage irm = (IFSAReportMessage) msg;
if (isThrowExceptions()) {
throw new SenderException(getLogPrefix() + "received IFSAReportMessage [" + ToStringBuilder.reflectionToString(irm) + "], NoReplyReason [" + irm.getNoReplyReason() + "]");
}
log.warn(getLogPrefix() + "received IFSAReportMessage [" + ToStringBuilder.reflectionToString(irm) + "], NoReplyReason [" + irm.getNoReplyReason() + "]");
result = "<IFSAReport>" + "<NoReplyReason>" + irm.getNoReplyReason() + "</NoReplyReason>" + "</IFSAReport>";
}
} else {
log.warn(getLogPrefix() + "received neither TextMessage nor IFSAReportMessage but [" + msg.getClass().getName() + "]");
result = msg.toString();
}
}
if (result == null) {
log.info(getLogPrefix() + "received null reply");
} else {
if (log.isDebugEnabled()) {
if (AppConstants.getInstance().getBoolean("log.logIntermediaryResults", false)) {
log.debug(getLogPrefix() + "received reply [" + result + "]");
} else {
log.debug(getLogPrefix() + "received reply");
}
} else {
log.info(getLogPrefix() + "received reply");
}
}
} else {
result = sentMessage.getJMSMessageID();
}
} catch (JMSException e) {
throw new SenderException(getLogPrefix() + "caught JMSException in sendMessage()", e);
} catch (IfsaException e) {
throw new SenderException(getLogPrefix() + "caught IfsaException in sendMessage()", e);
} finally {
if (sender != null) {
try {
log.debug(getLogPrefix() + "closing sender");
sender.close();
} catch (JMSException e) {
log.debug(getLogPrefix() + "Exception closing sender", e);
}
}
closeSession(session);
}
if (isThrowExceptions() && result != null && result.startsWith("<exception>")) {
throw new SenderException("Retrieved exception message from IFSA bus: " + result);
}
return result;
}
use of javax.jms.QueueSender in project activemq-artemis by apache.
the class QueueReceiverTest method testCreateReceiverWithMessageSelector.
/**
* com.sun.ts.tests.jms.ee.all.queueconn.QueueConnTest line 171
*/
@Test
public void testCreateReceiverWithMessageSelector() throws Exception {
QueueConnection qc = null;
try {
qc = createQueueConnection();
QueueSession qs = qc.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
QueueReceiver qreceiver = qs.createReceiver(queue1, "targetMessage = TRUE");
qc.start();
TextMessage m = qs.createTextMessage();
m.setText("one");
m.setBooleanProperty("targetMessage", false);
QueueSender qsender = qs.createSender(queue1);
qsender.send(m);
m.setText("two");
m.setBooleanProperty("targetMessage", true);
qsender.send(m);
TextMessage rm = (TextMessage) qreceiver.receive(1000);
ProxyAssertSupport.assertEquals("two", rm.getText());
} finally {
if (qc != null) {
qc.close();
}
Thread.sleep(2000);
removeAllMessages(queue1.getQueueName(), true);
checkEmpty(queue1);
}
}
Aggregations