Search in sources :

Example 21 with MessagingMessageListenerAdapter

use of org.springframework.jms.listener.adapter.MessagingMessageListenerAdapter in project spring-framework by spring-projects.

the class MethodJmsListenerEndpointTests method resolveObjectPayload.

@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();
}
Also used : MessagingMessageListenerAdapter(org.springframework.jms.listener.adapter.MessagingMessageListenerAdapter) ObjectMessage(javax.jms.ObjectMessage) Session(javax.jms.Session) Test(org.junit.Test)

Example 22 with MessagingMessageListenerAdapter

use of org.springframework.jms.listener.adapter.MessagingMessageListenerAdapter in project spring-framework by spring-projects.

the class MethodJmsListenerEndpointTests method resolveHeaderAndPayload.

@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();
}
Also used : MessagingMessageListenerAdapter(org.springframework.jms.listener.adapter.MessagingMessageListenerAdapter) StubTextMessage(org.springframework.jms.StubTextMessage) Session(javax.jms.Session) Test(org.junit.Test)

Example 23 with MessagingMessageListenerAdapter

use of org.springframework.jms.listener.adapter.MessagingMessageListenerAdapter in project spring-framework by spring-projects.

the class MethodJmsListenerEndpoint method createMessageListener.

@Override
protected MessagingMessageListenerAdapter createMessageListener(MessageListenerContainer container) {
    Assert.state(this.messageHandlerMethodFactory != null, "Could not create message listener - MessageHandlerMethodFactory not set");
    MessagingMessageListenerAdapter messageListener = createMessageListenerInstance();
    InvocableHandlerMethod invocableHandlerMethod = this.messageHandlerMethodFactory.createInvocableHandlerMethod(getBean(), getMethod());
    messageListener.setHandlerMethod(invocableHandlerMethod);
    String responseDestination = getDefaultResponseDestination();
    if (StringUtils.hasText(responseDestination)) {
        if (container.isReplyPubSubDomain()) {
            messageListener.setDefaultResponseTopicName(responseDestination);
        } else {
            messageListener.setDefaultResponseQueueName(responseDestination);
        }
    }
    MessageConverter messageConverter = container.getMessageConverter();
    if (messageConverter != null) {
        messageListener.setMessageConverter(messageConverter);
    }
    DestinationResolver destinationResolver = container.getDestinationResolver();
    if (destinationResolver != null) {
        messageListener.setDestinationResolver(destinationResolver);
    }
    return messageListener;
}
Also used : MessagingMessageListenerAdapter(org.springframework.jms.listener.adapter.MessagingMessageListenerAdapter) DestinationResolver(org.springframework.jms.support.destination.DestinationResolver) InvocableHandlerMethod(org.springframework.messaging.handler.invocation.InvocableHandlerMethod) MessageConverter(org.springframework.jms.support.converter.MessageConverter)

Example 24 with MessagingMessageListenerAdapter

use of org.springframework.jms.listener.adapter.MessagingMessageListenerAdapter in project spring-framework by spring-projects.

the class AbstractJmsAnnotationDrivenTests method testJmsHandlerMethodFactoryConfiguration.

/**
	 * 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));
}
Also used : MessagingMessageListenerAdapter(org.springframework.jms.listener.adapter.MessagingMessageListenerAdapter) StubTextMessage(org.springframework.jms.StubTextMessage) SimpleMessageListenerContainer(org.springframework.jms.listener.SimpleMessageListenerContainer) JmsListenerContainerTestFactory(org.springframework.jms.config.JmsListenerContainerTestFactory) MethodJmsListenerEndpoint(org.springframework.jms.config.MethodJmsListenerEndpoint) Session(javax.jms.Session)

Aggregations

MessagingMessageListenerAdapter (org.springframework.jms.listener.adapter.MessagingMessageListenerAdapter)24 Test (org.junit.Test)22 Session (javax.jms.Session)17 StubTextMessage (org.springframework.jms.StubTextMessage)9 SimpleMessageListenerContainer (org.springframework.jms.listener.SimpleMessageListenerContainer)5 Method (java.lang.reflect.Method)2 TextMessage (javax.jms.TextMessage)2 MessageConverter (org.springframework.jms.support.converter.MessageConverter)2 DestinationResolver (org.springframework.jms.support.destination.DestinationResolver)2 MessageConversionException (org.springframework.messaging.converter.MessageConversionException)2 DefaultMessageHandlerMethodFactory (org.springframework.messaging.handler.annotation.support.DefaultMessageHandlerMethodFactory)2 Destination (javax.jms.Destination)1 InvalidDestinationException (javax.jms.InvalidDestinationException)1 ObjectMessage (javax.jms.ObjectMessage)1 QueueSender (javax.jms.QueueSender)1 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)1 JmsListenerContainerTestFactory (org.springframework.jms.config.JmsListenerContainerTestFactory)1 MethodJmsListenerEndpoint (org.springframework.jms.config.MethodJmsListenerEndpoint)1 InvocableHandlerMethod (org.springframework.messaging.handler.invocation.InvocableHandlerMethod)1