0

I'm starting to evaluate WSO2 ESB and try to implement some simple but real life scenarios.

What I'm trying to do, in this specific case is connect to a web-service that uses a session-key in the payload to do the authentication. So there is one web-service call with user and password to get the key and then I need to put this into the payload of the second web-service call to actually retrieve data from a service.

I don't want to log in with every service call, for performance reasons, but log in once, store the key for some time and do a couple of requests.

The service I want to call is a SugarCRM web-service.

The login message would be something like this:

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

Which returns something like this:

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

Then I need to use the "id" field as the token for a new request.

Example, to request all the Leads (the "id" is put into the "session" field):

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

This request then returns all the Leads in the database.

Equally this is needed for accessing web-services that use OAuth2, for example the REST-API of MS Dynamics CRM, only then I need to put the token/bearer in the header.

How would I go about realizing the above scenario in WSO2 ESB? I'm sure this is pretty common, but I have not found documentation or examples for it.

Here is the sequence to get the session-id from the CRM:

<?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>
Community
  • 1
  • 1
Chris
  • 834
  • 1
  • 10
  • 23

1 Answers1

0

You can use the sugarcrm connector to connect with SugarCRM API. You can find the sugarcrm connector at WSO2 Store. Find more details in the documentation.

Kesavan
  • 246
  • 1
  • 3
  • 7
  • I tried it then and it did not work. Can't remember exactly what the problem was, and by now it's obsolete. – Chris Oct 18 '16 at 09:35