use of com.rabbitmq.jms.client.message.RMQStreamMessage 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 com.rabbitmq.jms.client.message.RMQStreamMessage in project rocketmq-externals by apache.
the class RabbitmqSourceTaskTest method getMessageConnentTest.
@Test
public void getMessageConnentTest() throws JMSException {
String value = "hello rocketmq";
RabbitmqSourceTask task = new RabbitmqSourceTask();
RMQTextMessage textMessage = new RMQTextMessage();
textMessage.setText(value);
ByteBuffer buffer = task.getMessageContent(textMessage);
Assert.assertEquals(new String(buffer.array()), textMessage.getText());
ObjectMessage objectMessage = new RMQObjectMessage();
objectMessage.setObject(value);
buffer = task.getMessageContent(objectMessage);
Assert.assertEquals(new String(buffer.array()), "\"" + objectMessage.getObject().toString() + "\"");
BytesMessage bytes = new RMQBytesMessage();
bytes.writeBytes(value.getBytes());
bytes.reset();
buffer = task.getMessageContent(bytes);
Assert.assertEquals(new String(buffer.array()), value);
MapMessage mapMessage = new RMQMapMessage();
mapMessage.setString("hello", "rocketmq");
buffer = task.getMessageContent(mapMessage);
Map<String, String> map = JSON.parseObject(buffer.array(), Map.class);
Assert.assertEquals(map.get("hello"), "rocketmq");
Assert.assertEquals(map.size(), 1);
StreamMessage streamMessage = new RMQStreamMessage();
String valueTwo = null;
for (int i = 0; i < 200; i++) {
valueTwo = valueTwo + value;
}
streamMessage.writeBytes(valueTwo.getBytes());
streamMessage.reset();
// buffer = task.getMessageContent(streamMessage);
// Assert.assertEquals(new String(buffer.array()), valueTwo);
}
Aggregations