Can't get JSESSIONID in cookies while using Apigee proxy

Hello all, 

When I am calling the proxy, I don't see the JSESSIONID in cookies. Our requirement is to get the cookies with JSESSIONID.  

Can we implement Httpsession at API gateway layer ? 

Any help would be appreciated !!

0 3 386
3 REPLIES 3

There are a number of policies that can fetch cookies - ExtractVariables, AssignMessage, and Javascript are the most common. You need to read the variable -

request.header.cookie.values

As an example using the ExtractVariables policy, you could do this -

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ExtractVariables async="false" continueOnError="false" enabled="true" name="Extract-Cookies">
    <DisplayName>Extract-Cookies</DisplayName>
    <Properties/>
    <Variable name="request.header.cookie.values">
        <Pattern>{cookie_values}</Pattern>
    </Variable>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
    <Source clearPayload="false">request</Source>
</ExtractVariables>

To test this via curl, you go do the following -

curl https://$APIGEE_HOSTNAME/$BASEPATH --cookie "JSESSIONID=abc123"

Also, if you are looking to fetch cookies as they are being set, you would take a different approach. Be mindful there are likely redirects occurring when the set-cookies headers are sent, so you'll need to capture that. More detail on that can be found on this post https://www.googlecloudcommunity.com/gc/Apigee/Can-t-get-cookies-in-Apigee-or-see-them-on-Trace-help...

Thank you @apickelsimer . Here the requirement is API should generate the id which is a random value and stores the session details . If session exists, it will return the object, if it doesn't then it creates new. 

If you want to store a state or a pseudo session in Apigee, you can use the cache. If you need to generate a unique identifier then you can use a message template `createUuid()` as described at https://cloud.google.com/apigee/docs/api-platform/reference/message-template-intro#create-uuid-funct... 

For use of the cache policies for storing this, see another thread on this same topic at https://www.googlecloudcommunity.com/gc/Apigee/Stateful-Session-by-Apigee-Edge/m-p/61963