-1

I am trying to consume a soap ws by using a json input. I am stuck in converting the json to xml. How can I create flow that convert from json to soap xml format by using NiFi.

Walid
  • 3
  • 2

3 Answers3

0

There is no processor that directly converts JSON to XML. One option would be to use ExecuteScript with a Groovy script that did the conversion. It looks like there are some examples out there of converting JSON to XML with Groovy:

Is there a way to convert Json file to XML by using groovy script on soapUI?

Community
  • 1
  • 1
Bryan Bende
  • 18,320
  • 1
  • 28
  • 39
0

You could pipe the JSON content in your flow file into the ConvertRecord processor. This processor takes in a reader and a writer. You could then configure a JSON Tree Reader to parse your JSON content, and the writer would need to be an XMLRecordSetWriter. Make sure you specify the element name in the configuration of the writer. Now, this is a vanilla writer which simply creates an XML equivalent of your JSON.

Input:

{
   "firstname": "John",
   "lastname": "Doe",
   "age": "45",
}

Output:

<person>
   <firstname>John</firstname>
   <lastname>Doe</lastname>
   <age>45</age>
</person>

Now once you have the XML, you can pipe it through the TransformerXML processor. You should be able to set up the processor to use XSLT to create a SOAP XML payload as per your specification.

Srikanth Anusuri
  • 1,234
  • 9
  • 16
-1

I've a similar scenario, where Oracle registeres need to put in XML POST HTTP, one by one.

To solve I've created the follow flow, I putted some details (parameters/configurations) where I've setted:

1) ExecuteSQLRecord, details:

  • SQL select query: select id, ip from server_table
  • RecordWriter: JsonRecordSetWriter
  • Max Rows Per Flow File: 1

2) EvaluateJsonPath, details:

  • Destination: flowfile-attribute
  • additional propertie 1: local.id
  • additional value 1: $.[0].id
  • additional propertie 2: local.ip
  • additional value 2: $.[0].ip

3) ReplaceText, details:

  • Search Value: (?s)(^.*$)
  • Replacement Value (XML):
    <item>
        <id>${local.id}</id>
        <ip>${local.ip}</ip>
    </item>
  • Replacement Strategy: Always Replace

4) InvokeHTTP, details: