Worklight adapters and the
Worklight: resource handler pattern
Worklight adapters are the server-side code of applications deployed on and
serviced by the Worklight Mobile Application Platform. Adapters connect
Worklight Server to enterprise applications such as those running in WebSphere
Message Broker. The adapter makes a set of services available, called procedures. The
adapter and mobile application are deployed to Worklight Server.
The following steps describe a typical flow of data for an HTTP/JSON
request issued by a mobile application:
Mobile Device to Worklight
-
The mobile application accesses procedures by issuing Ajax requests (
WL.Client.invokeProcedure
).
-
Parameters for the procedure are passed as JSON-formatted data. Parameters may
include a JSON representation of the resource that is being accessed and, if
security is enabled, a base64 string representation of the user ID and
password.
Worklight
-
The procedure adds information to the JSON object, such as the
name of the action to be performed on that object.
Worklight to Message Broker
-
The procedure uses an HTTP command and includes the user ID and password in
the HTTP basic authentication header.
Message Broker
-
The request handler message flow in Message Broker handles the HTTP request.
-
The request handler message flow authenticates the user ID and password
against an LDAP server.
-
The request handler flow removes the additional information from the JSON
object and uses that information to determine the action that is being performed on
each instance of the resource.
-
The request handler authorizes the request against an LDAP server. This
validates that the user ID is in the correct LDAP group to perform that action
on that resource.
-
If the request is to read a resource, the request handler flow uses the resource
instance identifier to check whether that instance of the resource is in the
cache.
-
The request handler flow populates the local environment (
$LocalEnvironmentVariables/Worklight/ID
)
with the unique identifier of the resource instance that is being accessed.
-
A JSON domain message is sent to the correct procedure handler subflow.
The structure of that message matches the JavaScript object passed to the
WL.Client.invokeProcedure
API by the mobile application.
-
The subflow logic runs. This will typically involve transforming the JSON
object to a request to a backend service or database.
-
The subflow sends the response JSON message to its output terminal.
-
If the action is a read, and caching is enabled, the request handler message
flow writes the JSON object to the cache.
-
If the action is update or delete, then the request handler message flow removes
that instance of the resource from the cache.
Message Broker to Worklight
-
The JSON response is sent back Worklight adapter as an HTTP response from
Message Broker.
Worklight to Mobile Device
-
The JSON response is sent back to the originating mobile application as an HTTP
response from Worklight Server.
Back to the Worklight: resource
handler pattern specification