Hello Guys
I am trying to solve the problem of configure input/output channels when I use a int:service-activator together with a int:exception-type-router.
Before to follow just to recall in the section 5.1.2. Routing and Error handling appear the follow
I am assuming that any Exception would be generated or arise from a Service Activator and/or Transformer, perhaps from other endpoint, the point is handle the Exception thrown.Spring Integration also provides a special type-based router called
ErrorMessageExceptionTypeRouter for routing Error Messages
(Messages whose payload is a Throwable instance).
ErrorMessageExceptionTypeRouter is very similar to the PayloadTypeRouter.
In fact they are almost identical.
The only difference is that while PayloadTypeRouter navigates the instance hierarchy of a payload instance (e.g., payload.getClass().getSuperclass()) to find the most specific type/channel mappings,the ErrorMessageExceptionTypeRouter navigates the hierarchy of 'exception causes' (e.g., payload.getCause()) to find the most specific Throwable type/channel mappings.
I going to work with an ErrorMessage since it let has the payload explicitly of type Throwable
The follow code work fine (match colors for a better understanding)
I did realize the input-channel attribute of the int:exception-type-router element is mandatory, therefore must exists an exclusive message channel only to send and receive ErrorMessage exclusively for this type of RouterCode:<int:exception-type-router input-channel="myErrorChannel" > <int:mapping exception-type="com.manuel.jordan.exception.MyErrorMessageException" channel="myErrorMessageException"/> <int:mapping exception-type="java.lang.IllegalArgumentException" channel="illegalChannel"/> <int:mapping exception-type="java.lang.NullPointerException" channel="npeChannel"/> </int:exception-type-router> <int:service-activator id="errorServiceActivator01" input-channel="inicio" output-channel="myErrorChannel" method="serviceActivator03" ref="errorServiceActivator" /> <int:service-activator id="objectServiceActivator01" input-channel="myErrorMessageException" output-channel="final" method="serviceActivator03" ref="objectServiceActivator" />
Below the code of the method serviceActivator03 which belong to errorServiceActivator
The code work fine, I have some observations, doubts and confusion, please give me a handCode:public Message<?> serviceActivator03(Message<?> message)throws MyGlobalException{ logger.info("serviceActivator03 message: {}", message); boolean control = true; if(control){ logger.info("66666666"); MyErrorMessageException myErrorMessageException = new MyErrorMessageException("MyErrorMessageException"); ErrorMessage errorMessage = new ErrorMessage(myErrorMessageException); return errorMessage; } else return message; } }
1) the Service Activator has explicitly configured the output channel to myErrorChannel, therefore practically it call the Router (it is little illogic, read (2) ).
2) if my boolean variable control is changed to false, therefore the Exception never is thrown, the application work fine but the original Message sent it is lost, I think due the payload is not a Throwable type (I sent originally a String like payload).
3) To solve (1) and (2). How I could do the follow.
3.1) Has any amount of Service Activators where the output channel be free (I mean, not explicitly configure each output channel to some int:exception-type-router)
3.2) from 3.1 if only I have detected some error, classic try/catch, I want create the ErrorMessage and it should go explicitly to some int:exception-type-router through some configuration
Thanks in advanced


Reply With Quote

