Java Code Examples for org.springframework.jms.listener.adapter.MessagingMessageListenerAdapter#onMessage()

The following examples show how to use org.springframework.jms.listener.adapter.MessagingMessageListenerAdapter#onMessage() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Test
public void processAndReply() throws JMSException {
	MessagingMessageListenerAdapter listener = createDefaultInstance(String.class);
	String body = "echo text";
	String correlationId = "link-1234";
	Destination replyDestination = new Destination() {};

	TextMessage reply = mock(TextMessage.class);
	QueueSender queueSender = mock(QueueSender.class);
	Session session = mock(Session.class);
	given(session.createTextMessage(body)).willReturn(reply);
	given(session.createProducer(replyDestination)).willReturn(queueSender);

	listener.setDefaultResponseDestination(replyDestination);
	StubTextMessage inputMessage = createSimpleJmsTextMessage(body);
	inputMessage.setJMSCorrelationID(correlationId);
	listener.onMessage(inputMessage, session);
	assertDefaultListenerMethodInvocation();

	verify(reply).setJMSCorrelationID(correlationId);
	verify(queueSender).send(reply);
	verify(queueSender).close();
}
 
Example 2
@Test
public void processAndReply() throws JMSException {
	MessagingMessageListenerAdapter listener = createDefaultInstance(String.class);
	String body = "echo text";
	String correlationId = "link-1234";
	Destination replyDestination = new Destination() {};

	TextMessage reply = mock(TextMessage.class);
	QueueSender queueSender = mock(QueueSender.class);
	Session session = mock(Session.class);
	given(session.createTextMessage(body)).willReturn(reply);
	given(session.createProducer(replyDestination)).willReturn(queueSender);

	listener.setDefaultResponseDestination(replyDestination);
	StubTextMessage inputMessage = createSimpleJmsTextMessage(body);
	inputMessage.setJMSCorrelationID(correlationId);
	listener.onMessage(inputMessage, session);
	assertDefaultListenerMethodInvocation();

	verify(reply).setJMSCorrelationID(correlationId);
	verify(queueSender).send(reply);
	verify(queueSender).close();
}
 
Example 3
/**
 * Test for {@link ValidationBean} with a validator ({@link TestValidator}) specified
 * in a custom {@link org.springframework.messaging.handler.annotation.support.MessageHandlerMethodFactory}.
 *
 * The test should throw a {@link org.springframework.jms.listener.adapter.ListenerExecutionFailedException}
 */
public void testJmsHandlerMethodFactoryConfiguration(ApplicationContext context) throws JMSException {
	JmsListenerContainerTestFactory simpleFactory =
			context.getBean("defaultFactory", JmsListenerContainerTestFactory.class);
	assertEquals(1, simpleFactory.getListenerContainers().size());
	MethodJmsListenerEndpoint endpoint = (MethodJmsListenerEndpoint)
			simpleFactory.getListenerContainers().get(0).getEndpoint();

	SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
	endpoint.setupListenerContainer(container);
	MessagingMessageListenerAdapter listener = (MessagingMessageListenerAdapter) container.getMessageListener();
	listener.onMessage(new StubTextMessage("failValidation"), mock(Session.class));
}
 
Example 4
@Test
public void resolveMessageAndSession() throws JMSException {
	MessagingMessageListenerAdapter listener = createDefaultInstance(javax.jms.Message.class, Session.class);

	Session session = mock(Session.class);
	listener.onMessage(createSimpleJmsTextMessage("test"), session);
	assertDefaultListenerMethodInvocation();
}
 
Example 5
@Test
public void emptySendTo() throws JMSException {
	MessagingMessageListenerAdapter listener = createDefaultInstance(String.class);

	TextMessage reply = mock(TextMessage.class);
	Session session = mock(Session.class);
	given(session.createTextMessage("content")).willReturn(reply);

	thrown.expect(ReplyFailureException.class);
	thrown.expectCause(Matchers.isA(InvalidDestinationException.class));
	listener.onMessage(createSimpleJmsTextMessage("content"), session);
}
 
Example 6
@Test
public void resolveHeaderAndPayload() throws JMSException {
	MessagingMessageListenerAdapter listener = createDefaultInstance(String.class, int.class);

	Session session = mock(Session.class);
	StubTextMessage message = createSimpleJmsTextMessage("my payload");
	message.setIntProperty("myCounter", 55);
	listener.onMessage(message, session);
	assertDefaultListenerMethodInvocation();
}
 
Example 7
@Test
public void resolveCustomHeaderNameAndPayload() throws JMSException {
	MessagingMessageListenerAdapter listener = createDefaultInstance(String.class, int.class);

	Session session = mock(Session.class);
	StubTextMessage message = createSimpleJmsTextMessage("my payload");
	message.setIntProperty("myCounter", 24);
	listener.onMessage(message, session);
	assertDefaultListenerMethodInvocation();
}
 
Example 8
@Test
public void invalidPayloadType() throws JMSException {
	MessagingMessageListenerAdapter listener = createDefaultInstance(Integer.class);
	Session session = mock(Session.class);

	thrown.expect(ListenerExecutionFailedException.class);
	thrown.expectCause(Matchers.isA(MessageConversionException.class));
	thrown.expectMessage(getDefaultListenerMethod(Integer.class).toGenericString()); // ref to method
	listener.onMessage(createSimpleJmsTextMessage("test"), session); // test is not a valid integer
}
 
Example 9
@Test
public void resolveHeaders() throws JMSException {
	MessagingMessageListenerAdapter listener = createDefaultInstance(String.class, Map.class);

	Session session = mock(Session.class);
	StubTextMessage message = createSimpleJmsTextMessage("my payload");
	message.setIntProperty("customInt", 1234);
	message.setJMSMessageID("abcd-1234");
	listener.onMessage(message, session);
	assertDefaultListenerMethodInvocation();
}
 
