简体   繁体   中英

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

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?

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>

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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