Mule esb和Transform消息(波变换组件)

时间:2016-03-30 12:53:42

标签: mule mule-component dataweave

我在使用转换消息组件和我不理解的mule ESB时遇到问题。 我有一个很好的简单流程,一开始是Http端点,最后是转换消息组件,将一个JSON转换为另一个JSON。

现在,当我尝试在将消息转换为变量之前存储有效负载,然后将有效负载设置为该变量时,我在转换消息组件上获得异常: 类型不匹配      发现:name,:string   required:name,:object(com.mulesoft.weave.engine.ast.dynamic.DynamicDispatchException)   com.mulesoft.weave.engine.ast.dynamic.DynamicDispatchNode:65(null)

这是一个有效的流程,下面是不起作用的流程。 有效的流程:

<mule xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw" xmlns:metadata="http://www.mulesoft.org/schema/mule/metadata" 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/ee/dw http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd">
    <http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8085" doc:name="HTTP Listener Configuration"/>
    <flow name="testFlow">
        <http:listener config-ref="HTTP_Listener_Configuration" path="/test" doc:name="HTTP"/>
        <byte-array-to-string-transformer doc:name="Byte Array to String"/>
        <dw:transform-message metadata:id="b8a77df6-4692-4c52-b572-b6a175e7467e" doc:name="Transform Message">
            <dw:set-payload><![CDATA[%dw 1.0
%output application/json
---
{
    id: payload.transfer-id,
    created-record-status: 'accepter'
}]]></dw:set-payload>
        </dw:transform-message>
    </flow>
</mule>

不起作用的流程&gt;

<mule xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw" xmlns:metadata="http://www.mulesoft.org/schema/mule/metadata" 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/ee/dw http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd">
    <http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8085" doc:name="HTTP Listener Configuration"/>
    <flow name="testFlow">
        <http:listener config-ref="HTTP_Listener_Configuration" path="/test" doc:name="HTTP"/>
        <byte-array-to-string-transformer doc:name="Byte Array to String"/>
        <set-variable variableName="OriginalPayload" value="#[payload]" doc:name="Variable"/>
        <set-payload value="#[flowVars.OriginalPayload]" doc:name="Set Payload"/>
        <dw:transform-message metadata:id="b8a77df6-4692-4c52-b572-b6a175e7467e" doc:name="Transform Message">
            <dw:set-payload><![CDATA[%dw 1.0
%output application/json
---
{
    id: payload.transfer-id,
    created-record-status: 'accepter'
}]]></dw:set-payload>
        </dw:transform-message>
    </flow>
</mule>

当我在转换之前将logger放入日志有效负载时,它在两个流程中都是相同的.... 有人能告诉我我做错了什么吗?

谢谢伊万。

1 个答案:

答案 0 :(得分:1)

由于设置的有效负载缺少mime类型,你得到的错误使用下面的xml,我已经测试过并且工作正常。<set-payload value="#[flowVars.OriginalPayload]" doc:name="Set Payload" mimeType="application/json"/>

<mule xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw" xmlns:metadata="http://www.mulesoft.org/schema/mule/metadata" 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/ee/dw http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd">
    <http:listener-config name="HTTP_Listener_Confi" host="localhost" port="8085" doc:name="HTTP Listener Configuration"/>
    <flow name="testFlow">
        <http:listener config-ref="HTTP_Listener_Confi" path="/test" doc:name="HTTP"/>
        <byte-array-to-string-transformer doc:name="Byte Array to String"/>
        <logger message="#[payload]" level="INFO" doc:name="Logger"/>
        <set-variable variableName="OriginalPayload" value="#[payload]" doc:name="Variable"/>
        <set-payload value="#[flowVars.OriginalPayload]" doc:name="Set Payload" mimeType="application/json"/>
        <dw:transform-message metadata:id="b8a77df6-4692-4c52-b572-b6a175e7467e" doc:name="Transform Message">
            <dw:set-payload><![CDATA[%dw 1.0
%output application/json
---
{
    id: payload.transfer-id,
    created-record-status: 'accepter'
}]]></dw:set-payload>
        </dw:transform-message>
    </flow>
</mule>