Example 10
@Test
public void resolveObjectPayload() throws JMSException {
	MessagingMessageListenerAdapter listener = createDefaultInstance(MyBean.class);
	MyBean myBean = new MyBean();
	myBean.name = "myBean name";

	Session session = mock(Session.class);
	ObjectMessage message = mock(ObjectMessage.class);
	given(message.getObject()).willReturn(myBean);

	listener.onMessage(message, session);
	assertDefaultListenerMethodInvocation();
}
 
Example 11
@Test
public void resolveConvertedPayload() throws JMSException {
	MessagingMessageListenerAdapter listener = createDefaultInstance(Integer.class);

	Session session = mock(Session.class);

	listener.onMessage(createSimpleJmsTextMessage("33"), session);
	assertDefaultListenerMethodInvocation();
}
 
Example 12
@Test
public void resolveMessageHeaders() throws JMSException {
	MessagingMessageListenerAdapter listener = createDefaultInstance(MessageHeaders.class);

	Session session = mock(Session.class);
	StubTextMessage message = createSimpleJmsTextMessage("my payload");
	message.setLongProperty("customLong", 4567L);
	message.setJMSType("myMessageType");
	listener.onMessage(message, session);
	assertDefaultListenerMethodInvocation();
}
 
Example 13
@Test
public void resolveConvertedPayload() throws JMSException {
	MessagingMessageListenerAdapter listener = createDefaultInstance(Integer.class);

	Session session = mock(Session.class);

	listener.onMessage(createSimpleJmsTextMessage("33"), session);
	assertDefaultListenerMethodInvocation();
}
 
Example 14
private void processAndReplyWithSendTo(MessagingMessageListenerAdapter listener,
		String replyDestinationName, boolean pubSubDomain,
		QosSettings replyQosSettings) throws JMSException {
	String body = "echo text";
	String correlationId = "link-1234";
	Destination replyDestination = new Destination() {};

	DestinationResolver destinationResolver = mock(DestinationResolver.class);
	TextMessage reply = mock(TextMessage.class);
	QueueSender queueSender = mock(QueueSender.class);
	Session session = mock(Session.class);

	given(destinationResolver.resolveDestinationName(session, replyDestinationName, pubSubDomain))
			.willReturn(replyDestination);
	given(session.createTextMessage(body)).willReturn(reply);
	given(session.createProducer(replyDestination)).willReturn(queueSender);

	listener.setDestinationResolver(destinationResolver);
	StubTextMessage inputMessage = createSimpleJmsTextMessage(body);
	inputMessage.setJMSCorrelationID(correlationId);
	listener.onMessage(inputMessage, session);

	verify(destinationResolver).resolveDestinationName(session, replyDestinationName, pubSubDomain);
	verify(reply).setJMSCorrelationID(correlationId);
	if (replyQosSettings != null) {
		verify(queueSender).send(reply, replyQosSettings.getDeliveryMode(),
				replyQosSettings.getPriority(), replyQosSettings.getTimeToLive());
	}
	else {
		verify(queueSender).send(reply);
	}
	verify(queueSender).close();
}
 
Example 15
@Test
public void resolveGenericMessage() throws JMSException {
	MessagingMessageListenerAdapter listener = createDefaultInstance(Message.class);

	Session session = mock(Session.class);
	listener.onMessage(createSimpleJmsTextMessage("test"), session);
	assertDefaultListenerMethodInvocation();
}
 
Example 16
@Test
public void resolveConvertedPayload() throws JMSException {
	MessagingMessageListenerAdapter listener = createDefaultInstance(Integer.class);

	Session session = mock(Session.class);

	listener.onMessage(createSimpleJmsTextMessage("33"), session);
	assertDefaultListenerMethodInvocation();
}
 
Example 17
@Test
public void resolveHeaders() throws JMSException {
	MessagingMessageListenerAdapter listener = createDefaultInstance(String.class, Map.class);

	Session session = mock(Session.class);
	StubTextMessage message = createSimpleJmsTextMessage("my payload");
	message.setIntProperty("customInt", 1234);
	message.setJMSMessageID("abcd-1234");
	listener.onMessage(message, session);
	assertDefaultListenerMethodInvocation();
}
 
Example 18
@Test
public void resolveHeaderAndPayload() throws JMSException {
	MessagingMessageListenerAdapter listener = createDefaultInstance(String.class, int.class);

	Session session = mock(Session.class);
	StubTextMessage message = createSimpleJmsTextMessage("my payload");
	message.setIntProperty("myCounter", 55);
	listener.onMessage(message, session);
	assertDefaultListenerMethodInvocation();
}
 
Example 19
@Test
public void resolveJmsMessageHeaderAccessor() throws JMSException {
	MessagingMessageListenerAdapter listener = createDefaultInstance(JmsMessageHeaderAccessor.class);

	Session session = mock(Session.class);
	StubTextMessage message = createSimpleJmsTextMessage("my payload");
	message.setBooleanProperty("customBoolean", true);
	message.setJMSPriority(9);
	listener.onMessage(message, session);
	assertDefaultListenerMethodInvocation();
}
 
Example 20
@Test
public void resolveCustomHeaderNameAndPayloadWithHeaderNameSet() throws JMSException {
	MessagingMessageListenerAdapter listener = createDefaultInstance(String.class, int.class);

	Session session = mock(Session.class);
	StubTextMessage message = createSimpleJmsTextMessage("my payload");
	message.setIntProperty("myCounter", 24);
	listener.onMessage(message, session);
	assertDefaultListenerMethodInvocation();
}