From cef54b84ea659645b52da29ce130120caca1f5d7 Mon Sep 17 00:00:00 2001 From: kranjanusa Date: Tue, 23 Sep 2014 16:58:39 -0700 Subject: [PATCH] This is our new feature --- variables/README.md | 44 +++++++ variables/apiproxy/policies/parseforecast.xml | 23 ++++ .../apiproxy/policies/parsejsonforecast.xml | 124 ++++++++++++++++++ variables/apiproxy/policies/variables.xml | 38 ++++++ variables/apiproxy/policies/xmltojson.xml | 4 + variables/apiproxy/proxies/default.xml | 19 +++ variables/apiproxy/resources/jsc/minimize.js | 9 ++ variables/apiproxy/targets/default.xml | 5 + variables/apiproxy/variables.xml | 2 + variables/deploy.sh | 15 +++ variables/invoke.sh | 7 + 11 files changed, 290 insertions(+) create mode 100644 variables/README.md create mode 100644 variables/apiproxy/policies/parseforecast.xml create mode 100644 variables/apiproxy/policies/parsejsonforecast.xml create mode 100644 variables/apiproxy/policies/variables.xml create mode 100644 variables/apiproxy/policies/xmltojson.xml create mode 100644 variables/apiproxy/proxies/default.xml create mode 100644 variables/apiproxy/resources/jsc/minimize.js create mode 100644 variables/apiproxy/targets/default.xml create mode 100644 variables/apiproxy/variables.xml create mode 100644 variables/deploy.sh create mode 100644 variables/invoke.sh diff --git a/variables/README.md b/variables/README.md new file mode 100644 index 00000000..d91d8335 --- /dev/null +++ b/variables/README.md @@ -0,0 +1,44 @@ +# Variables + +This sample demonstrates how you can use the ExtractVariables policy to +populate variables. The sample ExtractVariables policy sets the variable values +as HTTP headers in the response. + +The sample policy demonstrates how to populate variable from the context, +API proxy configuration, request message, and m by parsing message content. + +The sample converts the XML response to from Yahoo! weather to demonstrate +how to configure the ExtractVariables policy with XPath and JSONPath +to work with message content. + +You can also refer to the API Platform variables reference: + +http://apigee.com/docs/enterprise/content/predefined-variables + +# Configure + +Update `/setup/setenv.sh` with your environment details + +# Import and deploy sample project + +To deploy, run `$ sh deploy.sh` + +To test, run `$ sh invoke.sh` + +# Get help + +For assistance, please use [StackOverflow](http://stackoverflow.com/tags/apigee) and add the tag "apigee". + +Copyright © 2014 Apigee Corporation + +Licensed under the Apache License, Version 2.0 (the "License"); you may not use +this file except in compliance with the License. You may obtain a copy +of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/variables/apiproxy/policies/parseforecast.xml b/variables/apiproxy/policies/parseforecast.xml new file mode 100644 index 00000000..1e84b841 --- /dev/null +++ b/variables/apiproxy/policies/parseforecast.xml @@ -0,0 +1,23 @@ + + + message + true + weather + + + http://xml.weather.yahoo.com/ns/rss/1.0 + + + /rss/channel/yweather:location/@city + + + /rss/channel/item/yweather:condition/@text + + + /rss/channel/item/yweather:forecast[1]/@text + + + /rss/channel/item/yweather:forecast[2]/@text + + + diff --git a/variables/apiproxy/policies/parsejsonforecast.xml b/variables/apiproxy/policies/parsejsonforecast.xml new file mode 100644 index 00000000..d912bc31 --- /dev/null +++ b/variables/apiproxy/policies/parsejsonforecast.xml @@ -0,0 +1,124 @@ + + message + true + weather + + + $.rss.channel.description + + + $.rss.atmosphere.humidity + + + + + + + \ No newline at end of file diff --git a/variables/apiproxy/policies/variables.xml b/variables/apiproxy/policies/variables.xml new file mode 100644 index 00000000..1edb0e09 --- /dev/null +++ b/variables/apiproxy/policies/variables.xml @@ -0,0 +1,38 @@ + + + true + + +
{system.timestamp}
+
{system.time}
+
{organization.name}
+
{apiproxy.name}
+
{apiproxy.revision}
+
{proxy.basepath}
+
{apiproxy.name}
+
{proxy.pathsuffix}
+
{message.headers.count}
+
{message.headers.names}
+
{client.ip}
+
{request.uri}
+
{request.headers.names}
+
{request.header.user-agent.values}
+
{request.path}
+
{request.querystring}
+
{request.queryparams.names}
+
{request.queryparam.w}
+
{request.verb}
+
{target.url}
+
{target.host}
+
{target.ip}
+ +
{weather.location}
+
{weather.condition}
+
{weather.forecast_today}
+
{weather.forecast_tomorrow}
+ +
{weather.description}
+
{weather.humidity}
+
+
+
\ No newline at end of file diff --git a/variables/apiproxy/policies/xmltojson.xml b/variables/apiproxy/policies/xmltojson.xml new file mode 100644 index 00000000..c34f3959 --- /dev/null +++ b/variables/apiproxy/policies/xmltojson.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/variables/apiproxy/proxies/default.xml b/variables/apiproxy/proxies/default.xml new file mode 100644 index 00000000..a62909fc --- /dev/null +++ b/variables/apiproxy/proxies/default.xml @@ -0,0 +1,19 @@ + + + + + parseforecast + xmltojson + parsejsonforecast + variables + + + + + /variables + default + + + default + + \ No newline at end of file diff --git a/variables/apiproxy/resources/jsc/minimize.js b/variables/apiproxy/resources/jsc/minimize.js new file mode 100644 index 00000000..415ad68d --- /dev/null +++ b/variables/apiproxy/resources/jsc/minimize.js @@ -0,0 +1,9 @@ +var orig = JSON.parse(response.content); +var channel = orig.rss.channel; +var nr = { city: channel.yweather_location.a.city, + state: channel.yweather_location.a.region, + country: channel.yweather_location.a.country, + temperature: channel.item.yweather_condition.a.temp, + conditions: channel.item.yweather_condition.a.text, + windSpeed: channel.yweather_wind.a.speed }; +response.content = JSON.stringify(nr); \ No newline at end of file diff --git a/variables/apiproxy/targets/default.xml b/variables/apiproxy/targets/default.xml new file mode 100644 index 00000000..284ef5a0 --- /dev/null +++ b/variables/apiproxy/targets/default.xml @@ -0,0 +1,5 @@ + + + http://weather.yahooapis.com + + \ No newline at end of file diff --git a/variables/apiproxy/variables.xml b/variables/apiproxy/variables.xml new file mode 100644 index 00000000..299d92e9 --- /dev/null +++ b/variables/apiproxy/variables.xml @@ -0,0 +1,2 @@ + + diff --git a/variables/deploy.sh b/variables/deploy.sh new file mode 100644 index 00000000..c596ee78 --- /dev/null +++ b/variables/deploy.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +source ../../setup/setenv.sh + +echo "Enter your password for the Apigee Enterprise organization $org, followed by [ENTER]:" + +read -s password + +echo Deploying $proxy to $env on $url using $username and $org + +../../tools/deploy.py -n variables -u $username:$password -o $org -h $url -e $env -p / -d ../variables + +echo "If 'State: deployed', then your API Proxy is ready to be invoked." + +echo "Run 'invoke.sh'" \ No newline at end of file diff --git a/variables/invoke.sh b/variables/invoke.sh new file mode 100644 index 00000000..aa7f1780 --- /dev/null +++ b/variables/invoke.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +echo Using org and environment configured in /setup/setenv.sh, $org and $env + +source ../../setup/setenv.sh + +curl http://$org-$env.$api_domain/variables/forecastrss?"w=12797282" -i