我可以使用带有有效负载的 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 oldjson:
evaluator (see JSON support in MEL).
因此,您需要将消息有效负载设置为您刚刚在 set-variable
中创建的字符串,并将现在使用的输入流替换为其实际内容:
<set-payload value="#[req]" />
关于mule - Mule 流中出现错误 - 消息有效负载的类型为 : byte[],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28751744/