如何在WSO2 EI中修复<空JSON内容>

时间:2019-10-16 10:28:28

标签: json wso2

我有一个带有InSequence的Api,它应采用存储在注册表中的json文件,以及一个OutSequence,用于响应调用者。

我试图解决更改某些设置的问题,例如文字或到达资源的路径以及属性中介的类型

这是Api:

<api xmlns="http://ws.apache.org/ns/synapse" name="PhonePrefixApi" context="/phoneprefix">
   <resource methods="POST GET" url-mapping="/getprefix" inSequence="PhonePrefixApiInSequence" outSequence="PhonePrefixApiOutSequence"/>
</api>

这是InSequence:

<?xml version="1.0" encoding="UTF-8"?>
<sequence name="PhonePrefixApiInSequence" xmlns="http://ws.apache.org/ns/synapse">
    <property
        expression="get-property('registry','gov:/repository/EOS/EosCommon/phone_prefix .json')"
        name="jsonPhonePrefix" scope="registry" type="STRING" xmlns:ns="http://org.apache.synapse/xsd"/>
    <log>
        <property expression="$ctx:jsonPhonePrefix" name="JsonProp" xmlns:ns="http://org.apache.synapse/xsd"/>
    </log>
    <payloadFactory media-type="json">
        <format>$1</format>
        <args>
            <arg evaluator="json" expression="$ctx:jsonPhonePrefix" literal="true"/>
        </args>
    </payloadFactory>
    <loopback/>
</sequence>

这是OutSequence:

<?xml version="1.0" encoding="UTF-8"?>
<sequence name="PhonePrefixApiOutSequence" xmlns="http://ws.apache.org/ns/synapse">
    <send/>
</sequence>

这是我想看到的Json:

