mule - Mule 流中出现错误 - 消息有效负载的类型为 : byte[]

标签 mule esb mule-studio

我可以使用带有有效负载的 localhost url 访问名为 method 的子流(请参阅下面的代码片段)。 如果我必须指出,以下 xpath 表达式评估失败了

#[xpath://Envelope/Body/add] 错误提示消息有效负载类型为:byte[]

我尝试过使用转换器(字节数组到字符串、字节数组到对象、对象到 xml 等),但似乎没有任何方法可以解决这个问题。

<flow name="version1" >
    <http:inbound-endpoint ........ />
    <set-variable variableName="req" value="#[payload:java.lang.String]"/>
    <flow-ref name="method"/>
    <catch-exception-strategy>
        <logger level="ERROR" message="Exception occurred when invoking add/update operation. The payload submitted was: #[flowVars['req']]"/>      
    </catch-exception-strategy>
</flow>

<sub-flow name="method" >   
    <choice doc:name="Choice" >
        <when expression="#[xpath://Envelope/Body/add]">
            <flow-ref name="add_v1"/>
        </when>
        <when expression="#[xpath://Envelope/Body/update]" >
            <flow-ref name="update_v1"/>
        </when>
        <otherwise>
            <scripting:component>
                <scripting:script engine="Groovy">
                    <![CDATA[throw new Exception("Operation not found!");]]>
                </scripting:script>
            </scripting:component>
        </otherwise>
    </choice>
</sub-flow>

**ERROR**

Message : Failed to invoke ScriptComponent{method.component.568157096}. Component that caused exception is: ScriptComponent{method.component.568157096}. Message payload is of type: byte[]
Code : MULE_ERROR--2

最佳答案

这样:

<set-variable variableName="req" value="#[payload:java.lang.String]"/>

您使用入站输入流将其呈现为字符串。

BTW Assuming you're on Mule 3.3 or above, you should be using MEL and not the super old expression evaluation framework, ie: #[message.payloadAs(java.lang.String)] Same applies to the old json: evaluator (see JSON support in MEL).

因此,您需要将消息有效负载设置为您刚刚在 set-variable 中创建的字符串,并将现在使用的输入流替换为其实际内容:

<set-payload value="#[req]" />

关于mule - Mule 流中出现错误 - 消息有效负载的类型为 : byte[],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28751744/

相关文章:

json - Mule ESB,以类似 JSON 的格式返回数据库连接器数据

Mule - SFTP 远程归档

azure - 用于 EAI 的 Biztalk 与用于 EAI 场景的 ESB

java - 使用 SOAP WS 进行 ESB 和 Java 应用程序通信

java - Mule - MuleMessage.getPayloadString() 给我 java.io.IOException : Bad chunk size

java - 使用 Mule 发送格式化邮件

mysql - 根据 Mule 中 http 中发送的属性从数据库获取值

apache-camel - 你什么时候会使用企业服务总线和像 Apache Camel 这样的集成框架?

mysql - 功能未实现查询 : select * from alarm_status Parameters: []

Mule - 将文件放在哪里以便 Mule Studio 和 Mule Standalone 可以读取它?