2014-04-07 2 views
0

Worklight에서 RSS 자원의 URL이 ".xml"로 끝나야합니까?
예 : http://www.youku.com/user/rss/id/24645394IBM Worklight - "백엔드에서 페이로드를 구문 분석하지 못했습니다."

위의 내용을 XML 파일로 저장 한 다음 내 로컬 호스트에 저장하려고했습니다. 그것은 작동합니다. 그러나 아래 코드는 작동하지 않습니다 ... 나는 다음 호출 결과를 얻습니다.

내 사건에 대한 해결책이 있으십니까?

{ 
    "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> 

답변

2

호스트 헤더 추가 :

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