简体   繁体   English

使用 dataweave 2.0 在 mule 4 中转换 xml 有效负载

[英]transform the xml payload in mule 4 using dataweave 2.0

In my case, I've done the XML payload transform using Java in Mule 3.就我而言,我在 Mule 3 中使用Java完成了 XML 有效负载转换。

But in Mule 4, could we be able to transform the xml payload using Dataweave 2.0.但是在 Mule 4 中,我们能否使用Dataweave 2.0 转换 xml 有效载荷。

I have an XML Request and Expected response payload.我有一个 XML 请求和预期响应负载。 But I don't know to transform using Dataweave 2.0但我不知道使用 Dataweave 2.0 进行转换

Input XML: https://github.com/Manikandan99/demo/blob/master/input_xml_request输入 XML: https://github.com/Manikandan99/demo/blob/master/input_xml_request

Output XML: https://github.com/Manikandan99/demo/blob/master/output_xml Output XML: https://github.com/Manikandan99/demo/blob/master/output_xml

Java code for my logic: https://github.com/Manikandan99/demo/blob/master/transform_xml.java Java 我的逻辑代码: https://github.com/Manikandan99/demo/blob/master/transform_xml.Z93F725A07423FE1C889F448B33D21F46

Note:笔记:

        * Difference between the input and output payload is that the value of the DTOStep node should be updated.
        * The attribute value of DTOStep is autoincremented from 500 each time.

Please assist me.请帮助我。

In generic terms there are two main ways to resolve this in Mule 4.一般而言,在 Mule 4 中有两种主要方法可以解决此问题。

  1. Implement the desired transformation in DataWeave 2. This is usually recommended and is the natural way in Mule 4.在 DataWeave 2 中实现所需的转换。这通常是推荐的,也是 Mule 4 中的自然方式。
  2. Migrate the Mule 3 Java code.迁移 Mule 3 Java 代码。 This implies removing any references to Mule Java APIs, types, class, interfaces or packages from your Java code.这意味着从您的 Java 代码中删除对 Mule Java API、类型、class、接口或包的任何引用。 Mule 4 expects plain Java code with not usage of Mule internals. Mule 4 需要简单的 Java 代码,而不使用 Mule 内部。 For example that means no references to Mule events, messages nor variables.例如,这意味着不引用 Mule 事件、消息或变量。 Just put everything as parameters of the methods you are calling and use the Java module.只需将所有内容作为您正在调用的方法的参数并使用 Java 模块。 Don't assume Mule is magically sending DOM to your code.不要假设 Mule 会神奇地将 DOM 发送到您的代码中。 To invoke Java code in Mule 4 read the instructions in the documentations of the Java Module.要在 Mule 4 中调用 Java 代码,请阅读 Java 模块文档中的说明。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM