1

我正在关注04_02_HTTP_adapter_-_Communicating_with_HTTP_back- end_systemsIBM Worklight Getting Started 网站上提供的培训模块,并且在调用程序时它给了我一个错误:

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

1 回答 1

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>
于 2013-08-02T12:42:41.170 回答