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

The following examples show how to use org.springframework.jms.listener.adapter.ListenerExecutionFailedException. 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: EnableJmsTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
@Test
public void jmsHandlerMethodFactoryConfiguration() throws JMSException {
	ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(
			EnableJmsHandlerMethodFactoryConfig.class, ValidationBean.class);

	assertThatExceptionOfType(ListenerExecutionFailedException.class).isThrownBy(() ->
			testJmsHandlerMethodFactoryConfiguration(context))
		.withCauseInstanceOf(MethodArgumentNotValidException.class);
}
 
Example #2
Source File: AnnotationDrivenNamespaceTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
@Test
public void jmsHandlerMethodFactoryConfiguration() throws JMSException {
	ApplicationContext context = new ClassPathXmlApplicationContext(
			"annotation-driven-custom-handler-method-factory.xml", getClass());

	assertThatExceptionOfType(ListenerExecutionFailedException.class).isThrownBy(() ->
			testJmsHandlerMethodFactoryConfiguration(context))
		.withCauseInstanceOf(MethodArgumentNotValidException.class);
}
 
Example #3
Source File: MethodJmsListenerEndpointTests.java    From spring-analysis-note 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);

	// test is an invalid value
	assertThatExceptionOfType(ListenerExecutionFailedException.class).isThrownBy(() ->
			listener.onMessage(createSimpleJmsTextMessage("invalid value"), session));

}
 
Example #4
Source File: MethodJmsListenerEndpointTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void invalidPayloadType() throws JMSException {
	MessagingMessageListenerAdapter listener = createDefaultInstance(Integer.class);
	Session session = mock(Session.class);

	// test is not a valid integer
	assertThatExceptionOfType(ListenerExecutionFailedException.class).isThrownBy(() ->
			listener.onMessage(createSimpleJmsTextMessage("test"), session))
		.withCauseInstanceOf(MessageConversionException.class)
		.withMessageContaining(getDefaultListenerMethod(Integer.class).toGenericString()); // ref to method
}
 
Example #5
Source File: MethodJmsListenerEndpointTests.java    From spring-analysis-note 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);

	// Message<String> as Message<Integer>
	assertThatExceptionOfType(ListenerExecutionFailedException.class).isThrownBy(() ->
			listener.onMessage(createSimpleJmsTextMessage("test"), session))
		.withCauseInstanceOf(MessageConversionException.class);
}
 
Example #6
Source File: EnableJmsTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
@Test
public void jmsHandlerMethodFactoryConfiguration() throws JMSException {
	ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(
			EnableJmsHandlerMethodFactoryConfig.class, ValidationBean.class);

	thrown.expect(ListenerExecutionFailedException.class);
	thrown.expectCause(Is.<MethodArgumentNotValidException>isA(MethodArgumentNotValidException.class));
	testJmsHandlerMethodFactoryConfiguration(context);
}
 
Example #7
Source File: AnnotationDrivenNamespaceTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
@Test
public void jmsHandlerMethodFactoryConfiguration() throws JMSException {
	ApplicationContext context = new ClassPathXmlApplicationContext(
			"annotation-driven-custom-handler-method-factory.xml", getClass());

	thrown.expect(ListenerExecutionFailedException.class);
	thrown.expectCause(Is.<MethodArgumentNotValidException>isA(MethodArgumentNotValidException.class));
	testJmsHandlerMethodFactoryConfiguration(context);
}
 
Example #8
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 #9
Source File: MethodJmsListenerEndpointTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void invalidPayloadType() throws JMSException {
	MessagingMessageListenerAdapter listener = createDefaultInstance(Integer.class);
	Session session = mock(Session.class);

	this.thrown.expect(ListenerExecutionFailedException.class);
	this.thrown.expectCause(Matchers.isA(MessageConversionException.class));
	this.thrown.expectMessage(getDefaultListenerMethod(Integer.class).toGenericString()); // ref to method
	listener.onMessage(createSimpleJmsTextMessage("test"), session); // test is not a valid integer
}
 
