1

I use WSO2 ESB and want to connect 2 web services together - on a timer pull data from one service and push it to another.

The problem is that one of the services authenticates callers with cookies. You first need to call a GetSession method with the username and password. The response to this call sets a cookie. Then with this cookie you make other calls.

I couldn't find anywhere in the documentation, how can I get a cookie from the result of one call and set it for a subsequent call. Is it at all achievable? If so - how?

Here is my sequence code:

<sequence xmlns="http://ws.apache.org/ns/synapse" name="SampleName" trace="enable">
   <payloadFactory media-type="xml">
      <format>
         <Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
            <Body>
               <GetSessionWithCredentials xmlns="blabla">
                  <User>bla</User>
                  <Password>bla</Password>
               </GetSessionWithCredentials>
            </Body>
         </Envelope>
      </format>
   </payloadFactory>
   <call>
      <endpoint key="conf:/Tracker"></endpoint>
   </call>
   <payloadFactory media-type="xml">
      <format>
         <GetTrackingList xmlns="blabla"></GetTrackingList>
      </format>
   </payloadFactory>
   <property xmlns:ns="http://org.apache.synapse/xsd" name="Cookie" expression="$trp:Cookie"></property>
   <call>
      <endpoint key="conf:/Tracker"></endpoint>
   </call>
   <log level="full"></log>
</sequence>

Thanks a lot

Community
  • 1
  • 1
artemb
  • 9,251
  • 9
  • 48
  • 68

1 Answers1

2

get Cookie header : <property name="Cookie" expression="$trp:Cookie"/> If you want to get one cookie and it's value, use xpath expression with 'substring' for exemple

set cookie header with value JSESSIONID=1 : <property name="Cookie" value="JSESSIONID=1" scope="transport"/>

Jean-Michel
  • 5,926
  • 1
  • 13
  • 19
  • Thanks, Jean-Michel! But I couldn't get it working. I appended the sequence code to the question, can you please tell me what I am doing wrong? The second call returns an error of "No valid session". – artemb Oct 30 '14 at 17:41
  • By the way, is there a way to debug the headers in ESB? Thank you – artemb Oct 30 '14 at 17:41
  • 1
    with , you're are just defining a property named 'Cookie' and it's value is what you find in Cookie header... In ESB_HOME/bin you will find tcpmon, use it to debug http headers – Jean-Michel Oct 30 '14 at 22:02
  • It worked, but I had to user $trp.Set-Cookie instead of $trp.Cookie! – artemb Oct 31 '14 at 09:48
  • I try this with WSO2 ESB 4.8.1 and not work for me. I recieve null value with $trp.Set-Cookie – Jorge Infante Osorio Mar 30 '15 at 16:09