use of javax.jms.QueueReceiver 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.QueueReceiver in project rabbitmq-jms-client by rabbitmq.
the class SimpleAmqpQueueMessageIT method testSendFromAmqpAndReceiveTextMessage.
@Test
public void testSendFromAmqpAndReceiveTextMessage() throws Exception {
channel.queueDeclare(QUEUE_NAME_NON_EXCLUSIVE, // durable
false, // non-exclusive
false, // autoDelete
true, // options
null);
Map<String, Object> hdrs = new HashMap<String, Object>();
hdrs.put(USER_STRING_PROPERTY_NAME, STRING_PROP_VALUE);
// To signal a JMS TextMessage
hdrs.put("JMSType", "TextMessage");
hdrs.put("JMSPriority", 21);
hdrs.put("JMSDeliveryMode", 2);
hdrs.put("DummyProp", 42);
hdrs.put("rmq.jms.silly", "silly attempt");
AMQP.BasicProperties props = new AMQP.BasicProperties.Builder().deliveryMode(1).priority(6).headers(hdrs).build();
channel.basicPublish("", QUEUE_NAME_NON_EXCLUSIVE, props, MESSAGE.getBytes("UTF-8"));
queueConn.start();
QueueSession queueSession = queueConn.createQueueSession(false, Session.DUPS_OK_ACKNOWLEDGE);
// read-only AMQP-mapped queue
Queue queue = new RMQDestination(QUEUE_NAME_NON_EXCLUSIVE, null, null, QUEUE_NAME_NON_EXCLUSIVE);
QueueReceiver queueReceiver = queueSession.createReceiver(queue);
TextMessage message = (TextMessage) queueReceiver.receive(TEST_RECEIVE_TIMEOUT);
assertNotNull(message, "No message received");
assertEquals(MESSAGE, message.getText(), "Payload doesn't match");
// override should work
assertEquals(21, message.getJMSPriority(), "Priority incorrect");
// override should fail
assertEquals(1, message.getJMSDeliveryMode(), "Delivery mode incorrect");
// override should work
assertEquals("TextMessage", message.getJMSType(), "JMSType not set correctly");
Enumeration<?> propNames = message.getPropertyNames();
Set<String> propNameSet = new HashSet<String>();
while (propNames.hasMoreElements()) {
propNameSet.add((String) propNames.nextElement());
}
assertEquals(new HashSet<>(Arrays.asList(USER_STRING_PROPERTY_NAME, "DummyProp")), propNameSet, "Headers not set correctly");
assertEquals(STRING_PROP_VALUE, message.getStringProperty(USER_STRING_PROPERTY_NAME), "String property not transferred");
assertEquals("42", message.getStringProperty("DummyProp"), "Numeric property not transferred");
assertThat(message.getJMSTimestamp()).isZero();
}
use of javax.jms.QueueReceiver 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.QueueReceiver in project qpid-broker-j by apache.
the class QueueReceiverTest method createReceiver.
@Test
public void createReceiver() throws Exception {
Queue queue = createQueue(getTestName());
QueueConnection queueConnection = getQueueConnection();
try {
queueConnection.start();
Utils.sendMessages(queueConnection, queue, 3);
QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
QueueReceiver receiver = session.createReceiver(queue, String.format("%s=2", INDEX));
assertEquals("Queue names should match from QueueReceiver", queue.getQueueName(), receiver.getQueue().getQueueName());
Message received = receiver.receive(getReceiveTimeout());
assertNotNull("Message is not received", received);
assertEquals("Unexpected message is received", 2, received.getIntProperty(INDEX));
} finally {
queueConnection.close();
}
}
use of javax.jms.QueueReceiver in project iaf by ibissource.
the class PullingIfsaProviderListener method openThread.
@Override
public Map openThread() throws ListenerException {
Map threadContext = new HashMap();
try {
if (!isSessionsArePooled()) {
QueueSession session = createSession();
threadContext.put(THREAD_CONTEXT_SESSION_KEY, session);
QueueReceiver receiver;
receiver = getServiceReceiver(session);
threadContext.put(THREAD_CONTEXT_RECEIVER_KEY, receiver);
}
return threadContext;
} catch (IfsaException e) {
throw new ListenerException(getLogPrefix() + "exception in openThread()", e);
}
}
Aggregations