Advanced adapter usage and mashup
improve this page | report issueOverview
Now that basic usage of different types of adapters has been covered, it is important to remember that adapters can be combined to make a procedure that uses different adapters to generate one processed result. You can combine several sources (different HTTP servers, SQL, etc).
In theory, from the client side, you could make several requests successively, one depending on the other. However, writing this logic on the server side could be faster and cleaner.
This tutorial covers the following topics:
JavaScript API
Calling a JavaScript adapter procedure from a JavaScript adapter
When calling a JavaScript adapter procedure from another JavaScript adapter use theWL.Server.invokeProcedure(invocationData)
API.This API enables to invoke a procedure on any of your adapters.
WL.Server.invokeProcedure(invocationData)
returns the result object
retrieved from the called procedure.The
invocationData
API format is:WL.Server.invokeProcedure({adapter: [Adapter Name], procedure: [Procedure Name], parameters: [Parameters seperated by a comma]})
Calling a Java adapter from a JavaScript adapter is not supported
Java API
Calling a Java adapter from a Java adapter
When calling an adapter procedure from a Java adapter use theexecuteAdapterRequest
API.
This call returns an HttpResponse
object.
Calling a JavaScript adapter procedure from a Java adapter
When calling a JavaScript adapter procedure from a Java adapter use both theexecuteAdapterRequest
API and the createJavascriptAdapterRequest
API that creates an HttpUriRequest to pass as a parameter to the executeAdapterRequest
call.
Data mashup example
The following example shows how to mash up data from 2 data sources, a database table and Yahoo! Weather Service, And to return the data stream to the application as a single object. In this example we will use 2 adapters:-
Cities Adapter:
- Extract a list of cities from a “weather” database table.
- The result contains the list of several cities around the world, their Yahoo! Weather identifier and some description.
-
Weather Adapter:
- Connect to the Yahoo! Weather Service.
- Extract an updated weather forecast for each of the cities that are retrieved via the Cities adapter.
scenario | cities Adapter | Weather Adapter |
---|---|---|
JavaScript -> JavaScript adapters | getCitiesListJS | getCityWeatherJS |
Java adapter -> JavaScript adapter | getCitiesListJavaToJS | getCityWeatherJS |
Java adapter -> Java adapter | getCitiesListJava | getCityWeatherJava |
Mashup Sample Flow
-
Create a procedure / adapter call that create a request to Yahoo! Weather Service for each city and retrieves the corresponding data:
(getCitiesListJS adapter) XML: (getCitiesListJS adapter) JavaScript: (getCityWeatherJava adapter)
-
Create an SQL query and fetch the cities records from the database:
(getCitiesListJS adapter)
(getCitiesListJava, getCitiesListJavaToJs adapters)
-
Loop through the cities records and fetch the weather info for each city from Yahoo! Weather Service:
(getCitiesListJS adapter)
(getCitiesListJava adapter)
(getCitiesListJavaToJs adapter)
-
Iterating through the retrieved rss feed to fetch only the weather description, put this values in a resultSet / JSONArray object
and return it to the application:
(getCitiesListJS adapter)
(getCitiesListJava, getCitiesListJavaToJs adapters)
An example of city list in SQL is provided with the attached sample, underserver/mobilefirstTraining.sql
. Remember that SQL adapters require a JDBC connector driver, which must be downloaded separately by the developer and added to theserver/lib
folder of the project.
Sample application
Click to download the MobileFirst project.This sample is a hybrid project and includes also the server code (adapters). ▲
Inclusive terminology note: The Mobile First Platform team is making changes to support the IBM® initiative to replace racially biased and other discriminatory language in our code and content with more inclusive language. While IBM values the use of inclusive language, terms that are outside of IBM's direct influence are sometimes required for the sake of maintaining user understanding. As other industry leaders join IBM in embracing the use of inclusive language, IBM will continue to update the documentation to reflect those changes.
Last modified on November 09, 2016