简体   繁体   中英

Apigee; Rest > Soap (using POST), json payload parameters are not propagated

I need to use a Soap API and expose it as REST.

Something just like the Weather API discussed in this Apigee tutorial/doc http://docs.apigee.com/tutorials/proxy-soap-service

However, in my case, instead of using a rest GET, I have to use a rest POST with the parameters in a json payload.

So instead of doing this

GET http://myapi.apigee.net/weatherrest/cityweatherbyzip?ZIP=07030

I need to do this:

POST http://myapi.apigee.net/weatherrest/cityweatherbyzip

{
    "ZIP":07030
}

with apigee taking the parameter from the posted json payload and making the normal SOAP call with it.

At the moment, it doesn't seem to work, the call reaches the target but without the parameter. It returns:

{
    "GetCityWeatherByZIPResponse":{
        "GetCityWeatherByZIPResult":{
            "Success":"false",
            "ResponseText":"Invalid ZIP",
            "State":{
            },
            "City":{
            },
            "WeatherStationCity":{
            },
            "WeatherID":-1,
            "Description":{
            },
            "Temperature":{
            },
            "RelativeHumidity":{
            },
            "Wind":{
            },
            "Pressure":{
            },
            "Visibility":{
            },
            "WindChill":{
            },
            "Remarks":{
            }
        }
    }
}

What should i do to make sure parameters are taken from my json payload and propagated to the SOAP target call? Many Thanks

Actually, this is all related to those ExtractVariable block.

See this: http://docs.apigee.com/api-services/reference/extract-variables-policy

So in this case, something like this should be used:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ExtractVariables async="false" continueOnError="true" enabled="true" name="GetCityWeatherByZIP-extract-form-param">
    <DisplayName>GetCityWeatherByZIP Extract Form Param</DisplayName>
    <Source clearPayload="true|false">request</Source>
    <JSONPayload>
        <Variable name="ZIP" type="string">
            <JSONPath>$.ZIP</JSONPath>
        </Variable>
    </JSONPayload>
    <IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
</ExtractVariables>

in Api > Develop > policy (the one corresponding to the first step of your PUT)

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