The generic exception strategy you propose sounds like a good idea.
Just to be clear on our problem, we have the following config:
Code:
<bean id="container" class="our.overriden.MessageListenerContainer">
<property name="errorHandler" ref="messagePublishErorr"/>
<property name="destinationName" value="destination"/>
<property name="connectionFactory" ref="connectionFactory"/>
<property name="transactionManager" ref="transactionManager"/>
</bean>
<bean id="messagePublishErorr" class="org.springframework.integration.channel.MessagePublishingErrorHandler">
<property name="defaultErrorChannel" ref="messageError"/>
</bean>
<integration:channel id="messageError"/>
Then we would have an ErrorMessageExceptionTypeRouter listening on messageError channel and sending to our jms outbound channel adapter which sends to the invalid queue.
If we override the method in the container as follows:
Code:
protected void doExecuteListener(Session session, Message message) throws JMSException {
if (!isAcceptMessagesWhileStopping() && !isRunning()) {
if (logger.isWarnEnabled()) {
logger.warn("Rejecting received message because of the listener container " +
"having been stopped in the meantime: " + message);
}
rollbackIfNecessary(session);
throw new MessageRejectedWhileStoppingException();
}
try {
invokeListener(session, message);
}
catch(OurBusinessException e) {
//commit the trxn but want to send the original message onto invalid queue
commitIfNecessary(session, message);
throw new InvalidMessageException(e);
}
catch (JMSException ex) {
rollbackOnExceptionIfNecessary(session, ex);
throw ex;
}
catch (RuntimeException ex) {
rollbackOnExceptionIfNecessary(session, ex);
throw ex;
}
catch (Error err) {
rollbackOnExceptionIfNecessary(session, err);
throw err;
}
commitIfNecessary(session, message);
}
All exceptions happen within a SI context, so are you saying then that if catch our business exception and then rethrow a SI MessagingException we will be able to get hold of the original message in our subscribers to the ErrorMessageExceptionTypeRouter?
Hope that's clear?