IBM Worklight 6.0 - 在调用适配器过程时出错

时间:2013-08-02 09:03:09

标签: ibm-mobilefirst worklight-adapters

我正在关注IBM Worklight Getting Started网站上提供的培训模块04_02_HTTP_adapter_-_Communicating_with_HTTP_back- end_systems,并在调用过程时出现错误:

{
    "errors": [
        "Runtime: Http request failed: java.net.UnknownHostException: rss.cnn.com"
    ],
    "info": [
    ],
    "isSuccessful": false,
    "warnings": [
    ]
}

适配器-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 = '';
          }else {
    interest = '_' + interest;
         }
           return 'rss/edition' + interest + '.rss';
                   }

XML文件

        <?xml version="1.0" encoding="UTF-8"?>

   <wl:adapter name="RSSReader"
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>RSSReader</displayName>
<description>RSSReader</description>
<connectivity>
    <connectionPolicy xsi:type="http:HTTPConnectionPolicyType">
        <protocol>http</protocol>
        <domain>rss.cnn.com</domain>
        <port>80</port> 

    </connectionPolicy>
    <loadConstraints maxConcurrentConnectionsPerNode="2" />
</connectivity>

<procedure name="getStories"/>

<procedure name="getStoriesFiltered"/>

     </wl:adapter>
啊哈,最后我得到了答案。我在XML文件中做了一些代理设置,我的适配器开始工作。以下是在使用任何代理时必须添加的代理代码。

 <connectionPolicy xsi:type="http:HTTPConnectionPolicyType">
 <protocol>http</protocol>
 <domain>rss.cnn.com</domain>
 <port>80</port>
 <proxy>
 <protocol>http</protocol>
 <domain>proxy.My_company_name.com</domain>  ----use proxy URL here
 <port>8080</port>
 <authentication>
 <basic/>
 <serverIdentity>
 <username>user</username> --------user is username
 <password>password</password> ------------Proxy Password 
 </serverIdentity>
 </authentication>
 </proxy>
 </connectionPolicy>

1 个答案:

答案 0 :(得分:3)

啊哈,最后我得到了答案。我在XML文件中做了一些代理设置,我的适配器开始工作。以下是在使用任何代理时必须添加的代理代码。

 <connectionPolicy xsi:type="http:HTTPConnectionPolicyType">
 <protocol>http</protocol>
 <domain>rss.cnn.com</domain>
 <port>80</port>
 <proxy>
 <protocol>http</protocol>
 <domain>proxy.My_company_name.com</domain>  ----use proxy URL here
 <port>8080</port>
 <authentication>
 <basic/>
 <serverIdentity>
 <username>user</username> --------user is username
 <password>password</password> ------------Proxy Password 
 </serverIdentity>
 </authentication>
 </proxy>
 </connectionPolicy>