Thanks for your suggestion, I have tried your alternate suggestion, so retaining the jms backed channel and adding <service-activator/> after it that references a <gateway/>. Then add the splitter after the <gateway/>. I have given the gateway an error-channel on it.
I'm still getting some strange behaviour
1) Firstly I seem to find defining the service activator like your suggestion caused start up errors, saying something along the lines of the activator can't find matching method on gateway.
Code:
Caused by:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.integration.config.ServiceActivatorFactoryBean#6': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalArgume
ntException: Found ambiguous parameter type [interface java.util.List] for method match: [public final void $Proxy89.processSubmission(org.springframework.integration.Message), public final boolean $Proxy89.removeAdvice(org.aopalliance.aop.Advice), p
ublic final boolean $Proxy89.removeAdvisor(org.springframework.aop.Advisor), public final void $Proxy89.removeAdvisor(int) throws org.springframework.aop.framework.AopConfigException, public final java.lang.String $Proxy89.toProxyConfigString(), publ
ic final boolean $Proxy89.isInterfaceProxied(java.lang.Class), public final void $Proxy89.setPreFiltered(boolean), public final void $Proxy89.setTargetSource(org.springframework.aop.TargetSource)]
So I assumed you're example was just illustrative, so I used the same theory but defined a java class as the Service Activator (in front of the gateway), autowired the gateway interface into it, then in the implementation just delegated to the Gateway interface.
I also had to give the Gateway a Java Service Interface as there is no return value, so I found it waa expecting (and didn't receive) a reply, as the default interface was RequestReplyExchanger, so we have:-
Code:
<int:service-activator id="errorHandlingActivator"
input-channel="submission-jms" ref="processSubmissionGatewayHandler" >
</int:service-activator>
<int:gateway id="errorHandlingGateway"
default-request-channel="submission-gw"
service-interface="....ProcessTransactionGateway"
error-channel="submissionErrorChannel">
</int:gateway>
<int-xml:xpath-splitter id="itemSplitterTest"
input-channel="submission-gw"
output-channel="extractedPayloadChannel">
<int-xml:xpath-expression expression="/rootDoc/payload"
namespace-map="namespaceMapSubmission" />
</int-xml:xpath-splitter>
Service Interface for Gateway
Code:
public interface ProcessTransactionGateway {
@Transactional
public void processSubmission(Message<String> message);
}
The issue now is that when an Exception occurs, the 'errorChannel' processes the exception, but the JMS transaction still seems to see the exception and rollbacks, so the message gets re-delivered by the JMS container. Where as the errorchannel and flow at the gateway is supposed to supress the exception. I think the exception is propagating back to the service activator in front of the gateway.
The errorChannel flow does execute correctly, this goes to a Transformer' that transforms message, and puts the response onto a jms backed queue.
Code:
<int:transformer id="submissionToErrorReasonTransformer"
input-channel="submissionErrorChannel"
output-channel="ackPublishJMSChannel"
ref="submissionErrorTransformer"/>
<int-jms:channel id="ackPublishJMSChannel" queue="ackPublishDestination"
transaction-manager="transactionManager" concurrency="1-10"/>
Any thoughts ?
I also tried try-catch suppress in Service Activator but this isn't reached
Code:
@Component("processSubmissionGatewayHandler")
public class ProcessSubmissionGatewayHandler {
@Autowired
private ProcessTransactionGateway processTransactionGateway;
@ServiceActivator
@Transactional
public void processSubmission(Message<String> message) {
System.out.println(" #### ProcessSubmissionGatewayHandler");
try {
processTransactionGateway.processSubmission(message);
} catch (RuntimeException e) {
System.out.println(" #### RuntimeException caught in ProcessSubmissionGatewayHandler");
}
}
}