如何外部化Mule DataWeave中重复的SOAP响应属性?

时间:2018-11-02 23:32:23

标签: soap mule integration dataweave soapheader

我正在Dataweave中构造一个SOAP响应。响应的某些组件(ESBHeader)在多个流中重复。我还需要为每个请求设置状态代码和消息。

我需要将这些重复的行加载到通用dwl文件中的通用方法来优化代码。我该怎么办?

flow1的示例响应消息1

{
        ns1#ResponseMsg1: {
            ns0#ESBHeader: {
                ns0#InitialContext @(CreationTime: flowVars.req.ResponseMsg1.ESBHeader.InitialContext.@CreationTime, TrackingID: flowVars.req.ResponseMsg1.ESBHeader.InitialContext.@TrackingID): {
                    ns0#Actor @(Component: flowVars.req.ResponseMsg1.ESBHeader.InitialContext.Actor.@Component , Operation: flowVars.req.ResponseMsg1.ESBHeader.InitialContext.Actor.@Operation): null
                },
                ns0#MessageContext  : {
                    ns0#Actor @(Component: flowVars.req.ResponseMsg1.ESBHeader.MessageContext.Actor.@Component  , Operation: flowVars.req.ResponseMsg1.ESBHeader.MessageContext.Actor.@Operation): null
                },
                ns0#Status: {
                    ns0#Code: "Success",
                    ns0#Message: ""
                }
            },
            ns1#var1: flowVars.var1
        }
    }

流程2的示例响应消息2

{
        ns1#ResponseMsg2: {
            ns0#ESBHeader: {
                ns0#InitialContext @(CreationTime: flowVars.req.ResponseMsg2.ESBHeader.InitialContext.@CreationTime, TrackingID: flowVars.req.ResponseMsg2.ESBHeader.InitialContext.@TrackingID): {
                    ns0#Actor @(Component: flowVars.req.ResponseMsg2.ESBHeader.InitialContext.Actor.@Component , Operation: flowVars.req.ResponseMsg2.ESBHeader.InitialContext.Actor.@Operation): null
                },
                ns0#MessageContext  : {
                    ns0#Actor @(Component: flowVars.req.ResponseMsg2.ESBHeader.MessageContext.Actor.@Component  , Operation: flowVars.req.ResponseMsg2.ESBHeader.MessageContext.Actor.@Operation): null
                },
                ns0#Status: {
                    ns0#Code: "Failure",
                    ns0#Message: ""
                }
            },
            ns1#var1: flowVars.var1,
            ns1#var2: flowVars.x.var2
        }
    }

非常感谢任何指针。

非常感谢。

1 个答案:

答案 0 :(得分:1)

如果您使用的是Mule 4,则可以轻松创建和导入DataWeave module

在Mule 3中,有一种类似的方法,但实际上并不受支持,您可能会遇到一些问题。在您的脚本中,它看起来像Mule3。此blog post说明了该方法。