Worklight Interview Questions
1. What is an IBM Worklight Adapter?
A. Adapter is a mediator between mobile applications and enterprise system. Adapters provide an easy and secure access to enterprise system. And it is efficient to provide enterprise data to mobile devices in a uniform data format. The data can be presented to mobile device using various interchange formats like XML or JSON (used mostly)
IBM Worklight provides three different types of adapters
HTTP adapter: HTTP adapters provide access to HTTP-based enterprise services, including RESTful and SOAP-based services.
SQL adapter: SQL adapters provide access to enterprise databases.
Cast IRON adapter: Cast Iron adapters initiate orchestrations in IBM Web Sphere Cast Iron.
2. How to create HTTP adapter?
A. Architecture of HTTP Adapter
Adapters are developed using JavaScript and always runs on the IBM Worklight server. When the mobile application makes request to the HTTP adapter, the HTTP adapter sends the web request to the back end web services. As a response the web service returns the response either in json or xml format, and the adapters converts the response to JSON format and sends it to the requested client application.
Now let us move to create a HTTP Adapter
- Start Eclipse, and create a new Worklight project.
- Right-click on the newly created Worklight project and then, New-> Worklight Adapter. You require giving the project name, adapter name and choosing HTTP adapter type.
- Go to the adapter’s folder and then open the newly created adapter xml file. This XML contains the configuration required to connect to the REST Web service from adapter.
- Change the connection parameters like protocol, domain name and port. See my connection parameter in this example. My xml file after changes
<wl:adapter xmlns:wl="http://www.worklight.com/integration"
xmlns:http="http://www.worklight.com/integration/http"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
name="JavatechigFeedReader">
<displayName>Javatechig.com</displayName>
<description>Javatechig FeedReader</description>
<connectivity>
<connectionPolicy xsi:type="http:HTTPConnectionPolicyType">
<protocol>http</protocol>
<domain>javatechig.com</domain>
<port>80</port>
</connectionPolicy>
<loadConstraints maxConcurrentConnectionsPerNode="2"/>
</connectivity>
<procedure name="getFeeds"/>
</wl:adapter>
function getFeeds() {
var input = {
method : 'get',
returnedContentType : 'xml',
path : "feed",
transformation : {
type : 'xslFile',
xslFile : 'filtered.xsl'
}
};
return WL.Server.invokeHttp(input);
}
I have changed domain name to “Javatechig.com”
The xml file lists the procedure declaration for the adapters. It declares all the procedures that the adapter implements. The adapter implementation resides on the JavaScript impl file.
Now let us implement the procedure.
function getFeeds() {
var input = {
method : 'get',
returnedContentType : 'xml',
path : "feed",
transformation : {
type : 'xslFile',
xslFile : 'filtered.xsl'
}
};
return WL.Server.invokeHttp(input);
}