2016-02-24 33 views
0

我開始評估WSO2 ESB並嘗試實施一些簡單但實際的生活場景。使用來自WSO2的會話密鑰/令牌訪問Web服務ESB

我在做什麼,在這個特定的情況下,是連接到一個Web服務,使用有效載荷中的會話密鑰進行身份驗證。因此,有一個帶有用戶和密碼的Web服務調用來獲取密鑰,然後我需要將它放入第二個Web服務調用的有效負載中,以實際從服務中檢索數據。

出於性能原因,我不想登錄每個服務調用,但登錄一次,將密鑰存儲一段時間並執行一些請求。

我想要調用的服務是SugarCRM Web服務。

的登錄信息將是這樣的:

<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sug="http://www.sugarcrm.com/sugarcrm" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"> 
<soapenv:Header/> 
<soapenv:Body> 
    <sug:login soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> 
     <user_auth xsi:type="sug:user_auth"> 
     <user_name xsi:type="xsd:string">interface</user_name> 
     <password xsi:type="xsd:string">MD5HASHOFPASSWORD</password> 
     </user_auth> 
     <application_name xsd:string">dummy</application_name> 
     <name_value_list xsi:type="sug:name_value_list" soapenc:arrayType="sug:name_value[]"/> 
    </sug:login> 
</soapenv:Body> 

它返回是這樣的:

<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="http://www.sugarcrm.com/sugarcrm"> 
    <SOAP-ENV:Body> 
     <ns1:loginResponse xmlns:ns1="http://www.sugarcrm.com/sugarcrm"> 
      <return xsi:type="tns:entry_value"> 
       <id xsi:type="xsd:string">loggfi0i3j6eeugs7l0a0m2587</id> 
      </return> 
     </ns1:loginResponse> 
    </SOAP-ENV:Body> 
</SOAP-ENV:Envelope> 

然後,我需要用 「id」 字段作爲標記爲新的請求。

實施例,請求(即「ID」被放入「會話」字段)的所有信息:

<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sug="http://www.sugarcrm.com/sugarcrm" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"> 
    <soapenv:Header/> 
    <soapenv:Body> 
     <sug:get_entry_list soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> 
     <session xsi:type="xsd:string">loggfi0i3j6eeugs7l0a0m2587</session> 
     <module_name xsi:type="xsd:string">Leads</module_name> 
     </sug:get_entry_list> 
    </soapenv:Body> 
</soapenv:Envelope> 

此請求然後返回數據庫中的所有的信息。

同樣,這是訪問使用OAuth2的Web服務所需要的,例如MS Dynamics CRM的REST-API,只有這樣我才需要將標記/承載放在標題中。

我該如何去實現WSO2 ESB中的上述場景?我相信這是很常見的,但我沒有找到它的文檔或例子。

這裏是從CRM獲得會話ID序列:

<?xml version="1.0" encoding="UTF-8"?> 
<sequence name="sugar_login" trace="enable" xmlns="http://ws.apache.org/ns/synapse"> 
    <payloadFactory media-type="xml"> 
     <format> 
      <sug:login xmlns:sug="http://www.sugarcrm.com/sugarcrm"> 
       <sug:user_auth> 
        <user_name>interface</user_name> 
        <password>MD5HASHOFPASSWORD</password> 
        <version>1</version> 
       </sug:user_auth> 
       <application_name>dummy</application_name> 
      </sug:login> 
     </format> 
    </payloadFactory> 
    <header name="To" value="http://my.sugarcrm.com:9090/service/v4_1/soap.php"/> 
    <call> 
     <endpoint name="templEPTimeout" template="org.wso2.carbon.connector.sugarcrm.timeout"> 
      <axis2ns653:parameter name="timoutDuration" value="6000" xmlns:axis2ns653="http://ws.apache.org/ns/synapse"/> 
      <axis2ns654:parameter name="maximumDuration" value="3000" xmlns:axis2ns654="http://ws.apache.org/ns/synapse"/> 
      <axis2ns655:parameter name="progressAFactor" value="2.0" xmlns:axis2ns655="http://ws.apache.org/ns/synapse"/> 
      <axis2ns656:parameter name="initialDuration" value="2000" xmlns:axis2ns656="http://ws.apache.org/ns/synapse"/> 
     </endpoint> 
    </call> 
    <!-- Remove response custom header information --> 
    <header action="remove" name="X-SOAP-Server" scope="transport"/> 
    <header action="remove" name="Cache-control" scope="transport"/> 
    <header action="remove" name="Vary" scope="transport"/> 
    <header action="remove" name="Expires" scope="transport"/> 
    <header action="remove" name="Set-Cookie" scope="transport"/> 
    <header action="remove" name="path" scope="transport"/> 
    <property expression="//ns1:loginResponse/return/id" 
     name="sugarsessionid" scope="default" type="STRING" xmlns:ns="http://org.apache.synapse/xsd"/> 
</sequence> 

回答

0

您可以使用SugarCRM的連接器與SugarCRM的API連接。您可以在WSO2 Store找到sugarcrm連接器。在documentation中查找更多詳情。

+0

我試了一下,但沒有奏效。不記得問題是什麼,現在已經過時了。 – Chris

相關問題