IBM Worklight - “无法从后端解析有效负载”

时间:2014-04-07 13:23:37

标签: ibm-mobilefirst worklight-adapters

RSS资源的任何URL都必须以" .xml"结尾在Worklight中使用时?
例如:http://www.youku.com/user/rss/id/24645394

我尝试将上述文件保存为XML文件,然后将其放在我的localhost中。有用。但是,下面的代码不起作用......我得到以下调用结果。

你对我的案子有解决方案吗?

{
   "errors": [
      "Premature end of file.",
      "Failed to parse the payload from backend (procedure: HttpRequest)"
   ],
   "info": [
   ],
   "isSuccessful": false,
   "responseHeaders": {
      "Accept-Ranges": "bytes",
      "Age": "0",
      "Cache-Control": "no-store, no-cache, must-revalidate",
      "Connection": "close",
      "Content-Length": "0",
      "Content-Type": "text\/html; charset=utf-8",
      "Date": "Mon, 07 Apr 2014 16:24:45 GMT",
      "Server": "Varnish",
      "X-Cache": "Miss from 1.w.b28"
   },
   "responseTime": 2452,
   "statusCode": 404,
   "statusReason": "Unknown virtual host",
   "totalTime": 2465,
   "warnings": [
   ]
}

News.xml

<?xml version="1.0" encoding="UTF-8"?>
<wl:adapter name="News"
    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>News</displayName>
    <description>News</description>
    <connectivity>
        <connectionPolicy xsi:type="http:HTTPConnectionPolicyType">
            <protocol>http</protocol>
            <domain>www.youku.com</domain>
            <port>80</port>         
        </connectionPolicy>
        <loadConstraints maxConcurrentConnectionsPerNode="2" />
    </connectivity>
    <procedure name="getStories" />
    <procedure name="getStoriesFiltered" />
</wl:adapter>

新闻-impl.js

    function getStories(interest) {
        path = getPath(interest);   
        var input = {
            method : 'get',
            returnedContentType : 'xml',
            path : path
        };
        return WL.Server.invokeHttp(input);
    }

    function getStoriesFiltered(interest) {
        path = getPath(interest);
        var input = {
            method : 'get',
            returnedContentType : 'xml',
            path : path,
            transformation : {
                type : 'xslFile',
                xslFile : 'filtered.xsl'
            }
        };

        return WL.Server.invokeHttp(input);
    }

    function getPath(interest) {
        if (interest == undefined || interest == '') {
            interest = '/user/rss/id/24645394/';
        }else {
            interest = '/user/rss/id/'+interest;
        }
        return interest;
    }

filtered.xsl

<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:h="http://www.w3.org/1999/xhtml">
    <xsl:output method="text"/>
    <xsl:template match="/">
        {
            'Items': [
                 <xsl:for-each select="rss/channel/item">
                    {
                        'title': '<xsl:value-of select="title"/>',
                        'link': '<xsl:value-of select="link"/>'
                    },
                </xsl:for-each>
            ]
        }
    </xsl:template>
</xsl:stylesheet>

1 个答案:

答案 0 :(得分:2)

添加主机标头:

    var input = {
        method : 'get',
        returnedContentType : 'xml',
        path : path,
        headers: {
            "Host":"www.youku.com"
        }
    };