{
    "prefix": [{
            "value": "Algeria (+213)",
            "key": "213"
        },
        {
            "value": "Andorra (+376)",
            "key": "376"
        },
        {
            "value": "Angola (+244)",
            "key": "244"
        },
        {
            "value": "Anguilla (+1264)",
            "key": "1264"
        },
        {
            "value": "Antigua & Barbuda (+1268)",
            "key": "1268"
        },
        {
            "value": "Argentina (+54)",
            "key": "54"
        },
        {
            "value": "Armenia (+374)",
            "key": "374"
        },
        {
            "value": "Aruba (+297)",
            "key": "297"
        },
        {
            "value": "Australia (+61)",
            "key": "61"
        },
        {
            "value": "Austria (+43)",
            "key": "43"
        },
        {
            "value": "Azerbaijan (+994)",
            "key": "994"
        },
        {
            "value": "Bahamas (+1242)",
            "key": "1242"
        },
        {
            "value": "Bahrain (+973)",
            "key": "973"
        },
        {
            "value": "Bangladesh (+880)",
            "key": "880"
        },
        {
            "value": "Barbados (+1246)",
            "key": "1246"
        },
        {
            "value": "Belarus (+375)",
            "key": "375"
        },
        {
            "value": "Belgium (+32)",
            "key": "32"
        },
        {
            "value": "Belize (+501)",
            "key": "501"
        },
        {
            "value": "Benin (+229)",
            "key": "229"
        },
        {
            "value": "Bermuda (+1441)",
            "key": "1441"
        },
        {
            "value": "Bhutan (+975)",
            "key": "975"
        },
        {
            "value": "Bolivia (+591)",
            "key": "591"
        },
        {
            "value": "Bosnia Herzegovina (+387)",
            "key": "387"
        },
        {
            "value": "Botswana (+267)",
            "key": "267"
        },
        {
            "value": "Brazil (+55)",
            "key": "55"
        },
        {
            "value": "Brunei (+673)",
            "key": "673"
        },
        {
            "value": "Bulgaria (+359)",
            "key": "359"
        },
        {
            "value": "Burkina Faso (+226)",
            "key": "226"
        },
        {
            "value": "Burundi (+257)",
            "key": "257"
        },
        {
            "value": "Cambodia (+855)",
            "key": "855"
        },
        {
            "value": "Cameroon (+237)",
            "key": "237"
        },
        {
            "value": "Canada (+1)",
            "key": "1"
        },
        {
            "value": "Cape Verde Islands (+238)",
            "key": "238"
        },
        {
            "value": "Cayman Islands (+1345)",
            "key": "1345"
        },
        {
            "value": "Central African Republic (+236)",
            "key": "236"
        },
        {
            "value": "Chile (+56)",
            "key": "56"
        },
        {
            "value": "China (+86)",
            "key": "86"
        },
        {
            "value": "Colombia (+57)",
            "key": "57"
        },
        {
            "value": "Comoros (+269)",
            "key": "269"
        },
        {
            "value": "Congo (+242)",
            "key": "242"
        },
        {
            "value": "Cook Islands (+682)",
            "key": "682"
        },
        {
            "value": "Costa Rica (+506)",
            "key": "506"
        },
        {
            "value": "Croatia (+385)",
            "key": "385"
        },
        {
            "value": "Cuba (+53)",
            "key": "53"
        },
        {
            "value": "Cyprus North (+90392)",
            "key": "90392"
        },
        {
            "value": "Cyprus South (+357)",
            "key": "357"
        },
        {
            "value": "Czech Republic (+42)",
            "key": "42"
        },
        {
            "value": "Denmark (+45)",
            "key": "45"
        },
        {
            "value": "Djibouti (+253)",
            "key": "253"
        },
        {
            "value": "Dominica (+1809)",
            "key": "1809"
        },
        {
            "value": "Dominican Republic (+1809)",
            "key": "1809"
        },
        {
            "value": "Ecuador (+593)",
            "key": "593"
        },
        {
            "value": "Egypt (+20)",
            "key": "20"
        },
        {
            "value": "El Salvador (+503)",
            "key": "503"
        },
        {
            "value": "Equatorial Guinea (+240)",
            "key": "240"
        },
        {
            "value": "Eritrea (+291)",
            "key": "291"
        },
        {
            "value": "Estonia (+372)",
            "key": "372"
        },
        {
            "value": "Ethiopia (+251)",
            "key": "251"
        },
        {
            "value": "Falkland Islands (+500)",
            "key": "500"
        },
        {
            "value": "Faroe Islands (+298)",
            "key": "298"
        },
        {
            "value": "Fiji (+679)",
            "key": "679"
        },
        {
            "value": "Finland (+358)",
            "key": "358"
        },
        {
            "value": "France (+33)",
            "key": "33"
        },
        {
            "value": "French Guiana (+594)",
            "key": "594"
        },
        {
            "value": "French Polynesia (+689)",
            "key": "689"
        },
        {
            "value": "Gabon (+241)",
            "key": "241"
        },
        {
            "value": "Gambia (+220)",
            "key": "220"
        },
        {
            "value": "Georgia (+7880)",
            "key": "7880"
        },
        {
            "value": "Germany (+49)",
            "key": "49"
        },
        {
            "value": "Ghana (+233)",
            "key": "233"
        },
        {
            "value": "Gibraltar (+350)",
            "key": "350"
        },
        {
            "value": "Greece (+30)",
            "key": "30"
        },
        {
            "value": "Greenland (+299)",
            "key": "299"
        },
        {
            "value": "Grenada (+1473)",
            "key": "1473"
        },
        {
            "value": "Guadeloupe (+590)",
            "key": "590"
        },
        {
            "value": "Guam (+671)",
            "key": "671"
        },
        {
            "value": "Guatemala (+502)",
            "key": "502"
        },
        {
            "value": "Guinea (+224)",
            "key": "224"
        },
        {
            "value": "Guinea - Bissau (+245)",
            "key": "245"
        },
        {
            "value": "Guyana (+592)",
            "key": "592"
        },
        {
            "value": "Haiti (+509)",
            "key": "509"
        },
        {
            "value": "Honduras (+504)",
            "key": "504"
        },
        {
            "value": "Hong Kong (+852)",
            "key": "852"
        },
        {
            "value": "Hungary (+36)",
            "key": "36"
        },
        {
            "value": "Iceland (+354)",
            "key": "354"
        },
        {
            "value": "India (+91)",
            "key": "91"
        },
        {
            "value": "Indonesia (+62)",
            "key": "62"
        },
        {
            "value": "Iran (+98)",
            "key": "98"
        },
        {
            "value": "Iraq (+964)",
            "key": "964"
        },
        {
            "value": "Ireland (+353)",
            "key": "353"
        },
        {
            "value": "Israel (+972)",
            "key": "972"
        },
        {
            "value": "Italy (+39)",
            "key": "39"
        },
        {
            "value": "Jamaica (+1876)",
            "key": "1876"
        },
        {
            "value": "Japan (+81)",
            "key": "81"
        },
        {
            "value": "Jordan (+962)",
            "key": "962"
        },
        {
            "value": "Kazakhstan (+7)",
            "key": "7"
        },
        {
            "value": "Kenya (+254)",
            "key": "254"
        },
        {
            "value": "Kiribati (+686)",
            "key": "686"
        },
        {
            "value": "Korea North (+850)",
            "key": "850"
        },
        {
            "value": "Korea South (+82)",
            "key": "82"
        },
        {
            "value": "Kuwait (+965)",
            "key": "965"
        },
        {
            "value": "Kyrgyzstan (+996)",
            "key": "996"
        },
        {
            "value": "Laos (+856)",
            "key": "856"
        },
        {
            "value": "Latvia (+371)",
            "key": "371"
        },
        {
            "value": "Lebanon (+961)",
            "key": "961"
        },
        {
            "value": "Lesotho (+266)",
            "key": "266"
        },
        {
            "value": "Liberia (+231)",
            "key": "231"
        },
        {
            "value": "Libya (+218)",
            "key": "218"
        },
        {
            "value": "Liechtenstein (+417)",
            "key": "417"
        },
        {
            "value": "Lithuania (+370)",
            "key": "370"
        },
        {
            "value": "Luxembourg (+352)",
            "key": "352"
        },
        {
            "value": "Macao (+853)",
            "key": "853"
        },
        {
            "value": "Macedonia (+389)",
            "key": "389"
        },
        {
            "value": "Madagascar (+261)",
            "key": "261"
        },
        {
            "value": "Malawi (+265)",
            "key": "265"
        },
        {
            "value": "Malaysia (+60)",
            "key": "60"
        },
        {
            "value": "Maldives (+960)",
            "key": "960"
        },
        {
            "value": "Mali (+223)",
            "key": "223"
        },
        {
            "value": "Malta (+356)",
            "key": "356"
        },
        {
            "value": "Marshall Islands (+692)",
            "key": "692"
        },
        {
            "value": "Martinique (+596)",
            "key": "596"
        },
        {
            "value": "Mauritania (+222)",
            "key": "222"
        },
        {
            "value": "Mayotte (+269)",
            "key": "269"
        },
        {
            "value": "Mexico (+52)",
            "key": "52"
        },
        {
            "value": "Micronesia (+691)",
            "key": "691"
        },
        {
            "value": "Moldova (+373)",
            "key": "373"
        },
        {
            "value": "Monaco (+377)",
            "key": "377"
        },
        {
            "value": "Mozambique (+258)",
            "key": "258"
        },
        {
            "value": "Myanmar (+95)",
            "key": "95"
        },
        {
            "value": "Namibia (+264)",
            "key": "264"
        },
        {
            "value": "Nauru (+674)",
            "key": "674"
        },
        {
            "value": "Nepal (+977)",
            "key": "977"
        },
        {
            "value": "Netherlands (+31)",
            "key": "417"
        },
        {
            "value": "New Caledonia (+687)",
            "key": "687"
        },
        {
            "value": "New Zealand (+64)",
            "key": "67"
        },
        {
            "value": "Nicaragua (+505)",
            "key": "505"
        },
        {
            "value": "Niger (+227)",
            "key": "227"
        },
        {
            "value": "Nigeria (+234)",
            "key": "234"
        },
        {
            "value": "Niue (+683)",
            "key": "683"
        },
        {
            "value": "Norfolk Islands (+672)",
            "key": "672"
        },
        {
            "value": "Northern Marianas (+670)",
            "key": "670"
        },
        {
            "value": "Norway (+47)",
            "key": "47"
        },
        {
            "value": "Oman (+968)",
            "key": "968"
        },
        {
            "value": "Palau (+680)",
            "key": "680"
        },
        {
            "value": "Panama (+507)",
            "key": "507"
        },
        {
            "value": "Papua New Guinea (+675)",
            "key": "675"
        },
        {
            "value": "Paraguay (+595)",
            "key": "595"
        },
        {
            "value": "Peru (+51)",
            "key": "51"
        },
        {
            "value": "Philippines (+63)",
            "key": "63"
        },
        {
            "value": "Poland (+48)",
            "key": "48"
        },
        {
            "value": "Portugal (+351)",
            "key": "351"
        },
        {
            "value": "Puerto Rico (+1787)",
            "key": "1787"
        },
        {
            "value": "Qatar (+974)",
            "key": "974"
        },
        {
            "value": "Reunion (+262)",
            "key": "262"
        },
        {
            "value": "Romania (+40)",
            "key": "40"
        },
        {
            "value": "Russia (+7)",
            "key": "7"
        },
        {
            "value": "Rwanda (+250)",
            "key": "250"
        },
        {
            "value": "San Marino (+378)",
            "key": "378"
        },
        {
            "value": "Sao Tome &amp; Principe (+239)",
            "key": "239"
        },
        {
            "value": "Saudi Arabia (+966)",
            "key": "966"
        },
        {
            "value": "Senegal (+221)",
            "key": "221"
        },
        {
            "value": "Serbia (+381)",
            "key": "381"
        },
        {
            "value": "Seychelles (+248)",
            "key": "248"
        },
        {
            "value": "Sierra Leone (+232)",
            "key": "232"
        },
        {
            "value": "Singapore (+65)",
            "key": "65"
        },
        {
            "value": "Slovak Republic (+421)",
            "key": "421"
        },
        {
            "value": "Slovenia (+386)",
            "key": "386"
        },
        {
            "value": "Solomon Islands (+677)",
            "key": "677"
        },
        {
            "value": "Somalia (+252)",
            "key": "252"
        },
        {
            "value": "South Africa (+27)",
            "key": "27"
        },
        {
            "value": "Spain (+34)",
            "key": "34"
        },
        {
            "value": "Sri Lanka (+94)",
            "key": "94"
        },
        {
            "value": "St. Helena (+290)",
            "key": "290"
        },
        {
            "value": "St. Kitts (+1869)",
            "key": "1869"
        },
        {
            "value": "St. Lucia (+1758)",
            "key": "1758"
        },
        {
            "value": "Sudan (+249)",
            "key": "249"
        },
        {
            "value": "Suriname (+597)",
            "key": "597"
        },
        {
            "value": "Swaziland (+268)",
            "key": "268"
        },
        {
            "value": "Sweden (+46)",
            "key": "46"
        },
        {
            "value": "Switzerland (+41)",
            "key": "41"
        },
        {
            "value": "Syria (+963)",
            "key": "963"
        },
        {
            "value": "Taiwan (+886)",
            "key": "886"
        },
        {
            "value": "Tajikstan (+7)",
            "key": "7"
        },
        {
            "value": "Thailand (+66)",
            "key": "66"
        },
        {
            "value": "Togo (+228)",
            "key": "228"
        },
        {
            "value": "Tonga (+676)",
            "key": "676"
        },
        {
            "value": "Trinidad &amp; Tobago 1868)",
            "key": "1868"
        },
        {
            "value": "Tunisia (+216)",
            "key": "216"
        },
        {
            "value": "Turkey (+90)",
            "key": "90"
        },
        {
            "value": "Turkmenistan (+7)",
            "key": "7"
        },
        {
            "value": "Turkmenistan (+993)",
            "key": "993"
        },
        {
            "value": "Turks &amp; Caicos Islands (+1649)",
            "key": "1649"
        },
        {
            "value": "Tuvalu (+688)",
            "key": "688"
        },
        {
            "value": "Uganda (+256)",
            "key": "256"
        },
        {
            "value": "UK (+44)",
            "key": "44"
        },
        {
            "value": "Ukraine (+380)",
            "key": "380"
        },
        {
            "value": "United Arab Emirates (+971)",
            "key": "971"
        },
        {
            "value": "Uruguay (+598)",
            "key": "598"
        },
        {
            "value": "USA (+1)",
            "key": "1"
        },
        {
            "value": "Uzbekistan (+7)",
            "key": "7"
        },
        {
            "value": "Vanuatu (+678)",
            "key": "678"
        },
        {
            "value": "Vatican City (+379)",
            "key": "379"
        },
        {
            "value": "Venezuela (+58)",
            "key": "58"
        },
        {
            "value": "Vietnam (+84)",
            "key": "84"
        },
        {
            "value": "Virgin Islands - British (+1284)",
            "key": "1284"
        },
        {
            "value": "Virgin Islands - US (+1340)",
            "key": "1340"
        },
        {
            "value": "Wallis &amp; Futuna (+681)",
            "key": "681"
        },
        {
            "value": "Yemen (North)(+969)",
            "key": "969"
        },
        {
            "value": "Yemen (South)(+967)",
            "key": "967"
        },
        {
            "value": "Zambia (+260)",
            "key": "260"
        },
        {
            "value": "Zimbabwe (+263)",
            "key": "263"
        }
    ]
}

但是我想像这样:

空JSON内容

1 个答案:

答案 0 :(得分:0)

您可以进行一些更改以使其正常运行,

  • 从属性中介者中删除 scope =“ registry” ,从注册表中读取资源。
  • 删除有效负载工厂调解器的参数部分中的 evaluator =“ json”

示例代理如下所示。

<proxy xmlns="http://ws.apache.org/ns/synapse"
       name="abc"
       startOnLoad="true"
       statistics="disable"
       trace="disable"
       transports="http,https">
   <target>
      <inSequence>
         <property expression="get-property('registry','gov:/example.json')"
                   name="JsonProp"/>
         <log level="custom" separator="">
            <property expression="get-property('JsonProp')" name="JsonProp-------"/>
         </log>
         <payloadFactory media-type="json">
            <format>$1</format>
            <args>
               <arg evaluator="xml" expression="$ctx:JsonProp" literal="true"/>
            </args>
         </payloadFactory>
         <property name="messageType" scope="axis2" value="application/json"/>
         <respond/>
      </inSequence>
      <outSequence>
         <send/>
      </outSequence>
   </target>
   <description/>
</proxy>