BreenDeen
BreenDeen

Reputation: 732

Until-Successful failureExpression condition not working

I created a simple flow which creates a list of names transforms it. The transformer throws an IllegalArgumentException to break the flow. Unfortunately, the failureExpression does not work even though an exception is thrown. It doesn't match any exceptions. I have included the flow and the transformer.

Here is my configuration:

<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:scripting="http://www.mulesoft.org/schema/mule/scripting"
    xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core"
    xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
    xmlns:spring="http://www.springframework.org/schema/beans" xmlns:vm="http://www.mulesoft.org/schema/mule/vm"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="
        http://www.mulesoft.org/schema/mule/scripting    
        http://www.mulesoft.org/schema/mule/scripting/current/mule-scripting.xsd     
        http://www.springframework.org/schema/beans 
        http://www.springframework.org/schema/beans/spring-beans-current.xsd
        http://www.mulesoft.org/schema/mule/core   
        http://www.mulesoft.org/schema/mule/core/current/mule.xsd
        http://www.mulesoft.org/schema/mule/vm   
        http://www.mulesoft.org/schema/mule/vm/current/mule-vm.xsd 
        http://www.mulesoft.org/schema/mule/http    
        http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd">

    <spring:beans>
        <spring:bean name="transf" class="com.until.sucessful.tests.StringAppenderTransformer" />
        <spring:bean id="objectStore" class="org.mule.util.store.SimpleMemoryObjectStore" />
    </spring:beans>

    <http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration" />

    <flow name="untilsuccessfultestsFlow">
        <http:listener config-ref="HTTP_Listener_Configuration" path="/mytest" doc:name="HTTP" />
        <splitter expression="#[xpath3('//Names')]" doc:name="Splitter" />
        <until-successful maxRetries="5" millisBetweenRetries="5000" doc:name="Until Successful" objectStore-ref="objectStore" failureExpression="#[exception is java.lang.IllegalArgumentException)]">
            <vm:outbound-endpoint path="process-vm" exchange-pattern="request-response" />
        </until-successful>
        <logger level="INFO" message="After the scoped processor :: #[payload]" doc:name="Logger" />
    </flow>

    <flow name="processorFlow">
        <vm:inbound-endpoint path="process-vm" exchange-pattern="request-response" />
        <logger level="INFO" message="Before component #[payload]" doc:name="Logger" />
        <transformer ref="transf" />
    </flow>
</mule>

Here is my Transformer

public class StringAppenderTransformer extends AbstractTransformer {

    @Override
    protected Object doTransform(Object src, String enc) throws TransformerException {
        String payload = (String) src;
        List<String> results = new ArrayList<>();
        System.out.println("Upon entry in transformer payload is :: " + payload);
        System.out.println("About to return from transformer payload is :: " + payload.split("\\s+"));
        int i = 1;
        for (String args : payload.split("\\s+")) {
            System.out.println("" + i + " " + args);
            i++;
            if (args != null && args.trim().equals("")) {
                results.add(args);
            } else {
                throw new IllegalArgumentException("Break the Flow!!!!!!");
            }

        }

        return results;
    }
}

Upvotes: 0

Views: 644

Answers (1)

mario martinez
mario martinez

Reputation: 297

According to documentation : https://docs.mulesoft.com/mule-user-guide/v/3.5/until-successful-scope

failureExpression

Specifies an expression that, when it evaluated to true, determines that the processing of one route was a failure. If no expression is provided, only an exception will be treated as a processing failure.

So 2 options, remove that expression or be sure that the MEL return true. #[exception.causeMatches("java.lang.IllegalArgumentException")]

Upvotes: 0

Related Questions