org.springframework.jms.listener.adapter.MessagingMessageListenerAdapter Java Examples

The following examples show how to use org.springframework.jms.listener.adapter.MessagingMessageListenerAdapter. 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
Source File: MethodJmsListenerEndpointTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@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
Source File: MethodJmsListenerEndpointTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@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
Source File: MethodJmsListenerEndpointTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void processAndReplyWithCustomReplyQosSettings() throws JMSException {
	String methodName = "processAndReplyWithSendTo";
	SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
	QosSettings replyQosSettings = new QosSettings(1, 6, 6000);
	container.setReplyQosSettings(replyQosSettings);
	MessagingMessageListenerAdapter listener = createInstance(this.factory,
			getListenerMethod(methodName, String.class), container);
	processAndReplyWithSendTo(listener, "replyDestination", false, replyQosSettings);
	assertListenerMethodInvocation(this.sample, methodName);
}
 
Example #4
Source File: MethodJmsListenerEndpointTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void invalidMessagePayloadType() throws JMSException {
	MessagingMessageListenerAdapter listener = createDefaultInstance(Message.class);
	Session session = mock(Session.class);

	this.thrown.expect(ListenerExecutionFailedException.class);
	this.thrown.expectCause(Matchers.isA(MessageConversionException.class));
	listener.onMessage(createSimpleJmsTextMessage("test"), session);  // Message<String> as Message<Integer>
}
 
Example #5
Source File: MethodJmsListenerEndpointTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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 #6
Source File: MethodJmsListenerEndpointTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example #7
Source File: MethodJmsListenerEndpointTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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 #8
Source File: MethodJmsListenerEndpointTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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 #9
Source File: MethodJmsListenerEndpointTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void validatePayloadInvalid() throws JMSException {
	DefaultMessageHandlerMethodFactory customFactory = new DefaultMessageHandlerMethodFactory();
	customFactory.setValidator(testValidator("invalid value"));

	Method method = getListenerMethod("validatePayload", String.class);
	MessagingMessageListenerAdapter listener = createInstance(customFactory, method);
	Session session = mock(Session.class);

	thrown.expect(ListenerExecutionFailedException.class);
	listener.onMessage(createSimpleJmsTextMessage("invalid value"), session); // test is an invalid value

}
 
Example #10
Source File: MethodJmsListenerEndpointTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void processFromQueueAndReplyWithSendToTopic() throws JMSException {
	String methodName = "processAndReplyWithSendTo";
	SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
	container.setReplyPubSubDomain(true);
	MessagingMessageListenerAdapter listener = createInstance(this.factory,
			getListenerMethod(methodName, String.class), container);
	processAndReplyWithSendTo(listener, true);
	assertListenerMethodInvocation(sample, methodName);
}
 
Example #11
Source File: MethodJmsListenerEndpointTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void resolveConvertedPayload() throws JMSException {
	MessagingMessageListenerAdapter listener = createDefaultInstance(Integer.class);

	Session session = mock(Session.class);

	listener.onMessage(createSimpleJmsTextMessage("33"), session);
	assertDefaultListenerMethodInvocation();
}
 
Example #12
Source File: MethodJmsListenerEndpointTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void processAndReplyWithSendToQueue() throws JMSException {
	String methodName = "processAndReplyWithSendTo";
	SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
	MessagingMessageListenerAdapter listener = createInstance(this.factory,
			getListenerMethod(methodName, String.class), container);
	processAndReplyWithSendTo(listener, false);
	assertListenerMethodInvocation(sample, methodName);
}
 
Example #13
Source File: MethodJmsListenerEndpointTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void resolveGenericMessage() throws JMSException {
	MessagingMessageListenerAdapter listener = createDefaultInstance(Message.class);

	Session session = mock(Session.class);
	listener.onMessage(createSimpleJmsTextMessage("test"), session);
	assertDefaultListenerMethodInvocation();
}
 
Example #14
Source File: MethodJmsListenerEndpointTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void validatePayloadValid() throws JMSException {
	String methodName = "validatePayload";

	DefaultMessageHandlerMethodFactory customFactory = new DefaultMessageHandlerMethodFactory();
	customFactory.setValidator(testValidator("invalid value"));
	initializeFactory(customFactory);

	Method method = getListenerMethod(methodName, String.class);
	MessagingMessageListenerAdapter listener = createInstance(customFactory, method);
	Session session = mock(Session.class);
	listener.onMessage(createSimpleJmsTextMessage("test"), session); // test is a valid value
	assertListenerMethodInvocation(this.sample, methodName);
}
 
Example #15
Source File: MethodJmsListenerEndpointTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void invalidMessagePayloadType() throws JMSException {
	MessagingMessageListenerAdapter listener = createDefaultInstance(Message.class);
	Session session = mock(Session.class);

	thrown.expect(ListenerExecutionFailedException.class);
	thrown.expectCause(Matchers.isA(MethodArgumentTypeMismatchException.class));
	listener.onMessage(createSimpleJmsTextMessage("test"), session);  // Message<String> as Message<Integer>
}
 
