I have a spring-integration transformer that accepts a org.w3c.dom.Document and returns a domain object. And this is nice. If there are elements missing I raise an application exception.
However, I’d like to get that exception onto the error channel but instead the way it currently works by bubbling back through a chain of handlers. It would be nice if there a way of specifying an error channel in the case of a failed transform.
I could:
- pass the message through a router to check for missing elements before (or after) the transformer
- route the message
However that means both parsing the document twice and a bit of a re-write.
The answer I came up with was to change the return type of the transformer from the domain POJO to a Message. And then, in the exception case, to return a Message. The exception is then routed to the correct handler by a Payload Type Router.