문제

I'm new to mule, please help me on this logic. Actually in my flow i have choice message processor, Expression which is not satisfy it will go to default in choice. After that i have flow reference. I don't want message goes to default(choice) has to be populate to flow reference.Instead it has to go to choice exception strategy which i configured in that flow. So i need to throw some exception in default. Actually i have a very big flow, i made it simple to understand. Please find by xml config.

        <flow name="Choice" doc:name="Choice">
    <file:inbound-endpoint path="C:\Users\Star\Desktop\Mule\FilePath1" responseTimeout="10000" doc:name="File"/>
    <byte-array-to-string-transformer doc:name="Byte Array to String"/>
    <choice doc:name="Choice">
        <when expression="#[xpath('fn:local-name(/root/*[2])')=='book']">
            <file:outbound-endpoint path="C:\Users\Star\Desktop\Mule\FilePath2" responseTimeout="10000" doc:name="File"/>
        </when>
        <otherwise>
            <file:outbound-endpoint path="C:\Users\Star\Desktop\Mule\FilePath3" responseTimeout="10000" doc:name="File"/>
        </otherwise>
    </choice>
    <flow-ref name="SampleService" doc:name="Flow Reference"/>
    <catch-exception-strategy doc:name="Catch Exception Strategy">
        <logger message="*****#[exception]****" level="INFO" doc:name="Logger"/>
    </catch-exception-strategy>
</flow>
<flow name="SampleService" doc:name="SampleService">
    <file:inbound-endpoint path="C:\Users\Star\Desktop\Mule\FilePath4" responseTimeout="10000" doc:name="File"/>
</flow>

Kindly suggest me any standard way to throw exception in Mule.I also tried keeping

            <test:component  throwException="true"/> 

but it is throwing exception like - "The prefix "test" for element "test:component" is not bound".

도움이 되었습니까?

해결책

To use the test:component you need to declare the test namespace, as you've done for all the other namespaces Mule uses. This said, not sure you want to use test elements in your production code.

One alternative is to use the null-component that always throws an exception when it receives a message, but this doesn't give you control of the thrown exception.

The other alternative, is to throw any exception you want from a Groovy component.

Bear in mind that exceptions are wrapped by Mule infrastructure: you'll have to use the ExceptionUtils to dig in the stack and find the root cause.

다른 팁

You can also use the Validation component if you don't want to write code. Just create a new 'Is True' validator and set the expression to #[false]. On the customize page set your error and the message you want to return, I used org.mule.module.apikit.exception.NotFoundException, but you can use the lookup too. Took me forever to figure this out.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top