Mule 异常是否通过组件绑定传播?

Mule 异常是否通过组件绑定传播?,mule,Mule,使用下面的Mule配置和Java代码,我无法让Mule通过组件绑定传播异常。如何让远程服务抛出的异常传播到调用组件?Mule EE 3.2.2 谢谢 骡子配置 <mule ...> <flow name="Test"> <vm:inbound-endpoint path="Test" exchange-pattern="request-response" /> <component class="foo.Component">

使用下面的Mule配置和Java代码,我无法让Mule通过组件绑定传播异常。如何让远程服务抛出的异常传播到调用组件?Mule EE 3.2.2

谢谢

骡子配置

<mule ...>
    <flow name="Test">
    <vm:inbound-endpoint path="Test" exchange-pattern="request-response" />
    <component class="foo.Component">
        <binding interface="foo.Interface" method="bar">
                <vm:outbound-endpoint path="Interface.bar"
                    exchange-pattern="request-response" />
        </binding>
        </component>
    </flow>

    <flow name="Interface.bar">
        <vm:inbound-endpoint path="Interface.bar" 
            exchange-pattern="request-response" />
        <scripting:component>
            <scripting:script engine="groovy">
                throw new Exception();
            </scripting:script>
        </scripting:component>
    </flow>
</mule>
Interface.java

package foo;

public interface Interface {

    String bar() throws Exception;

}
司机

package foo;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.runners.MockitoJUnitRunner;
import org.mule.api.MuleException;
import org.mule.api.client.MuleClient;
import org.mule.tck.junit4.FunctionalTestCase;


@RunWith(MockitoJUnitRunner.class)
public class ATest extends FunctionalTestCase {

    @Test(expected = Exception.class)
    public void willItThrowException() throws MuleException {
        final MuleClient client = muleContext.getClient();
        client.send("vm://Test", "", null, RECEIVE_TIMEOUT);
    }

    @Override
    protected String getConfigResources() {
        return "app/mule-config.xml";
    }

}

异常不是通过消息交换作为“抛出的异常”传播的,而是作为飞行中消息上的异常有效负载传播的

因此,调用
vm://Interface.bar
的响应应该是一条消息,其中包含一个与您抛出的异常一起设置的异常负载。因为绑定将主有效负载绑定到接口,所以无法从组件访问它

一个选项是在
接口.bar
流中添加一个响应转换器,它将异常负载(如果有)复制到主负载,并允许bar()返回对象(有时是字符串,有时是异常)。或者使用String并将返回的错误定义为String

package foo;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.runners.MockitoJUnitRunner;
import org.mule.api.MuleException;
import org.mule.api.client.MuleClient;
import org.mule.tck.junit4.FunctionalTestCase;


@RunWith(MockitoJUnitRunner.class)
public class ATest extends FunctionalTestCase {

    @Test(expected = Exception.class)
    public void willItThrowException() throws MuleException {
        final MuleClient client = muleContext.getClient();
        client.send("vm://Test", "", null, RECEIVE_TIMEOUT);
    }

    @Override
    protected String getConfigResources() {
        return "app/mule-config.xml";
    }

}