Error in mule flow - Message payload is of type: byte[]

你离开我真会死。 提交于 2019-12-12 20:48:10

问题


I am able to get to the subflow named method (refer snippet below) using localhost url with a valid payload. If I had to pinpoint, following xpath expression evaluation is failing

#[xpath://Envelope/Body/add] with an error saying Message payload is of type: byte[]

I have tried using transformers (byte-array-to-string, byte-array-to-object, object-to-xml etc.) but nothing seems to resolve this.

<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

回答1:


With this:

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

you consume the inbound input stream to render it as a 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).

So you need to set the message payload to the string you've just created in set-variable, replacing the now consumed input stream with its actual content:

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



回答2:


In the flow version1

after the http inbound endpoint, add object-to-string transformer. the xpath expression evalautes with out the error.



来源:https://stackoverflow.com/questions/28751744/error-in-mule-flow-message-payload-is-of-type-byte

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!