本文介绍了如果将Dataweave Transformer有效负载中使用的flowVar转换为Map,则为ule子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个Mule Dataweave Transformer出现错误的问题,这仅在以下情况下发生:-

I have an issue with a Mule Dataweave Transformer getting an error, this only occurs if :-

  1. 目前有一个浓缩器,包裹着json:json-to-object-transformer

  1. An enricher is present wrapping a json:json-to-object-transformer

 <enricher target="#[flowVars.myVar]" doc:name="Message Enricher"> 
    <json:json-to-object-transformer returnClass="java.util.HashMap" doc:name="JSON to Object"/>
</enricher>

  • DataVave变压器中包含flowVar

  • A flowVar is involved in the Dataweave Transformer

    该异常发生在第二个dataweave上:-

    The exception occurs on the 2nd dataweave :-

    ERROR 2017-08-15 09:09:52,239 [amqpReceiver.02] org.mule.exception.RollbackMessagingExceptionStrategy: 
    ********************************************************************************
    Message               : Exception while executing: 
    {bar=1, foo=0}
     ^
    Unexpected character 'b' at index 1 (line 1, position 2), expected '"'
    Payload               : com.mulesoft.weave.reader.ByteArraySeekableStream@39e7a0d3
    Element               : /subscribe-to-changeFlow4/processors/4 @ voa-009-mule-authorisation-search-api:test3.xml:58 (Transform Message)
    Element XML           : <dw:transform-message doc:name="Transform Message">
                            <dw:input-payload mimeType="application/json"></dw:input-payload>
                            <dw:set-payload>%dw 1.0%output application/json---{field1: payload.foo,field2: payload.bar,field3: flowVars.myFlowVar}</dw:set-payload>
                            </dw:transform-message>
    --------------------------------------------------------------------------------
    Root Exception stack trace:
    com.mulesoft.weave.reader.json.JsonReaderException: Unexpected character 'b' at index 1 (line 1, position 2), expected '"'
        at com.mulesoft.weave.reader.json.JsonTokenizer.fail(JsonTokenizer.scala:193)
        at com.mulesoft.weave.reader.json.JsonTokenizer.require(JsonTokenizer.scala:190)
        at com.mulesoft.weave.reader.json.JsonTokenizer.readString(JsonTokenizer.scala:74)
        at com.mulesoft.weave.reader.json.JsonTokenizer.readObjectMembers(JsonTokenizer.scala:146)
        at com.mulesoft.weave.reader.json.JsonTokenizer.com$mulesoft$weave$reader$json$JsonTokenizer$$readObject(JsonTokenizer.scala:140)
        at com.mulesoft.weave.reader.json.JsonTokenizer$$anonfun$readValue$1.apply$mcV$sp(JsonTokenizer.scala:37)
    

    发生的事情是,将flowVar添加到第二数据编织中后,有效负载似乎显示为Map而不是JSON.

    What happens is as soon as a flowVar is added into the 2nd data weave, then the payload seems to show as a Map rather than JSON.

    • 需要使用带有嵌套json-to-object-transformer的浓缩器来获取有效负载并允许访问JSON.如果浓缩器被移除,则效果很好
    • 将json-to-object-transformer之后的流重置为
    • 如果从第二个dataweave中移除了flowVar,则它工作正常

    测试用例

      <flow name="subscribe-to-changeFlow4" processingStrategy="synchronous">
    
            <amqp:inbound-endpoint numberOfChannels="1" ref="authorisationChangeQueueDef4" responseTimeout="10000" doc:name="authorisation-change-consumer" />
    
            <dw:transform-message doc:name="Transform Message">
            <dw:set-payload>
    <![CDATA[%dw 1.0
    %output application/json
    ---
    {
        foo:0,
        bar:1
    }]]>
            </dw:set-payload>
        </dw:transform-message>
    
        <enricher target="#[flowVars.myVar]" doc:name="Message Enricher"> 
            <json:json-to-object-transformer returnClass="java.util.HashMap" doc:name="JSON to Object"/>
        </enricher>
    
        <expression-component doc:name="Expression">
            <![CDATA[payload.seek(0);]]>
        </expression-component>
    
        <set-variable variableName="myFlowVar" value="1234" doc:name="Variable" />
    
        <dw:transform-message doc:name="Transform Message">
            <dw:input-payload mimeType="application/json"/>
            <dw:set-payload>
    <![CDATA[%dw 1.0
    %output application/json
    ---
    {   
        field1: payload.foo,
        field2: payload.bar,
        field3: flowVars.myFlowVar
    }
    ]]> 
            </dw:set-payload>
        </dw:transform-message>
    
        <logger  level="INFO" message="#[message.payloadAs(java.lang.String)]" doc:name="Logger all "/>
    
    
        </flow>
    

    推荐答案

    这可能是Mule中的 bug ,您可以在 M子吉拉

    This is probably a bug in Mule and you can raise it in Mule jira

    您使用的是哪个Mule运行时版本?

    Which Mule runtime version are you using?

    我在本地进行了测试,并使用Mule 运行时3.8.0 和Mule 运行时3.8.1 发现了此问题:

    I tested locally and found this issue with Mule runtime 3.8.0 and Mule runtime 3.8.1:

    工作正常,并且与Mule 运行时3.8.2 和Mule 3.8.5
    还对Mule 3.7.3 进行了本地测试,效果如下:-

    but worked fine with Mule runtime 3.8.2 and Mule 3.8.5
    Also tested with Mule 3.7.3 locally and it worked fine as below:-

    这篇关于如果将Dataweave Transformer有效负载中使用的flowVar转换为Map,则为ule子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

  • 10-29 05:43