use of javax.jms.ObjectMessage in project wildfly by wildfly.
the class ObjectMessageTestCase method testObjectMessage.
/**
* Test that the MDB can process a {@link ObjectMessage} without any classloading issues
*
* @throws Exception
*/
@Test
public void testObjectMessage() throws Exception {
final String goodAfternoon = "Good afternoon!";
// create the message
final SimpleMessageInEarLibJar message = new SimpleMessageInEarLibJar(goodAfternoon);
// send as ObjectMessage
this.jmsUtil.sendObjectMessage(message, this.objectMessageQueue, this.objectMessageReplyQueue);
// wait for an reply
final Message reply = this.jmsUtil.receiveMessage(objectMessageReplyQueue, 5000);
// test the reply
Assert.assertNotNull("Reply message was null on reply queue: " + this.objectMessageReplyQueue, reply);
final SimpleMessageInEarLibJar replyMessage = (SimpleMessageInEarLibJar) ((ObjectMessage) reply).getObject();
Assert.assertEquals("Unexpected reply message on reply queue: " + this.objectMessageReplyQueue, message, replyMessage);
}
use of javax.jms.ObjectMessage in project wildfly by wildfly.
the class ObjectMessageTestCase method testObjectMessageWithObjectArray.
/**
* Test that the MDB can process a {@link ObjectMessage} which consists of an array of objects,
* without any classloading issues
*
* @throws Exception
*/
@Test
public void testObjectMessageWithObjectArray() throws Exception {
final String goodMorning = "Good morning";
final String goodEvening = "Good evening";
// create the message
final SimpleMessageInEarLibJar[] multipleGreetings = new SimpleMessageInEarLibJar[2];
final SimpleMessageInEarLibJar messageOne = new SimpleMessageInEarLibJar(goodMorning);
final SimpleMessageInEarLibJar messageTwo = new SimpleMessageInEarLibJar(goodEvening);
multipleGreetings[0] = messageOne;
multipleGreetings[1] = messageTwo;
// send as ObjectMessage
this.jmsUtil.sendObjectMessage(multipleGreetings, this.objectMessageOfArrayTypeQueue, this.objectMessageOfArrayTypeReplyQueue);
// wait for an reply
final Message reply = this.jmsUtil.receiveMessage(objectMessageOfArrayTypeReplyQueue, 5000);
// test the reply
Assert.assertNotNull("Reply message was null on reply queue: " + this.objectMessageOfArrayTypeReplyQueue, reply);
final SimpleMessageInEarLibJar[] replyMessage = (SimpleMessageInEarLibJar[]) ((ObjectMessage) reply).getObject();
Assert.assertTrue("Unexpected reply message on reply queue: " + this.objectMessageOfArrayTypeReplyQueue, Arrays.equals(replyMessage, multipleGreetings));
}
use of javax.jms.ObjectMessage in project wildfly by wildfly.
the class JMSMessagingUtil method sendObjectMessage.
public void sendObjectMessage(final Serializable msg, final Destination destination, final Destination replyDestination) throws JMSException {
final ObjectMessage message = session.createObjectMessage();
message.setObject(msg);
this.sendMessage(message, destination, replyDestination);
}
use of javax.jms.ObjectMessage in project wildfly by wildfly.
the class QueueTestMDB method sendReply.
private void sendReply(Queue destination, String messageID, Exception e) throws JMSException {
QueueConnection conn = qFactory.createQueueConnection();
try {
QueueSession session = conn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
QueueSender sender = session.createSender(destination);
ObjectMessage message = session.createObjectMessage(e);
message.setJMSCorrelationID(messageID);
sender.send(message, DeliveryMode.NON_PERSISTENT, 4, 500);
} finally {
conn.close();
}
}
use of javax.jms.ObjectMessage in project wildfly by wildfly.
the class RunAsMDBUnitTestCase method testSendMessage.
@Test
public void testSendMessage() throws Exception {
ConnectionFactory connFactory = lookup("ConnectionFactory", ConnectionFactory.class);
Connection conn = connFactory.createConnection();
conn.start();
Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
TemporaryQueue replyQueue = session.createTemporaryQueue();
TextMessage msg = session.createTextMessage("Hello world");
msg.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT);
msg.setJMSReplyTo(replyQueue);
Queue queue = lookup("java:jboss/" + queueName, Queue.class);
MessageProducer producer = session.createProducer(queue);
producer.send(msg);
MessageConsumer consumer = session.createConsumer(replyQueue);
Message replyMsg = consumer.receive(5000);
Assert.assertNotNull(replyMsg);
if (replyMsg instanceof ObjectMessage) {
Exception e = (Exception) ((ObjectMessage) replyMsg).getObject();
throw e;
}
Assert.assertTrue(replyMsg instanceof TextMessage);
String actual = ((TextMessage) replyMsg).getText();
Assert.assertEquals("SUCCESS", actual);
consumer.close();
producer.close();
session.close();
conn.close();
}
Aggregations