Forum Discussion

krelm_52303's avatar
krelm_52303
Icon for Nimbostratus rankNimbostratus
Jun 29, 2007

Jsession persist with multiple cookie names

I'm trying to use the recommended method for persisting on JSESSION ID...

 

 

http://devcentral.f5.com/Default.aspx?tabid=53&view=topic&forumid=5&postid=12143

 

 

However, each of my 6 web server prefixs the Jsession cookie with it's own hostname. Therefore I have a rather ugly version of the above rule. Is there a smarter way of doing this? BTW, the rule doesn't actually work either yet!

 

 

Any advice for this newb much appreciated.

 

 

 

when CLIENT_ACCEPTED {

 

set add_persist 1

 

}

 

 

when HTTP_RESPONSE {

 

if { [HTTP::cookie exists "serverolw1-8010-PORTAL-JSESSIONID"] and $add_persist } {

 

persist add uie [HTTP::cookie "serverolw1-8010-PORTAL-JSESSIONID"]

 

set add_persist 0

 

}

 

 

if { [HTTP::cookie exists "serverolw2-8010-PORTAL-JSESSIONID"] and $add_persist } {

 

persist add uie [HTTP::cookie "serverolw2-8010-PORTAL-JSESSIONID"]

 

set add_persist 0

 

}

 

 

if { [HTTP::cookie exists "serverinw1-8030-PORTAL-JSESSIONID"] and $add_persist } {

 

persist add uie [HTTP::cookie "serverinw1-8030-PORTAL-JSESSIONID"]

 

set add_persist 0

 

}

 

 

if { [HTTP::cookie exists "serverinw2-8030-PORTAL-JSESSIONID"] and $add_persist } {

 

persist add uie [HTTP::cookie "serverinw2-8030-PORTAL-JSESSIONID"]

 

set add_persist 0

 

}

 

 

if { [HTTP::cookie exists "serverolw1-8030-PORTAL-JSESSIONID"] and $add_persist } {

 

persist add uie [HTTP::cookie "serverolw1-8030-PORTAL-JSESSIONID"]

 

set add_persist 0

 

}

 

 

if { [HTTP::cookie exists "serverolw2-8030-PORTAL-JSESSIONID"] and $add_persist } {

 

persist add uie [HTTP::cookie "serverolw2-8030-PORTAL-JSESSIONID"]

 

set add_persist 0

 

}

 

 

}

 

when HTTP_REQUEST {

 

if { [HTTP::cookie exists "serverolw1-8010-PORTAL-JSESSIONID"] } {

 

persist uie [HTTP::cookie "serverolw1-8010-PORTAL-JSESSIONID"]

 

}

 

 

if { [HTTP::cookie exists "serverolw2-8010-PORTAL-JSESSIONID"] } {

 

persist uie [HTTP::cookie "serverolw2-8010-PORTAL-JSESSIONID"]

 

}

 

 

if { [HTTP::cookie exists "serverolw1-8030-PORTAL-JSESSIONID"] } {

 

persist uie [HTTP::cookie "serverolw1-8030-PORTAL-JSESSIONID"]

 

}

 

 

if { [HTTP::cookie exists "serverolw2-8030-PORTAL-JSESSIONID"] } {

 

persist uie [HTTP::cookie "serverolw2-8030-PORTAL-JSESSIONID"]

 

}

 

 

if { [HTTP::cookie exists "serverinw1-8030-PORTAL-JSESSIONID"] } {

 

persist uie [HTTP::cookie "serverinw1-8030-PORTAL-JSESSIONID"]

 

}

 

 

if { [HTTP::cookie exists "serverinw2-8030-PORTAL-JSESSIONID"] } {

 

persist uie [HTTP::cookie "serverinw2-8030-PORTAL-JSESSIONID"]

 

}

 

}

 

 

 

 

 

 

  • Deb_Allen_18's avatar
    Deb_Allen_18
    Historic F5 Account
    Not tested, but maybe something along these lines?
    when CLIENT_ACCEPTED {
      set add_persist 1
    }
    when HTTP_RESPONSE {
       pull out cookie name by searching thru list for matching pattern
      set cname [lindex [HTTP::cookie names] [lsearch [HTTP::cookie names] "server*JSESSIONID"]]
       add persistence record if found
      if {$cname != ""}{
        persist add uie [HTTP::cookie $cname]
        set add_persist 0
      }
    }
    when HTTP_REQUEST {
       pull out cookie name by searching thru list for matching pattern
      set cname [lindex [HTTP::cookie names] [lsearch [HTTP::cookie names] "server*JSESSIONID"]]
       then persist on it if found
      if {$cname != ""}{
        persist uie [HTTP::cookie $cname]
      }
    }

    Let us know if that worked, feel free to post to the codeshare if you find it useful.

    /d
  • Deb_Allen_18's avatar
    Deb_Allen_18
    Historic F5 Account
    Edited to correct syntax/conditions (really wish we had preview...!)
  • Hi Deb,

     

     

    Thanks for the detailed reply. Sorry it's taken a while to respond.

     

     

    As per your suggestions , I have managed to convince our web server admin to remove the host prefix from all servers in the pool, so we now have the same JSESSION cookie name for all servers. :D

     

     

    I wasn't sure where to remove the flag logic - this concern still applies to the single-cookie-name irule - correct?

     

     

    So ultimately, the servers now have same cookie name, I have applied "reject on service down" for the relevent pool, and have set up a new Persistence Profile Hash, which specifies the timeout value and the simplified irule (below).

     

     

    I'll let you know how testing goes.

     

     

    Thanks again!

     

     

     

    when CLIENT_ACCEPTED {

     

    set add_persist 1

     

    }

     

    when HTTP_RESPONSE {

     

    if { [HTTP::cookie exists "JSESSIONID"] and $add_persist } {

     

    persist add uie [HTTP::cookie "JSESSIONID"]

     

    set add_persist 0

     

    }

     

    }

     

    when HTTP_REQUEST {

     

    if { [HTTP::cookie exists "JSESSIONID"] } {

     

    persist uie [HTTP::cookie "JSESSIONID"]

     

    } else {

     

    }

     

    }