Error handling in IBM worklight adapters

Source: Internet
Author: User
Tags error handling

Brief introduction

As a mediator between mobile applications and enterprise systems, the IBM Worklight adapter provides secure access to enterprise systems, enhances data transparency, and renders enterprise data to mobile devices in a unified data format.

The Worklight provides 3 types of adapters:

HTTP adapters provide the ability to access Enterprise Services based on HTTP, including RESTful and SOAP based services.

The SQL adapter provides the ability to access the enterprise database.

The Cast Iron adapter initiates business processes in the IBM WebSphere Cast Iron.

The adapter uses JavaScript encoding to run the server side on the IBM worklight mobile application platform, which uses the Rhino JavaScript engine to execute the JavaScript source code. Figure 1 depicts a simplified view of the adapter framework in the larger Worklight platform.

Figure 1. Adapter Frame

Conceptually, an adapter is a set of JavaScript functions that can be invoked remotely by an application. From a development perspective, an adapter contains:

An XML file that configures the connection from the adapter to the enterprise system and declares the adapter procedure that can be invoked by the mobile application.

A JavaScript file that contains the implementation of the JavaScript adapter procedure (function).

These two files are placed in a. Adapter archive and then deployed to the IBM worklight Server. Once the deployment is complete, the adapter process can be invoked by Worklight applications running on the mobile device and in the browser.

Adapter error Handling

The adapter procedure is a JavaScript function that accepts any number of parameter values and returns a JavaScript object to the calling client application. For the purposes of this article, the example described here is a mobile banking application, which focuses on a sample adapter process called transfer, which calls a RESTful enterprise service to transfer money between bank accounts.

As shown in Listing 1, the transfer process accepts 3 input parameter values, using the Worklight API function WL. Server.invokehttp invokes the transfer service on the enterprise system and then returns the response information sent by the enterprise system to the caller.

WL. The Server.invokehttp function is part of the Worklight server-side API set to invoke a RESTful (HTTP) service. For database operations, SQL adapters can use WL. Server.invokesqlstatement and WL. Server.invokesqlstoredprocedure API functions.

Listing 1. Transfer Adapter Process

1//Adapter procedure to invoke the Bank ' s transfer service

2//Via HTTP

3 function Transfer (Fromaccount, Toaccount, amount) {

4

5//Build the WL. Server.invokehttp input object to invoke the

6//Transfer Service

7 var service = "Transferservice?fromaccount=" +fromaccount+

8 "&toaccount=" +toaccount+ "&amount=" +amount;

9 var input = {

Method: ' Get ',

One returnedcontenttype: ' JSON ',

Path:service

13};

14

//Invoke The Enterprise service to the transfer funds

var response = WL. Server.invokehttp (input);

17

The response received from the transfer service to

//The caller

return response;

21}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.