问题
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 oldjson:
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