Topic
  • 6 replies
  • Latest Post - ‏2013-01-28T20:35:29Z by SystemAdmin
SystemAdmin
SystemAdmin
2327 Posts

Pinned topic Strange behaviour receiving cookies in Worklight Adapter

‏2013-01-11T10:06:52Z |
Hi,

I'm seeing strange, reproducible behaviour from the Worklight adapter in terms of receiving cookies.

The adapter only seems to be able to receive a single cookie at a time. Google by default provide two cookies; NID and PREF. Strangely, if I run against google.com with a Worklight adapter, I don't see both of these cookies appear in the response headers.

On the first run of the adapter (from WL Studio>Adapter>Invoke WL Procedure) through I see set-cookie: NID, but no PREF cookie. If I run the adapter procedure again though, I see PREF show up (and no NID) on the second run. If I run the adapter again a third time, I don't get any set-cookie response in the header at all. I presume this is because some form of internal storage is going on?! If so, how do I get ahold of these cookies that have been internalised into Worklight?

The actual situation I am trying to make work isn't against google.com, but another URI endpoint where I need to gather 5 cookies in one login request. Once I can see them, I can provide them in the headers of further requests back to this service to confirm my identity. These cookies change on each login request, so I can't work around by running 5 sequential requests to gather each one in turn.

Code for an example adapter hitting google.com that exhibits this behaviour is included below:

GOOGLE_Adapter.xml

<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed Materials - Property of IBM
5725-G92 (C) Copyright IBM Corp. 2011, 2012. All Rights Reserved.
US Government Users Restricted Rights - Use, duplication or
disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
-->
<wl:adapter name="GOOGLE_Adapter"
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>GOOGLE_Adapter</displayName>
<description>GOOGLE_Adapter</description>
<connectivity>
<connectionPolicy xsi:type="http:HTTPConnectionPolicyType">
<protocol>http</protocol>
<domain>google.com</domain>
<port>80</port>
</connectionPolicy>
<loadConstraints maxConcurrentConnectionsPerNode="2" />
</connectivity>

<procedure name="attemptGet"/>

</wl:adapter>

GOOGLE_Adapter-impl.js:

function attemptGet() {
path = "/";

var input = {
method : 'get',
returnedContentType : 'plain',
path : path
};

var results = WL.Server.invokeHttp(input) ;

return results;
}
  • SystemAdmin
    SystemAdmin
    2327 Posts

    Re: Strange behaviour receiving cookies in Worklight Adapter

    ‏2013-01-14T10:50:21Z  
    Further to this, I have tried the connectAs parameter on my login procedure. This produces further strange (session caching-like) situations with either the "endUser" or "server" options set.

    I am authenticating against a web server that uses JSessionID and 4 additional cookies to represent a particular user. These are returned to me upon a successful login. Even though I can only see one of these cookies in the returning HTTP call headers, Worklight somehow seems to save these anyway; when I issue a subsequent request to the server, it seems to have remembered my JSessionID, even if I don't specifically pass it back in.

    This would suggest to me that Worklight has cached this information even if I haven't told it to!

    Is there a way to ensure that each call to my login procedure is properly siloed so that it acts independently (and cookie free!) each time I call it?
  • SystemAdmin
    SystemAdmin
    2327 Posts

    Re: Strange behaviour receiving cookies in Worklight Adapter

    ‏2013-01-25T18:27:57Z  
    • IdanAdar
    • ‏2013-01-17T12:45:58Z
    This topic was continued off-forum, and has been resolved.
    Thanks!

    Idan Adar
    QA Engineer
    IBM Worklight Mobile Platform
    Hi,

    I'm also facing the same issue. I have a HTTPAdapter that connects to server which returns multiple cookies, but I can only see the last cookie set by server.
    I don't have control over server code, so I need to get this working on the worklight adapter side.

    Can you please elaborate what is the fix? is there a APAR to track this fix?

    Thanks,
    Rajaneesha S
  • AntonAleksandrov
    AntonAleksandrov
    55 Posts

    Re: Strange behaviour receiving cookies in Worklight Adapter

    ‏2013-01-27T08:06:13Z  
    Hi,

    I'm also facing the same issue. I have a HTTPAdapter that connects to server which returns multiple cookies, but I can only see the last cookie set by server.
    I don't have control over server code, so I need to get this working on the worklight adapter side.

    Can you please elaborate what is the fix? is there a APAR to track this fix?

    Thanks,
    Rajaneesha S
    By default WL server will use same instance of HTTPClient to connect to a backend.
    If you need to have a separate backend session for each client session you need to create security test and add wl_anonymousUserRealm as a user realm.
    Protect your adapter procedures with this security test and add connectAs="endUser" to your adapter procedure's declaration (adapter's xml file).
  • IdanAdar
    IdanAdar
    741 Posts

    Re: Strange behaviour receiving cookies in Worklight Adapter

    ‏2013-01-27T08:07:27Z  
    This topic was continued off-forum, and has been resolved.
    Thanks!

    Idan Adar
    QA Engineer
    IBM Worklight Mobile Platform
  • SystemAdmin
    SystemAdmin
    2327 Posts

    Re: Strange behaviour receiving cookies in Worklight Adapter

    ‏2013-01-28T10:11:23Z  
    By default WL server will use same instance of HTTPClient to connect to a backend.
    If you need to have a separate backend session for each client session you need to create security test and add wl_anonymousUserRealm as a user realm.
    Protect your adapter procedures with this security test and add connectAs="endUser" to your adapter procedure's declaration (adapter's xml file).
    I can confirm that what Anton suggests works. For further details on doing this, please refer to module 22 at http://www.ibm.com/developerworks/mobile/worklight/getting-started/ which details this process.
    Sean
  • SystemAdmin
    SystemAdmin
    2327 Posts

    Re: Strange behaviour receiving cookies in Worklight Adapter

    ‏2013-01-28T20:35:29Z  
    I can confirm that what Anton suggests works. For further details on doing this, please refer to module 22 at http://www.ibm.com/developerworks/mobile/worklight/getting-started/ which details this process.
    Sean
    @Sean,
    Hmm, my query was related to accessing multiple cookies from the response header as your original question.
    Not sure what Anton said helps me with that. How did you resolve your initial issue?

    ~Rajaneesha