How to create a HTTP adapter in IBM Worlight
来源:互联网 发布:网络计划图绘制方法 编辑:程序博客网 时间:2024/05/29 17:44
Reference:
http://javatechig.com/cross-platform/ibm-worklight/how-to-create-a-http-adapter-in-ibm-worlight
This tutorial explains how to create a HTTP adapter in IBM Worlight and easy steps to deploy on Worklight Server. This example reads feeds from javatechig.com using HTTP Adapter.
1. What is an IBM Worklight Adapter?
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.
Adapters are coded in JavaScript and it runs at server-side on the IBM Worklight mobile application platform. IBM internally uses Rhino JavaScript engine for executing the JavaScript source code.
2. How to create HTTP adapter?
2.1 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.
In my example, I am witting an adapter to fetch feeds from javatechig.com. To fetch the feeds I have to connect to http://javatechig.com/feed/
2.2 Now let us move to create a HTTP Adapter
1. Start Eclipse, and create a new Worklight project.
3. 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.
4. 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>
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.
5. 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);}
3. Testing Adapter Procedures?
Right click on the adapter folder -> run as -> Deploy as Worklight adapter. Once deployed you can see it from the admin console. Open your browser and hit http://localhost:8080/console/
Now, RunAs-> Invoke Worklight procedure. Select the procedure to test. For now you can test for getFeeds, results will appear as JSON data.
4. How to invoke worklight Adapter Procedure?
Refer my earlier post “Invoking Adapter procedure in IBM Worklight”
5. References
http://pic.dhe.ibm.com/infocenter/wrklight
- How to create a HTTP adapter in IBM Worlight
- How to create a user in PostgreSQL
- How to: Create a Binding in Code
- How to create a function in SQL
- How to create a link in Linux
- How to: Create a C# Test Project Add-In -wisdom
- How to Create a Slick and Clean Button in Photoshop
- how to create a global singleton object in exe
- How to create SVAs in a seperate file
- How to create a simple Ad Hoc Reporting in HR ?
- How to create a Toastmasters speech in 30 minutes
- How to create a File-Compare function in Visual C#
- How to Create a Second Level GridView in ASP.NET
- How to create a Gantt chart in SharePoint
- how to create a thread in win32 platform
- How to create (and deploy) a windows service in C# ?
- How to create a Plone Blog in 5 steps
- How to create a GUID / UUID in Javascript?
- linux 命令系列之 sort 和 wc命令(58)
- IT技术创业的方向
- 文章标题
- placement new 的使用实例
- Category
- How to create a HTTP adapter in IBM Worlight
- Tiling Up Blocks (LIS)
- HDU3172 Virtual Friends
- C++ primer 读书笔记(第2章)变量和基本类型
- [联赛可能考到]图论相关算法——COGS——联赛试题预测
- 大整数乘法
- 使用GTest对项目进行单元测试
- 从无头单链表中删除节点
- Studio 自动导入包