2

I code a Spring Integration route that queries a SOAP and a REST WS and somehow aggregates the results. I use a bean as payload to gather the useful information along the way, two payload enrichers to query the web services and a transformer at the end to build the result.

Now my problem is that the REST WS returns (by design) HttpStatus.NOT_FOUND (404) if the system has no information about the entity I'm querying. That needs be considered a nominal use case. Spring Integration considers this by default an error and bails out. I need to handle this case properly, store null in my bean or something similar (I can handle that down the road) and proceed.

So I've tried adding an error-handler to the outbound-gateway but could not make this work. If I tell this is not an error (overriding hasError()) then SI tries to unmarshall the body of the response, which obviously does not work; same if I override handleError() and do nothing.

Maybe I'm not going in the right direction but I miss a better idea so... any help accepted with gratitude.

Her-Bak
  • 71
  • 7

1 Answers1

1

You can add for the <int-http:outbound-gateway> a ExpressionEvaluatingRequestHandlerAdvice as a nested <request-handler-advice-chain> and use its options: onFailureExpression, returnFailureExpressionResult = true. You may also consider to use failureChannel.

This way you catch that 404 NOT FOUND exception and return whatever you think is appropriate compensation result.

More information you can find in the Reference Manual and there is also a sample project on the matter.

Artem Bilan
  • 113,505
  • 11
  • 91
  • 118
  • Thank you! It took me a couple of days to figure out the exact settings but that was definitely the way to go. Happy to see the documentation exists even if it is not where I expected ;-) The two pointers to documentation and example have been especially useful (and much appreciated). – Her-Bak Mar 14 '18 at 22:45
  • @Her-Bak While it's been quite a while since this was posted, if you're able to update this Answer or your Question with the 'exact settings' it would be quite helpful for the Spring Integration knowledge base. – Andrew T Finnell Aug 02 '19 at 18:48