Thursday, September 13, 2012

SpEL and Returning an Object From Void

SpEL and Returning an Object From Void

an odd scenario encountered at the client; they wanted to use a service via a service-activator in Spring Integration but use the exception and void as the true/false.  that is, the service validated an object and returned 'void' (nothing) if it was ok, and threw and exception if it was not.  but, in the Spring Integration pattern, they wanted the object to continue on after invoking the service-activator.  this pattern wouldn't normally work as a void in a service-activator doesn't return the object, and the message flow dies.  so, how to do it?

well, thanks to some insight from a colleague, this is the SpEL-based solution we came up with...

as you can see, using SpEL in the if/else allowed the return of the existing 'untouched' payload.  an exception, if thrown, can be handled via Spring Integration's normal patterns.

No comments:

Post a Comment