Home > Mobile >  Transform JSON message from XML which has 2 namespaces in WSO2 EI
Transform JSON message from XML which has 2 namespaces in WSO2 EI

Time:11-17

I have xml payload and I want to convert it to json message. For that, I used a payload factory mediator with freemarker template. My XML has 2 namespaces.

<?xml version="1.0" encoding="utf-8"?>
<AAA xmlns="http://www.example.com/XMLSchema">
    <BBB>
        <abc>xxxxxxx</abc>
        <msg>9212840000000996</msg>
        <ref>x212840000000078</ref>
    </BBB>
    <CCC xmlns="http://www.example.com/sc1">
        <cf1>
            <edg>N</edg>
            <nic>000265</nic>
            <ccc>I</ccc>
            <nnn>TESTNOTIF5</nnn>
        </cf1>
    </CCC>
</AAA>

This is my payload factory mediator which I implemented based on the documents.

<payloadFactory media-type="json" template-type="freemarker">
        <format><![CDATA[
<#ftl ns_prefixes={"n1": "http://www.example.com/XMLSchema", "n2": "http://www.example.com/sc1"}
      output_format="XML">
        {  
        "aaaaaa": "TestValue1", 
        "bbbb": "$payload.n1:AAA.n2:CCC.n2:cf1.n2.nic", 
        "ccc": "1299"}]]></format>
        <args/>
    </payloadFactory>

But I can't save this implementation from the integration studio. What is the error here?

CodePudding user response:

It seems this option is only available on API Manager 4.0. The Micro Integrator documentation about the PayloadFactory does not mention the freemarker template.

Latest Micro integrator docs on PayloadFactory

you could try the following

<payloadFactory media-type="json">
    <format>
    {  
    "aaaaaa": "TestValue1", 
    "bbbb": "$1", 
    "ccc": "1299"}</format>
    <args>
        <arg expression="//ns1:CCC/ns1:cf1/ns1:nic" evaluator="xml" xmlns:ns1="http://www.example.com/sc1"/>
    </args>
</payloadFactory>

CodePudding user response:

if you have soap services to be transformed into REST APIs, I did not see an easier way than Apinizer does, I know because we did it :)

Just wsdl is enough for transformation, all things done automaticaly and if you need customizations there are many advanced features it has. You can have a look its documentation from here

  • Related