Example #10
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 #11
Source File: EnableJmsTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
@Test
public void jmsHandlerMethodFactoryConfiguration() throws JMSException {
	ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(
			EnableJmsHandlerMethodFactoryConfig.class, ValidationBean.class);

	thrown.expect(ListenerExecutionFailedException.class);
	thrown.expectCause(Is.<MethodArgumentNotValidException>isA(MethodArgumentNotValidException.class));
	testJmsHandlerMethodFactoryConfiguration(context);
}
 
Example #12
Source File: AnnotationDrivenNamespaceTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
@Test
public void jmsHandlerMethodFactoryConfiguration() throws JMSException {
	ApplicationContext context = new ClassPathXmlApplicationContext(
			"annotation-driven-custom-handler-method-factory.xml", getClass());

	thrown.expect(ListenerExecutionFailedException.class);
	thrown.expectCause(Is.<MethodArgumentNotValidException>isA(MethodArgumentNotValidException.class));
	testJmsHandlerMethodFactoryConfiguration(context);
}
 
Example #13
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 #14
Source File: MethodJmsListenerEndpointTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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 #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: SearchIndexUpdateJmsMessageListener.java    From herd with Apache License 2.0 4 votes vote down vote up
/**
 * Processes a JMS message with retry.
 * This process message with retry method will attempt to process the message up to 4 times
 * with a 2 second, 4 second, 8 second, and 16 second exponential back off
 *
 * @param payload the message payload
 * @param allHeaders the JMS headers
 */
@Retryable(maxAttempts = 4, value = ListenerExecutionFailedException.class, backoff = @Backoff(delay = 2000, multiplier = 2))
private void processMessageWithRetry(String payload, @Headers Map<Object, Object> allHeaders)
{
    LOGGER.info("Message received from the JMS queue. jmsQueueName=\"{}\" jmsMessageHeaders=\"{}\" jmsMessagePayload={}",
        HerdJmsDestinationResolver.SQS_DESTINATION_SEARCH_INDEX_UPDATE_QUEUE, allHeaders, payload);
    try
    {
        // Unmarshall the SearchIndexUpdateDto from a JSON string to a SearchIndexUpdateDto object
        SearchIndexUpdateDto searchIndexUpdateDto = jsonHelper.unmarshallJsonToObject(SearchIndexUpdateDto.class, payload);

        LOGGER.info("Unmarshall the json payload into the searchIndexUpdateDto=\"{}\", jms_messageId=\"{}\"", searchIndexUpdateDto.toString(),
            allHeaders.get("jms_messageId"));

        // If the message type is null, this message is in the original message format.
        if (searchIndexUpdateDto.getMessageType() == null)
        {
            LOGGER.info("Updating the search index document(s) for the business object definition(s) that have changed. jms_messageId=\"{}\"",
                allHeaders.get("jms_messageId"));
            businessObjectDefinitionService.updateSearchIndexDocumentBusinessObjectDefinition(searchIndexUpdateDto);
        }
        else
        {
            switch (searchIndexUpdateDto.getMessageType())
            {
                case MESSAGE_TYPE_BUSINESS_OBJECT_DEFINITION_UPDATE:
                    LOGGER.info("Updating the search index document(s) for the business object definition(s) that have changed. jms_messageId=\"{}\"",
                        allHeaders.get("jms_messageId"));
                    businessObjectDefinitionService.updateSearchIndexDocumentBusinessObjectDefinition(searchIndexUpdateDto);
                    break;
                case MESSAGE_TYPE_TAG_UPDATE:
                    LOGGER.info("Updating the search index document(s) for the tag(s) that have changed. jms_messageId=\"{}\"",
                        allHeaders.get("jms_messageId"));
                    tagService.updateSearchIndexDocumentTag(searchIndexUpdateDto);
                    break;
                default:
                    LOGGER.error("Unknown message type.");
                    break;
            }
        }
    }
    catch (IOException ioException)
    {
        LOGGER.warn("Could not unmarshall JSON to SearchIndexUpdateDto object.", ioException);
    }
}