0
votes

i have this api

<api xmlns="http://ws.apache.org/ns/synapse" name="EosPlaces" context="/eosplaces"><resource methods="GET" uri-template="/comuni">
  <inSequence>
     <property name="comuni" expression="get-property('registry', 'gov:/eos/common/json/comuni.json')" scope="axis2" type="STRING"/>
     <payloadFactory media-type="json">
        <format>$1</format>
        <args>
           <arg evaluator="xml" expression="$ctx:comuni"/>
        </args>
     </payloadFactory>
     <property name="messageType" value="application/json" scope="axis2"/>
     <respond/>
  </inSequence></resource></api>

and this is the json stored in the registry with media type application/json:

{
    "comuni": [{
            "Denominazione": "Agliè",
            "Regione": "Piemonte",
            "Provincia": "Torino",
            "SiglaProv": "TO",
            "Belfiore": "A074"
        },
        {
            "Denominazione": "Airasca",
            "Regione": "Piemonte",
            "Provincia": "Torino",
            "SiglaProv": "TO",
            "Belfiore": "A109"
        },
        {
            "Denominazione": "Ala di Stura",
            "Regione": "Piemonte",
            "Provincia": "Torino",
            "SiglaProv": "TO",
            "Belfiore": "A117"
        },
        {
            "Denominazione": "Albiano d'Ivrea",
            "Regione": "Piemonte",
            "Provincia": "Torino",
            "SiglaProv": "TO",
            "Belfiore": "A157"
        },
        {
            "Denominazione": "Almese",
            "Regione": "Piemonte",
            "Provincia": "Torino",
            "SiglaProv": "TO",
            "Belfiore": "A218"
        },
        {
            "Denominazione": "Alpette",
            "Regione": "Piemonte",
            "Provincia": "Torino",
            "SiglaProv": "TO",
            "Belfiore": "A221"
        },
        {
            "Denominazione": "Alpignano",
            "Regione": "Piemonte",
            "Provincia": "Torino",
            "SiglaProv": "TO",
            "Belfiore": "A222"
        },
        {
            "Denominazione": "Andezeno",
            "Regione": "Piemonte",
            "Provincia": "Torino",
            "SiglaProv": "TO",
            "Belfiore": "A275"
        },
        {
            "Denominazione": "Andrate",
            "Regione": "Piemonte",
            "Provincia": "Torino",
            "SiglaProv": "TO",
            "Belfiore": "A282"
        },
        {
            "Denominazione": "Angrogna",
            "Regione": "Piemonte",
            "Provincia": "Torino",
            "SiglaProv": "TO",
            "Belfiore": "A295"
        }
    ]
}

I would like to read the json and ouput it when calling the api but the response is :

<Empty JSON content>

and the raw is : "HTTP/1.1 200 OK Host: 192.168.0.191:8280 Accept-Encoding: gzip,deflate Content-Type: application/json; charset=UTF-8 Date: Wed, 08 Apr 2020 12:00:19 GMT Transfer-Encoding: chunked Connection: Keep-A1live"

{}

Thank you

Update : if i log the property that pick the json from the registry, this is what i see in the log

ewoJCSJjb211bmkiOiBbewoJCQkJIkRlbm9taW5hemlvbmUiOiAiQWdsacOoIiwKCQkJCSJSZWdpb25lIjogIlBpZW1vbnRlIiwKCQkJCSJQcm92aW5jaWEiOiAiVG9yaW5vIiwKCQkJCSJTaWdsYVByb3YiOiAiVE8iLAoJCQkJIkJlbGZpb3JlIjogIkEwNzQiCgkJCX0sCgkJCXsKCQkJCSJEZW5vbWluYXppb25lIjogIkFpcmFzY2EiLAoJCQkJIlJlZ2lvbmUiOiAiUGllbW9udGUiLAoJCQkJIlByb3ZpbmNpYSI6ICJUb3Jpbm8iLAoJCQkJIlNpZ2xhUHJvdiI6ICJUTyIsCgkJCQkiQmVsZmlvcmUiOiAiQTEwOSIKCQkJfSwKCQkJewoJCQkJIkRlbm9taW5hemlvbmUiOiAiQWxhIGRpIFN0dXJhIiwKCQkJCSJSZWdpb25lIjogIlBpZW1vbnRlIiwKCQkJCSJQcm92aW5jaWEiOiAiVG9yaW5vIiwKCQkJCSJTaWdsYVByb3YiOiAiVE8iLAoJCQkJIkJlbGZpb3JlIjogIkExMTciCgkJCX0sCgkJCXsKCQkJCSJEZW5vbWluYXppb25lIjogIkFsYmlhbm8gZCdJdnJlYSIsCgkJCQkiUmVnaW9uZSI6ICJQaWVtb250ZSIsCgkJCQkiUHJvdmluY2lhIjogIlRvcmlubyIsCgkJCQkiU2lnbGFQcm92IjogIlRPIiwKCQkJCSJCZWxmaW9yZSI6ICJBMTU3IgoJCQl9LAoJCQl7CgkJCQkiRGVub21pbmF6aW9uZSI6ICJBbG1lc2UiLAoJCQk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PIiwKCQkJCSJCZWxmaW9yZSI6ICJBMjk1IgoJCQl9CgkJXQoJfQo=

