I am using spring integration XML and want to know what is the best way to deal with error handling.
I am connecting to s3 using s3-inbound-streaming-channel-adapter
and then transforming the csv file from s3 bucket.
Potential errors that can happen are:
- Transformation Exception could happen if a line in the file is not valid and so can throw a custom error:
LineTransformationException
What if on s3 bucket an image file is placed by mistake and again could get Transformation Exception
s3 could be down and could get
Caused by: com.amazonaws.SdkClientException: Unable to execute HTTP request: Connect to localhost:4572 [localhost/127.0.0.1] failed: Connection refused
And the list of many known and unknown errors can go on...
So what is the best way to handle all these errors? Through custom
ErrorHandler
orexception-type-router
If doing it through
ErrorHandler
then how to cater for so many Exceptions.And is there a catch-all exception handler?
public class ErrorHandler {
public void handleFailure(Message errorMmessage) {
MessagingException payload = (MessagingException) errorMmessage.getPayload(); LOG.info(">>--- Exception --- " + payload.getCause());
}}
or
<int:exception-type-router input-channel="errorChannel"
default-output-channel="nullChannel">
<int:mapping exception-type="com.api.exception.TransformationException"
channel="transformErrorChannel"/>
<int:mapping exception-type="com.amazonaws.SdkClientException"
channel="clientErrorChannel"/>
</int:exception-type-router>
<int:channel id="transformErrorChannel"/>
<int:service-activator ref="errorHandler"
method="handleFailure"
input-channel="transformErrorChannel"
output-channel="nullChannel"/>
<int:service-activator ref="clientErrorHandler"
method="handleFailure"
input-channel="clientErrorChannel"
output-channel="nullChannel"/>