MULE【Please retrieve the value from messageList or use getPayload(DataType.BYTE_ARRAY_DATA_TYPE)】错误

错误描述
Please retrieve the value from messageList or use getPayload(DataType.BYTE_ARRAY_DATA_TYPE)
java.lang.RuntimeException: java.lang.UnsupportedOperationException: getPayloadAsBytes(), There has been an attempt to directly access the payload of a message collection, which is unsupported.
Please retrieve the value from messageList or use getPayload(DataType.BYTE_ARRAY_DATA_TYPE)
如果是正在使用Collection Splitter元件,并且使用不当,则会出现上述错误,解决该错误的方法是将Collection Splitter元件放到Async域中,Collection SplitterPayload集合拆分成一个个部分,供后面的Message Processor进一步处理,如果不放在Async中,则Response无法一下子处理,因此抛出UnsupportedOperationException异常

Flow结构图

使用 Collection Splitter 拆分数组,并且用 Logger记录拆分后的内容,最后返回一句话。如果不放在Async中,尽管仍然可以打印出正确的结果,却在最后抛出异常。

xml文档

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:json="http://www.mulesoft.org/schema/mule/json" xmlns:db="http://www.mulesoft.org/schema/mule/db" 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:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="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/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/db http://www.mulesoft.org/schema/mule/db/current/mule-db.xsd
http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd">
    <http:listener-config name="HTTP_Listener_Configuration1" host="0.0.0.0" port="8082" doc:name="HTTP Listener Configuration"/>
    <flow name="Collection_Splitter_Test">
        <http:listener config-ref="HTTP_Listener_Configuration1" path="/splitter" doc:name="HTTP"/>
        <set-payload value="#[[100,101,102]]" doc:name="&#35774;&#32622;&#19968;&#20010;&#25972;&#24418;&#25968;&#32452;[100,101,102]"/>
        <async doc:name="Async">
            <collection-splitter doc:name="Collection Splitter"/>
            <logger message="#[payload]" level="INFO" doc:name="&#35760;&#24405;&#32463;&#36807;Collection Splitter&#25286;&#20998;&#21518;&#30340;payload"/>
        </async>
        <set-payload value="#['&#25286;&#20998;&#25104;&#21151;']" doc:name="Set Payload"/>
    </flow>
</mule>

参考资料
stackoverflow回答参考

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值