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.

A diagram showing the behaviour of the pattern.

The following steps describe a typical flow of data for an HTTP/JSON request issued by a mobile application:

Mobile Device to Worklight

  1. The mobile application accesses procedures by issuing Ajax requests (WL.Client.invokeProcedure).
  2. 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

  1. 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

  1. The procedure uses an HTTP command and includes the user ID and password in the HTTP basic authentication header.

Message Broker

  1. The request handler message flow in Message Broker handles the HTTP request.
  2. The request handler message flow authenticates the user ID and password against an LDAP server.
  3. 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.
  4. 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.
  5. 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.
  6. The request handler flow populates the local environment ($LocalEnvironmentVariables/Worklight/ID) with the unique identifier of the resource instance that is being accessed.
  7. 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.
  8. The subflow logic runs. This will typically involve transforming the JSON object to a request to a backend service or database.
  9. The subflow sends the response JSON message to its output terminal.
  10. If the action is a read, and caching is enabled, the request handler message flow writes the JSON object to the cache.
  11. 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

  1. The JSON response is sent back Worklight adapter as an HTTP response from Message Broker.

Worklight to Mobile Device

  1. 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