Forum Discussion

toto66's avatar
toto66
Icon for Nimbostratus rankNimbostratus
Apr 12, 2016

WebLogic universal persistance - multiple (JSESSIONID) cookie names

Hello experts,

we have a customer which uses a Java Web-Application hosted on WebLogic middleware. In the past this was quite simple, we used this iRule for managing the universal persistance:

when HTTP_REQUEST {
  if { [HTTP::cookie "JSESSIONID"] ne "" }{
    persist uie [string tolower [HTTP::cookie "JSESSIONID"]] 300
  } else {
    set jsess [findstr [string tolower [HTTP::path]] "jsessionid=" 11]
    if { $jsess != "" } {
      persist uie $jsess 300
    }
  }
}
when HTTP_RESPONSE {
  if { [HTTP::cookie "JSESSIONID"] ne "" }{
    persist add uie [string tolower [HTTP::cookie "JSESSIONID"]] 300
  }
}

This worked ever fine. But now the customer has multiple Java Web-Applications configured in WebLogic, each of them uses seperate Cookie names. So JSESSIONID (as before), but also new SESSIONIDA, JSESSIONIDB and JSESSIONIDC. All must be served over one Loadbalancer virtual server, we we have to manage the complexity in the iRule on the F5.

Note: We can use the same selected node node for one client, but also seperate per Cookie name, so per application to another selected node in the Backend - this is not relevant.

This is what I think it should work, but it doesn't. Please don't blame me regarding efficiency, I know it is worse. (But am no iRule expert.) Pure funcionality is Prio-1 for us.

when HTTP_REQUEST {
  if { [HTTP::cookie "JSESSIONID"] ne "" }
    { persist uie [string tolower [HTTP::cookie "JSESSIONID"]] 300 }
  elseif { [HTTP::cookie "JSESSIONIDA"] ne "" }
    { persist uie [string tolower [HTTP::cookie "JSESSIONIDA"]] 300 }
  elseif { [HTTP::cookie "JSESSIONIDB"] ne "" }
    { persist uie [string tolower [HTTP::cookie "JSESSIONIDB"]] 300 }
  elseif { [HTTP::cookie "JSESSIONIDC"] ne "" }
    { persist uie [string tolower [HTTP::cookie "JSESSIONIDC"]] 300 }
  else {
    set jsess [findstr [string tolower [HTTP::path]] "jsessionid=" 11]
    if { $jsess != "" } {persist uie $jsess 300 }
    else {
      set jsess [findstr [string tolower [HTTP::path]] "jsessionida=" 11]
      if { $jsess != "" } { persist uie $jsess 300 }
      else {
        set jsess [findstr [string tolower [HTTP::path]] "jsessionidb" 11]
        if { $jsess != "" } { persist uie $jsess 300 }
        else {
          set jsess [findstr [string tolower [HTTP::path]] "jsessionidc" 11]
          if { $jsess != "" } { persist uie $jsess 300 }
        }
      }
    } 
  }
}
when HTTP_RESPONSE {
  if { [HTTP::cookie "JSESSIONID"] ne "" }{
    persist add uie [string tolower [HTTP::cookie "JSESSIONID"]] 300
  }
  if { [HTTP::cookie "JSESSIONIDA"] ne "" }{
    persist add uie [string tolower [HTTP::cookie "JSESSIONIDA"]] 300
  }
  if { [HTTP::cookie "JSESSIONIDB"] ne "" }{
    persist add uie [string tolower [HTTP::cookie "JSESSIONIDB"]] 300
  }
  if { [HTTP::cookie "JSESSIONIDC"] ne "" }{
    persist add uie [string tolower [HTTP::cookie "JSESSIONIDC"]] 300
  }
}

I would like to thank you in advance for any hint on my problem here...

1 Reply

  • Hello dude,

    I didn't understand if you want to check if there is any order of procedence or if you are looking for a dynamic way to read cookies by name.

    Following my example, it's checking if any of the requested cookies has previous persistence considering that the request may have more than one session cookie.

    Regards.
    when HTTP_REQUEST {
        set uie_key ""
        foreach cookie [HTTP::cookie names] {
            if { $cookie starts_with "JSESSIONID" } {
                set uie_key [string tolower [HTTP::cookie value $cookie]]
                if { [persist lookup uie $uie_key] ne "" } {
                      contains persist-record
                    break
                }
            }
        }
        if { $uie_key eq "" and [string match -nocase *jsessionid* [HTTP::path]] } {
            set uie_key [getfield [findstr [string tolower [HTTP::path]] "jsessionid" 10] "=" 2]
        }
        if { $uie_key ne "" } {
            persist uie $uie_key 300
        }
        unset uie_key
    }
    
    when HTTP_RESPONSE {
        foreach cookie [HTTP::cookie names] {
            if { $cookie starts_with "JSESSIONID" } {
                persist add uie [string tolower [HTTP::cookie value $cookie]] 300
                break
            }
        }
    }