use of javax.jms.QueueSession in project spring-framework by spring-projects.
the class MessageListenerAdapterTests method testWithResponsiveMessageDelegateNoDefaultDestination_SendsReturnTextMessageWhenSessionSupplied_AndSendingThrowsJMSException.
@Test
public void testWithResponsiveMessageDelegateNoDefaultDestination_SendsReturnTextMessageWhenSessionSupplied_AndSendingThrowsJMSException() throws Exception {
Queue destination = mock(Queue.class);
final TextMessage sentTextMessage = mock(TextMessage.class);
// correlation ID is queried when response is being created...
given(sentTextMessage.getJMSCorrelationID()).willReturn(CORRELATION_ID);
// Reply-To is queried when response is being created...
given(sentTextMessage.getJMSReplyTo()).willReturn(destination);
TextMessage responseTextMessage = mock(TextMessage.class);
MessageProducer messageProducer = mock(MessageProducer.class);
willThrow(new JMSException("Doe!")).given(messageProducer).send(responseTextMessage);
final QueueSession session = mock(QueueSession.class);
given(session.createTextMessage(RESPONSE_TEXT)).willReturn(responseTextMessage);
given(session.createProducer(destination)).willReturn(messageProducer);
ResponsiveMessageDelegate delegate = mock(ResponsiveMessageDelegate.class);
given(delegate.handleMessage(sentTextMessage)).willReturn(RESPONSE_TEXT);
final MessageListenerAdapter adapter = new MessageListenerAdapter(delegate) {
@Override
protected Object extractMessage(Message message) {
return message;
}
};
try {
adapter.onMessage(sentTextMessage, session);
fail("expected CouldNotSendReplyException with JMSException");
} catch (ReplyFailureException ex) {
assertEquals(JMSException.class, ex.getCause().getClass());
}
verify(responseTextMessage).setJMSCorrelationID(CORRELATION_ID);
verify(messageProducer).close();
verify(delegate).handleMessage(sentTextMessage);
}
use of javax.jms.QueueSession in project spring-framework by spring-projects.
the class SingleConnectionFactoryTests method testCachingConnectionFactoryWithQueueConnectionFactoryAndJms102Usage.
@Test
public void testCachingConnectionFactoryWithQueueConnectionFactoryAndJms102Usage() throws JMSException {
QueueConnectionFactory cf = mock(QueueConnectionFactory.class);
QueueConnection con = mock(QueueConnection.class);
QueueSession txSession = mock(QueueSession.class);
QueueSession nonTxSession = mock(QueueSession.class);
given(cf.createQueueConnection()).willReturn(con);
given(con.createQueueSession(true, Session.AUTO_ACKNOWLEDGE)).willReturn(txSession);
given(txSession.getTransacted()).willReturn(true);
given(con.createQueueSession(false, Session.CLIENT_ACKNOWLEDGE)).willReturn(nonTxSession);
CachingConnectionFactory scf = new CachingConnectionFactory(cf);
scf.setReconnectOnException(false);
Connection con1 = scf.createQueueConnection();
Session session1 = con1.createSession(true, Session.AUTO_ACKNOWLEDGE);
session1.rollback();
session1.close();
session1 = con1.createSession(false, Session.CLIENT_ACKNOWLEDGE);
session1.close();
con1.start();
QueueConnection con2 = scf.createQueueConnection();
Session session2 = con2.createQueueSession(false, Session.CLIENT_ACKNOWLEDGE);
session2.close();
session2 = con2.createSession(true, Session.AUTO_ACKNOWLEDGE);
session2.getTransacted();
// should lead to rollback
session2.close();
con2.start();
con1.close();
con2.close();
// should trigger actual close
scf.destroy();
verify(txSession).rollback();
verify(txSession).close();
verify(nonTxSession).close();
verify(con).start();
verify(con).stop();
verify(con).close();
}
use of javax.jms.QueueSession in project wildfly by wildfly.
the class MDBRoleTestCase method testIsMDBinRole.
@Test
public void testIsMDBinRole() throws NamingException, JMSException {
final InitialContext ctx = new InitialContext();
final QueueConnectionFactory factory = (QueueConnectionFactory) ctx.lookup("java:/JmsXA");
final QueueConnection connection = factory.createQueueConnection();
connection.start();
final QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
final Queue replyDestination = session.createTemporaryQueue();
final QueueReceiver receiver = session.createReceiver(replyDestination);
final Message message = session.createTextMessage("Let's test it!");
message.setJMSReplyTo(replyDestination);
final Destination destination = (Destination) ctx.lookup("queue/myAwesomeQueue");
final MessageProducer producer = session.createProducer(destination);
producer.send(message);
producer.close();
final Message reply = receiver.receive(TimeoutUtil.adjust(5000));
assertNotNull(reply);
final String result = ((TextMessage) reply).getText();
assertEquals(SimpleSLSB.SUCCESS, result);
connection.close();
}
use of javax.jms.QueueSession in project wildfly by wildfly.
the class MDBLifecycleCallback 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 == null ? "SUCCESS" : e);
message.setJMSCorrelationID(messageID);
sender.send(message, DeliveryMode.NON_PERSISTENT, 4, 500);
} finally {
conn.close();
}
}
use of javax.jms.QueueSession in project wildfly by wildfly.
the class QueueTestMDB method sendReply.
private void sendReply(Queue destination, String messageID) throws JMSException {
QueueConnection conn = qFactory.createQueueConnection();
try {
QueueSession session = conn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
QueueSender sender = session.createSender(destination);
TextMessage message = session.createTextMessage("SUCCESS");
message.setJMSCorrelationID(messageID);
sender.send(message, DeliveryMode.NON_PERSISTENT, 4, 500);
} finally {
conn.close();
}
}
Aggregations