Example #16
Source File: MethodJmsListenerEndpointTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
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 #17
Source File: MethodJmsListenerEndpointTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void processAndReplyWithNullReplyQosSettings() throws JMSException {
	String methodName = "processAndReplyWithSendTo";
	SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
	container.setReplyQosSettings(null);
	MessagingMessageListenerAdapter listener = createInstance(this.factory,
			getListenerMethod(methodName, String.class), container);
	processAndReplyWithSendTo(listener, "replyDestination", false);
	assertListenerMethodInvocation(this.sample, methodName);
}
 
Example #18
Source File: MethodJmsListenerEndpointTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void validatePayloadInvalid() throws JMSException {
	DefaultMessageHandlerMethodFactory customFactory = new DefaultMessageHandlerMethodFactory();
	customFactory.setValidator(testValidator("invalid value"));

	Method method = getListenerMethod("validatePayload", String.class);
	MessagingMessageListenerAdapter listener = createInstance(customFactory, method);
	Session session = mock(Session.class);

	this.thrown.expect(ListenerExecutionFailedException.class);
	listener.onMessage(createSimpleJmsTextMessage("invalid value"), session); // test is an invalid value

}
 
Example #19
Source File: MethodJmsListenerEndpointTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void processFromQueueAndReplyWithSendToTopic() throws JMSException {
	String methodName = "processAndReplyWithSendTo";
	SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
	container.setReplyPubSubDomain(true);
	MessagingMessageListenerAdapter listener = createInstance(this.factory,
			getListenerMethod(methodName, String.class), container);
	processAndReplyWithSendTo(listener, "replyDestination", true);
	assertListenerMethodInvocation(this.sample, methodName);
}
 
Example #20
Source File: MethodJmsListenerEndpointTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void processAndReplyWithSendToTopic() throws JMSException {
	String methodName = "processAndReplyWithSendTo";
	SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
	container.setPubSubDomain(true);
	MessagingMessageListenerAdapter listener = createInstance(this.factory,
			getListenerMethod(methodName, String.class), container);
	processAndReplyWithSendTo(listener, "replyDestination", true);
	assertListenerMethodInvocation(this.sample, methodName);
}
 
Example #21
Source File: MethodJmsListenerEndpointTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void processFromTopicAndReplyWithSendToQueue() throws JMSException {
	String methodName = "processAndReplyWithSendTo";
	SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
	container.setPubSubDomain(true);
	container.setReplyPubSubDomain(false);
	MessagingMessageListenerAdapter listener = createInstance(this.factory,
			getListenerMethod(methodName, String.class), container);
	processAndReplyWithSendTo(listener, "replyDestination", false);
	assertListenerMethodInvocation(this.sample, methodName);
}
 
Example #22
Source File: MethodJmsListenerEndpointTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void processAndReplyWithSendToQueue() throws JMSException {
	String methodName = "processAndReplyWithSendTo";
	SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
	MessagingMessageListenerAdapter listener = createInstance(this.factory,
			getListenerMethod(methodName, String.class), container);
	processAndReplyWithSendTo(listener, "replyDestination", false);
	assertListenerMethodInvocation(this.sample, methodName);
}
 
Example #23
Source File: MethodJmsListenerEndpointTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void resolveConvertedPayload() throws JMSException {
	MessagingMessageListenerAdapter listener = createDefaultInstance(Integer.class);

	Session session = mock(Session.class);

	listener.onMessage(createSimpleJmsTextMessage("33"), session);
	assertDefaultListenerMethodInvocation();
}
 
Example #24
Source File: MethodJmsListenerEndpointTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@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 #25
Source File: MethodJmsListenerEndpointTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@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 #26
Source File: MethodJmsListenerEndpointTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@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 #27
Source File: MethodJmsListenerEndpointTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@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 #28
Source File: MethodJmsListenerEndpoint.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
protected MessagingMessageListenerAdapter createMessageListener(MessageListenerContainer container) {
	Assert.state(this.messageHandlerMethodFactory != null,
			"Could not create message listener - MessageHandlerMethodFactory not set");
	MessagingMessageListenerAdapter messageListener = createMessageListenerInstance();
	Object bean = getBean();
	Method method = getMethod();
	Assert.state(bean != null && method != null, "No bean+method set on endpoint");
	InvocableHandlerMethod invocableHandlerMethod =
			this.messageHandlerMethodFactory.createInvocableHandlerMethod(bean, method);
	messageListener.setHandlerMethod(invocableHandlerMethod);
	String responseDestination = getDefaultResponseDestination();
	if (StringUtils.hasText(responseDestination)) {
		if (container.isReplyPubSubDomain()) {
			messageListener.setDefaultResponseTopicName(responseDestination);
		}
		else {
			messageListener.setDefaultResponseQueueName(responseDestination);
		}
	}
	QosSettings responseQosSettings = container.getReplyQosSettings();
	if (responseQosSettings != null) {
		messageListener.setResponseQosSettings(responseQosSettings);
	}
	MessageConverter messageConverter = container.getMessageConverter();
	if (messageConverter != null) {
		messageListener.setMessageConverter(messageConverter);
	}
	DestinationResolver destinationResolver = container.getDestinationResolver();
	if (destinationResolver != null) {
		messageListener.setDestinationResolver(destinationResolver);
	}
	return messageListener;
}
 
Example #29
Source File: MethodJmsListenerEndpointTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@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 #30
Source File: MethodJmsListenerEndpointTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@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();
}