3

3 Answers

1
votes

This would work only if you have the media-type of the registry file as text/plain. This is because when you have it as application/json it encodes the file in a different way.

1
votes

You dont really need to set it as text/plain but it's one way to get the job done. You can simply add base64Decode() to get the string out ob the base64 coded json.

In your case it would look like this

<property name="comuni" expression="base64Decode(get-property('registry', 'gov:/eos/common/json/comuni.json'))" scope="axis2" type="STRING"/>
0
votes

Ok, now it works well but the output, even if is a valid json, had a escape characters as follow :

{
"text": "{\n\t\"comuni\": [{\n\t\t\t\"Denominazione\": \"Agliè\",\n\t\t\t\"Regione\": \"Piemonte\",\n\t\t\t\"Provincia\": \"Torino\",\n\t\t\t\"SiglaProv\": \"TO\",\n\t\t\t\"Belfiore\": \"A074\"\n\t\t},\n\t\t{\n\t\t\t\"Denominazione\": \"Airasca\",\n\t\t\t\"Regione\": \"Piemonte\",\n\t\t\t\"Provincia\": \"Torino\",\n\t\t\t\"SiglaProv\": \"TO\",\n\t\t\t\"Belfiore\": \"A109\"\n\t\t},\n\t\t{\n\t\t\t\"Denominazione\": \"Ala di Stura\",\n\t\t\t\"Regione\": \"Piemonte\",\n\t\t\t\"Provincia\": \"Torino\",\n\t\t\t\"SiglaProv\": \"TO\",\n\t\t\t\"Belfiore\": \"A117\"\n\t\t},\n\t\t{\n\t\t\t\"Denominazione\": \"Albiano d'Ivrea\",\n\t\t\t\"Regione\": \"Piemonte\",\n\t\t\t\"Provincia\": \"Torino\",\n\t\t\t\"SiglaProv\": \"TO\",\n\t\t\t\"Belfiore\": \"A157\"\n\t\t},\n\t\t{\n\t\t\t\"Denominazione\": \"Almese\",\n\t\t\t\"Regione\": \"Piemonte\",\n\t\t\t\"Provincia\": \"Torino\",\n\t\t\t\"SiglaProv\": \"TO\",\n\t\t\t\"Belfiore\": \"A218\"\n\t\t},\n\t\t{\n\t\t\t\"Denominazione\": \"Alpette\",\n\t\t\t\"Regione\": \"Piemonte\",\n\t\t\t\"Provincia\": \"Torino\",\n\t\t\t\"SiglaProv\": \"TO\",\n\t\t\t\"Belfiore\": \"A221\"\n\t\t},\n\t\t{\n\t\t\t\"Denominazione\": \"Alpignano\",\n\t\t\t\"Regione\": \"Piemonte\",\n\t\t\t\"Provincia\": \"Torino\",\n\t\t\t\"SiglaProv\": \"TO\",\n\t\t\t\"Belfiore\": \"A222\"\n\t\t},\n\t\t{\n\t\t\t\"Denominazione\": \"Andezeno\",\n\t\t\t\"Regione\": \"Piemonte\",\n\t\t\t\"Provincia\": \"Torino\",\n\t\t\t\"SiglaProv\": \"TO\",\n\t\t\t\"Belfiore\": \"A275\"\n\t\t},\n\t\t{\n\t\t\t\"Denominazione\": \"Andrate\",\n\t\t\t\"Regione\": \"Piemonte\",\n\t\t\t\"Provincia\": \"Torino\",\n\t\t\t\"SiglaProv\": \"TO\",\n\t\t\t\"Belfiore\": \"A282\"\n\t\t},\n\t\t{\n\t\t\t\"Denominazione\": \"Angrogna\",\n\t\t\t\"Regione\": \"Piemonte\",\n\t\t\t\"Provincia\": \"Torino\",\n\t\t\t\"SiglaProv\": \"TO\",\n\t\t\t\"Belfiore\": \"A295\"\n\t\t}\n\t]\n}"}

How could i adjuste it?