worklight中的adapter(json&xml)

json数据的adapter

使用的服务器的接口如:http://localhost:9000/webservice/getContacts?user_id=2&session_id=&contact_version=0,返回数据为:

{

status_code: 0,

result: [

{

id: 2,

real_name: "liuxinghan",

username: "keke",

email: "1266387772@qq.com",

phone: "12345686931"

}

],

msg: "",

contact_version: 1

}



写个测试的adpater名为test,则生成filtered.xsl,test.xml和test-impl.js三个文件。

在test.xml中如:

<?xml version="1.0" encoding="UTF-8"?>
<!--
    Licensed Materials - Property of IBM
    5725-G92 (C) Copyright IBM Corp. 2011, 2013. All Rights Reserved.
    US Government Users Restricted Rights - Use, duplication or
    disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
-->
<wl:adapter name="test"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:wl="http://www.worklight.com/integration"
xmlns:http="http://www.worklight.com/integration/http">


<displayName>test</displayName>
<description>test</description>
<connectivity>
<connectionPolicy xsi:type="http:HTTPConnectionPolicyType">
<protocol>http</protocol>
<domain>服务器的ip地址</domain>
<port>80</port>
<!-- Following properties used by adapter's key manager for choosing specific certificate from key store  
<sslCertificateAlias></sslCertificateAlias> 
<sslCertificatePassword></sslCertificatePassword>
-->
</connectionPolicy>
<loadConstraints maxConcurrentConnectionsPerNode="2" />
</connectivity>


<procedure name="getStories"/>


</wl:adapter>

在test-impl.js中,

/**
 * @param interest
 *            must be one of the following: world, africa, sport, technology, ...
 *            (The list can be found in http://edition.cnn.com/services/rss/)
 * @returns json list of items
 */

//参数要与接口的一致
function getStories(&&&&) {

var input = {
   method : 'get',
   returnedContentType : 'json',
   path : '/webservice/getContacts',
   parameters: {&&&&},

};


return WL.Server.invokeHttp(input);
}

这样就可以获取服务器的数据了,如:

Invocation Result of procedure: 'getStories' from the Worklight Server:



   "contact_version": 28,
   "isSuccessful": true,
   "msg": "",
   "responseHeaders": {
      "Cache-Control": "no-cache",
      "Content-Length": "2468",
      "Content-Type": "application\/json; charset=utf-8",
      "Server": "Play! Framework;1.2.4;dev",
      "Set-Cookie": [
         "PLAY_FLASH=;Expires=Thu, 23-Jan-2014 00:41:08 GMT;Path=\/",
         "PLAY_ERRORS=;Expires=Thu, 23-Jan-2014 00:41:08 GMT;Path=\/",
         "PLAY_SESSION=;Expires=Thu, 23-Jan-2014 00:41:08 GMT;Path=\/"
      ]
   },

  "responseTime": 9072,
   "result": [

{

status_code: 0,

result: [

{

id: 2,

real_name: "liuxinghan",

username: "keke",

email: "1266387772@qq.com",

phone: "12345686931"

}

],

msg: "",

contact_version: 1

}

],
   "statusCode": 200,
   "statusReason": "OK",
   "status_code": 0,
   "totalTime": 9075
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值