简体   繁体   English

WSO2 EI 从注册表中读取 json

[英]WSO2 EI read json from registry

i have this api我有这个 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:这是存储在注册表中的 json,媒体类型为 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:我想阅读 json 并在调用 api 时输出它,但响应是:

<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"原始文件是:“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 传输编码:分块连接: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更新:如果我记录从注册表中选择 json 的属性,这就是我在日志中看到的

= =

This would work only if you have the media-type of the registry file as text/plain.仅当您将注册表文件的媒体类型设置为 text/plain 时,这才有效。 This is because when you have it as application/json it encodes the file in a different way.这是因为当您将其作为 application/json 时,它会以不同的方式对文件进行编码。

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.您可以简单地添加 base64Decode() 以从 base64 编码的 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"/>

Ok, now it works well but the output, even if is a valid json, had a escape characters as follow:好的,现在它运行良好,但 output,即使是有效的 json,也有如下转义字符:

{
"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?我怎么能调整它?

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

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