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);
}
这样就可以获取服务器的数据了,如:
"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
}