【发布时间】:2014-07-10 12:27:54
【问题描述】:
我是 IBM Worklight 的新手,正在尝试“创建 HTTP 适配器”-“练习和代码示例”,但我无法获得提要,而是总是从“WL.Client.invokeProcedure”获得失败响应。
我的“FeedsAdapter.js”在这里:
var FeedsAdapter = (function(){
function getFeeds(_caller){
var caller = _caller;
var invocationData = {
adapter: "RSSReader_1",
procedure: "getFeedsFiltered",
parameters: []
};
WL.Client.invokeProcedure(invocationData, {
onSuccess: getFeedsSuccess,
onFailure: getFeedsFailure
});
function getFeedsSuccess(data){
caller.callback(data.invocationResult.Items);
}
function getFeedsFailure(){
alert("Failed to get feeds. Please check backend connectivity and restart the app");
}
}
return {
getFeeds: getFeeds
};
}());
filtered.xsl:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:h="http://www.w3.org/1999/xhtml"
xmlns:dc="http://purl.org/dc/elements/1.1/" >
<xsl:output method="text"/>
<xsl:template match="/">
{
'Items': [
<xsl:for-each select="//item">
{
'title': '<xsl:value-of select="title"/>',
'creator': '<xsl:value-of select="dc:creator"/>',
'link': '<xsl:value-of select="link"/>',
'pubDate': '<xsl:value-of select="pubDate"/>'
},
</xsl:for-each>
]
}
</xsl:template>
RSSReader_1.xml:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!--
Licensed Materials - Property of IBM
5725-G92 (C) Copyright IBM Corp. 2006, 2012. All Rights Reserved.
US Government Users Restricted Rights - Use, duplication or
disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
-->
<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="RSSReader_1">
<displayName>RSSReader_1</displayName>
<description>RSSReader_1</description>
<connectivity>
<connectionPolicy xsi:type="http:HTTPConnectionPolicyType">
<protocol>http</protocol>
<domain>engadget.com</domain>
<port>80</port>
</connectionPolicy>
<loadConstraints maxConcurrentConnectionsPerNode="2"/>
</connectivity>
<procedure name="getFeeds"/>
<procedure name="getFeedsFiltered"/>
RSSRarder_1-impl.js:
function getFeeds() {
var input = {
method : 'get',
returnedContentType : 'xml',
path : "rss.xml"
};
return WL.Server.invokeHttp(input);
}
function getFeedsFiltered() {
var input = {
method : 'get',
returnedContentType : 'xml',
path : "rss.xml",
transformation : {
type : 'xslFile',
xslFile : 'filtered.xsl'
}
};
return WL.Server.invokeHttp(input);
}
所有其他适配器文件与“HTTP 适配器”练习和代码示例中的 RSSReader 完全相同。我正在通过 Android 测试示例。
请求响应总是到达“getFeedsFailure()”。所以我需要帮助来解决问题,谢谢!
【问题讨论】:
-
您是否部署了适配器?您是否部署了应用程序?使用适配器 XML 编辑问题。使用来自 LogCat 的日志编辑问题。
-
您也可以直接在 Worklight Studio 中测试您的适配器,方法是右键单击适配器并选择 Run As -> Invoke Adapter Procedure。在这里您可以选择您的程序,然后输入您的参数并单击运行。这应该可以帮助您找出导致问题的确切原因
-
是的,我已经部署了适配器,还部署了应用程序。我刚刚用适配器 XML 编辑了我的问题。但没有 LogCat,因为我在没有 USB 连接的 Android 设备上测试应用程序
-
这可能是由于您的设备无法连接到 WL 服务器造成的吗?如果与 WL 服务器的连接不可用,则可能会调用失败回调。检查您的防火墙/IP 地址设置,以确保您可以从您的设备连接到服务器。最好检查一下您是否可以从移动浏览器访问 WL 服务器控制台。
-
嗨 MikeOrtman,我同意设备无法连接到 WL 服务器,因为我可以“调用适配器过程”从 Eclipse 获取结果。那么我该如何建立这种联系呢?
标签: android ibm-mobilefirst worklight-adapters