Enterprise Integration Zone is brought to you in partnership with:

Mark O'Neill is VP Innovation at Axway. Previously, he was CTO and co-founder at Vordel, acquired by Axway in 2012. He is the author of the McGraw-Hill book "Web Services Security" and is frequent speaker at conferences including Java One, the RSA Security Conference, and Oracle Open World. Mark is based on Boston, Massachusetts. Mark is a DZone MVB and is not an employee of DZone and has posted 63 posts at DZone. You can read more from them at their website. View Full User Profile

Orchestration of a JSON API with a SOAP Web Service w/API Server

04.05.2013
| 3796 views |
  • submit to reddit

 A frequent question about the Axway/Vordel API Server is "Is it possible to orchestrate multiple calls to different APIs or Web Services?". The answer is "Yes", and in this blog I'll show how. Along the way, we'll see how to configure JSON Path on the API Server.

For my worked example, I'm using a weather-lookup scenario. It's now Spring in Boston, and I'm interested in finding out the temperature using the API Server. Yahoo provides a great Weather API to retrieve weather information using REST and JSON. Unfortunately though, it returns the temperature in Fahrenheit and I'm more familiar with Celsius. So, I want to take the temperature from the Yahoo output, and feed this as input to the W3 Schools Fahrenheit-to-Celsius conversion Web Service. This means that I'm orchestrating to calls, one to a REST JSON API and the other to a SOAP Web Service.

Breaking down the steps, this means:

Step 1) The API Server receives a HTTP GET request containing a zip code as a parameter, like this: http://API-Server/orchestration?zip=02110

Step 2) The API Server first makes an API call for this zipcode's weather to Yahoo's Weather API, which returns the weather info as JSON

Step 3) We then extract the temperature from the Yahoo JSON response, and use this to construct a SOAP request to the W3 Schools Fahrenheit-to-Celsius conversion Web Service.

Step 4) Finally, we return the temperature info, converted to Celsius, to the client.

To achieve this, we use a circuit on the API Server, which I show in its entirety below:


Let's look at the steps in detail. Each of the blocks in the circuit is called a "filter". Let's look at what each filter does

1) Extract REST Request Attributes. This filter takes the items from the HTTP request and converts them to variables (which we call "Attributes"). When I call the API Server with a request in the browser like http://API-Server/orchestration?zip=02110 , the value "02110" is put into the attribute ${http.querystring.zip}

2) Set HTTP Verb to GET. This is a "Set HTTP Verb" filter which sets the HTTP Verb to "GET", as shown below:


I am setting the verb to GET because we need to do a GET request to Yahoo's REST Weather API.

3) Call Yahoo Weather API. This is a "Connect to URL" filter, which is configured to pass the zipcode which we've read from the querystring using the Extract REST Request Attributes filter earlier. Notice the zipcode underlined below in red:


4) Read temperature using JSON Path. After we call the Yahoo API, we have the weather response as JSON. I used the excellent online JSON Path Evaluator to construct the JSON Path to read the temperature from the Yahoo response into an Attribute called "temperature":


5) Create temperature lookup request.
The next step is to use a "Set Message" filter to take the temperature from the Yahoo JSON response (which we've just read using JSON Path) and place it into a SOAP request to the Fahrenheit-Celsius conversion Web Service, as shown below:


6) Set HTTP Verb to POST. This is another "Set HTTP Verb" filter, this time setting the verb to "POST" because we are about to POST our new SOAP request to the W3 Schools Web Service.



7) Connect to Temperature Conversion Service. This is a "Connect to URL" filter, which contains the URL we want to POST to.


8) Retrieve Celsius temp from message.
This is a "Retrieve from Message" filter which uses XPath to read the Celsius value from the SOAP response. To use the XPath Wizard, click on the little magic wand icon, and open a stored example of the SOAP response. I show the configuration for this below:


9) Return Response.
This is a "Set Message" filter, and you can see it takes the ${temperature} attribute from the XPath in Step 8, with the Zipcode we read from the Query-String in Step 1:


I wire up the circuit to a path of "/orchestration", like so:


This means that whenever a request comes in to "/orchestration", my circuit is run.

I can call circuit simply from a browser like so:


You can see it's just over 8C in Boston right now. Balmy, compared to a couple of weeks ago.

Using the Vordel Manager on port 8090 of an API Server instance, I can see each request go through, and click on "Show" buttons to see the actual messages and response.


You can see above that there are three request-response pairs:

1) From the Browser to the API Server
2) From the API Server to the Yahoo REST/JSON Weather API
3) From the API Server to the W3 Schools SOAP Web Service to convert from Fahrenheit to Celsius.

So, what we've seen here is that you can orchestrate two requests, one to a REST API and another to a SOAP Web Service, using the Axway/Vordel API Server. Note that the second request overwrites the initial response (if you want to keep a copy of the first response, use a "Store" filter and then use "Restore" to restore the message later).
Published at DZone with permission of Mark O'neill, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Tags:

Comments

Grzegorz Grzybek replied on Sun, 2013/04/07 - 11:50pm

Why not create JSON-BPEL under https://www.oasis-open.org? The history makes circles all the time..

regards
Grzegorz Grzybek

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.