2013-06-04 162 views
2

我很努力地向受保护的rss提要发送HTTP适配器请求以正确执行。我已经阅读了大量的IBM文档,并且追踪了死链接以移动或“维护”IBM页面。不幸的是,我没有发现任何示例显示如何授权此请求。在IBM Worklight中授权HTTP适配器

为了本示例的缘故,我试图从IBM Greenhouse Environment的Connections安装中访问rss订阅源。

适配器XML:

<?xml version="1.0" encoding="UTF-8"?> 
<wl:adapter name="exampleAdapter" 
    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>feedRead</displayName> 
    <description>feedRead</description> 
    <connectivity> 
     <connectionPolicy xsi:type="http:HTTPConnectionPolicyType"> 
      <protocol>https</protocol> 
      <domain>greenhouse.lotus.com</domain> 
      <port>443</port> 
     </connectionPolicy> 
     <loadConstraints maxConcurrentConnectionsPerNode="2" /> 
    </connectivity> 
    <procedure name="getFeed" connectAs="server"/> 
</wl:adapter> 

适配器的.js:

function getFeed() { 
    var input = { 
     method : 'get', 
     returnedContentType : 'xml', 
     path : 'connections/opensocial/basic/rest/activitystreams/@me/@all/@all? rollup=true&format=atom' 
    }; 
    return WL.Server.invokeHttp(input); 
} 

我如何可以通过访问此饲料所需的凭据?

谢谢!

回答

3

您可以指定身份验证机制为适配器XML文件的一部分。文档在这里:The Authentication element of the HTTP adapter

我不此刻有工作灯工作室的一个实例,在我的面前来检查,但我会想象有适配器XML或一些自动完成功能的设计,以帮助填补细节应该如何在<authentication>块中指定。

例子:

<?xml version="1.0" encoding="UTF-8"?> 
<wl:adapter name="exampleAdapter" 
    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>feedRead</displayName> 
    <description>feedRead</description> 
    <connectivity> 
     <connectionPolicy xsi:type="http:HTTPConnectionPolicyType"> 
      <protocol>https</protocol> 
      <domain>greenhouse.lotus.com</domain> 
      <port>443</port> 
      <authentication> 
       <basic/> 
       <serverIdentity> 
        <username> ${user} </username> 
        <password> ${password} </password> 
       </serverIdentity> 
      </authentication> 
     </connectionPolicy> 
     <loadConstraints maxConcurrentConnectionsPerNode="2" /> 
    </connectivity> 
    <procedure name="getFeed" connectAs="server"/> 
</wl:adapter> 
+0

太棒了!我以前看过这样的代码,但出于某种原因无法使用它,这次它运行得很完美。现在要弄清楚如何通过siteminder进行身份验证......有趣的部分 – Cmo

+2

@Nick我在哪里可以找到有关基本身份验证的文档? $ {user}和$ {password}变量存储在哪里? –

3

Feed如何期待凭证通过?如果使用基本身份验证,那么你可以Base64编码,您的凭据,并通过他们在适配器调用这样的标题:

function getFeed(){ 

    var input = { 
      method : 'get', 
      headers: {Authorization: "Basic YWRtaW5Ad29ya2xpZ2h0LmlibTpjaGFuZ2VJdCE="}, 
      path : "/hello",    
      returnedContentType : 'plain'  
    }; 

    return WL.Server.invokeHttp(input); 
} 
+0

我确认它的工作! –

相关问题