2
votes

In mule flow i have a file inbound endpoint which reads .edi files and generates xml files. If any exception is thrown while parsing edi file, i need catch it and send a custom error message to spring controller, from which mule flow is called. How to do this in mule integrated spring project?

Below are my mule flow end points:

    <file:inbound-endpoint path="D:\smooks\test docs\in"
        pollingFrequency="3000" responseTimeout="10000" doc:name="Incoming File"
        transformer-refs="SmooksTransformer">
        <file:filename-regex-filter pattern="(.*).edi"
            caseSensitive="false" />
    </file:inbound-endpoint>
    <file:outbound-endpoint path="D:\smooks\test docs\out" responseTimeout="10000" 
        doc:name="Outgoing File" outputPattern="#[header:originalFilename].xml"/>
2

2 Answers

1
votes

Looking at you've shared of your flow, this "spring controller, from which mule flow is called" doesn't make sense: there is no way nor need to call the flow as then file inbound endpoint is a poller and will fire regularly without any need to call it.

Because this flow is not invoked synchronously, the only way to have a custom bit of code being informed in case an exception is thrown is to listen to Mule notifications. Creating a listener that listens for [org.mule.context.notification.ExceptionNotification][1] and calls a method on your controller bean should work.

The way you start Mule will be a problem though: you start it in its own context so the beans defined in Mule will have no way of reaching the beans in your existing Spring application context. This documentation page explains how you could resolve this by making the Mule application context a child of the existing Spring one, which would allow calling the controller.

If this is too complex for you. here is an alternative: add an exception strategy in your flow that sends errors to a one-way VM queue and have your Spring controller use the muleClient bean to regularly poll the content of this VM queue (with request()). That way you will bring the errors back into your main Spring context.

0
votes

You need to import your spring config that had your controller bean and use a custom exception strategy in your flow to pass details to your controller in it like:

<spring:ref bean="Controller" />