Forum Discussion

dmpenn_184841's avatar
dmpenn_184841
Icon for Nimbostratus rankNimbostratus
Jan 29, 2015

Extract Session ID from SOAP body using iRule

Hello,

 

I am trying to find out how to extract information from the SOAP body in an HTTP request. Below is an example of the Session ID information that I'm trying to extract from the SOAP body: : : SOAP: SOAP: SOAP: SOAP: SOAP: VO00334261708 SOAP: : :

 

I was able to pull this information with an iRule when it was done via an HTTP cookie but this call is now different.

 

Your assistance will be appreciated. Thanks.

 

5 Replies

  • bonny_11145's avatar
    bonny_11145
    Historic F5 Account

    Hi dmpenn,

    You could work off getting the soap body into a variable and then working from it like so:

    ...
    set payload [HTTP::payload]
    set key ""
    set ekey ""
    set keylen [string length $key]
    
    set pos [expr {$keylen + [string first $key $payload] }  ]
    set epos [string first $ekey $payload $pos]
    set id [string range $payload $pos [expr {$epos -1]]
    

    Hope this helps

    Cheers,

    Bonny

  • Bonny,

     

    Thank you for your response. I was able to perform F5 persistence based on Session ID using the techniques that you presented. Your assistance is appreciated.

     

    dmpenn

     

    • Malcolm_Sydney1's avatar
      Malcolm_Sydney1
      Icon for Nimbostratus rankNimbostratus
      hi Could you please post and share you irule. I have a similar request I am trying to resolve
  • Hi Malcolm. I thought I replied to this earlier. Below is my solution for persistence based on SessionID:

    when HTTP_REQUEST {

    Capture sessionID from SOAP Request if exists log local0. "**** RTO Session Call ****** "

    set content_length [HTTP::header "Content-Length"]

    log local0. "Content Len: $content_length "

    Check if $content_length is not set to 0 if { $content_length > 0} { HTTP::collect $content_length

        }
    

    } when HTTP_REQUEST_DATA {

    set payload [HTTP::payload] set key ""

    set ekey ""

    set keylen [string length $key]

    set pos [expr {$keylen + [string first $key $payload] } ] set epos [string first $ekey $payload $pos] set id [string range $payload $pos [expr {$epos -1}] ]

    log local0. "SSES key: $key pos: $pos epos: $epos "

    if { $id == "" } then {

    log local0. "Parsing on " set payload [HTTP::payload] set key "" set ekey "" set keylen [string length $key]

    set pos [expr {$keylen + [string first $key $payload] } ] set epos [string first $ekey $payload $pos]

    log local0. "SES key: $key pos: $pos epos: $epos " set id [string range $payload $pos [expr {$epos -1}] ]

    } log local0. "FINAL SESSIONID: $id " Check if ID is present

    if { $id != "" } then { Persist on the ID value for X seconds log local0. "Persist on SESSIONID (id): $id " persist uie $id 600

    Check if the JSESSIONID cookie is present in the request and has a non-null value } elseif { [HTTP::cookie "JSESSIONID"] ne "" } then {

      Persist on the JSESSIONID cookie value for X seconds
      log local0. "Persist on cookie JSESSIONID  "
    
     persist uie [HTTP::cookie "JSESSIONID"] 600
    

    } else { Cookie wasn't set or didn't have a value, so check for the session ID in the URI

     set jsess [findstr [HTTP::uri] "JSESSIONID" 11 ";"]
    
     if { $jsess != "" } {
           Persist on the JSESSIONID URI value for X seconds
           log local0. "Persist on URI JSESSIONID  "
          persist uie $jsess 600
      } 
    

    } log local0. "**** END RTO Session Call ****** " }