Spring integration chain error handling -


need in error handling in chain during splitter , aggregator flow synchronous channel. below use case , synchronous channel. in chain there set of service activator perform business logic. if there exception in service activator present in chain, want handled in chain , continue other splitted messages.

inorder that, have tried adding header enricher error handler in chain.but did not work. suggestion.

object1 contains list < object2 >

flow:

list < object1 > --> splitter1 (for object1) --> splitter2 (for object2) --> chain --> aggregator --> aggregator

code

   <int:chain input-channel="ch3" output-channel="ch10"  >       <int:header-enricher>         <int:error-channel  ref="exception1" ></int:error-channel>     </int:header-enricher>     <int:service-activator ref="myservice" method="method1"></int:service-activator>     <int:service-activator ref="myservice" method="method2"></int:service-activator>    <int:service-activator ref="myservice" method="method3"></int:service-activator>     <int:service-activator ref="myservice" method="method4"></int:service-activator> </int:chain>       <!-- exception channel chain , output should go chain output channel -->          <int:chain input-channel="exception1" output-channel="ch10"  >         <int:service-activator ref="exp" method="myexception"></int:service-activator>       </int:chain> 

unfortunately doesn't work way. error-channel header asynchronous cases, too. allows override default behavior in messagepublishingerrorhandler pollablechannel , channels executor. in other words when can't try...catch if talk in raw java words.

so, fix requirements should rely on try...catch function particular <service-activator>. called expressionevaluatingrequesthandleradvice , must configured on <request-handler-advice-chain>.

in case should configure advice like:

<bean class="expressionevaluatingrequesthandleradvice">     <property name="trapexception" value="true"/>     <property name="onfailureexpression" value="#exception"/>     <property name="failurechannel" value="myerrorchannel"/> </bean> 

the trapexception="true" allows not re-throw exception top level. in case <splitter>.

the onfailureexpression says send failurechannel catch block.

the failurechannel desired error-channel handle <service-activator> failures.

the source code looks like, way:

   try {         object result = callback.execute();         if (this.onsuccessexpression != null) {             this.evaluatesuccessexpression(message);         }         return result;     }     catch (exception e) {         exception actualexception = this.unwrapexceptionifnecessary(e);         if (this.onfailureexpression != null) {             object evalresult = this.evaluatefailureexpression(message, actualexception);             if (this.returnfailureexpressionresult) {                 return evalresult;             }         }         if (!this.trapexception) {             throw actualexception;         }         return null;     } 

since prevent re-throw trapexception="true", end on return null. , having <service-activator> null-payload loyalty allow our <splitter> go ahead other messages.

hth


Comments