Forum Discussion

Sandeep_Krishna's avatar
Sandeep_Krishna
Icon for Nimbostratus rankNimbostratus
Feb 20, 2014

F5 irule intercept and configured JSON response question

Hi - I have a question on F5 irules. I need F5 to intercept a request to a weblogic server and respond with a JSON object. I have the following irule to perform this action. However the F5 intermittently allows some requests to pass through. During analysis, we found that the requests which passthrough has a JSESSIONID in the request header. Some more research showed that the below code intercepts the response and by this time, the JSESSIONID is already created and hence future requests from teh same session is allowed by F5.

 

Can we configure F5 to say intercept the request or hijack the request (instead of performing this on the response) and respond with this JSON? If yes, could anyone please modify the irule below? I am new to F5 and it would help if someone modified the irule below. Thanks in advance.

 

when CLIENT_ACCEPTED { UNCOMMENT the line below to ENABLE JSON Maintenance page now. set rewrite_response 1 } when HTTP_REQUEST { if { ([string tolower [HTTP::uri]] starts_with "/xxx/yyyy") && $rewrite_response==1 } { set json "{ \"error\": { \"errorType\":\"maintenanceError\", \"maintenanceError\": { \"errorCode\":\"1111\", \"errorMessage\":\"

 

We're Sorry

We are down.

 

\" } }, \"status\":false }" HTTP::respond 200 content $json "Content-Type" "application/json" unset rewrite_response return } }

 

5 Replies

  • I think there's some code missing from your post as you talk about intercepting a response but there is no HTTP_REPONSE in the code posted - can you please repost and also please format a bit better (use tabs at beginning of code lines and also a blank line at top and bottom of code). It looks like the code you have posted above would work, however I don't understand where JSESSIONID comes into it....

     

  • However the F5 intermittently allows some requests to pass through.

     

    what is the request uri? does it match the one in irule (i.e. starting with /xxx/yyyy)?

     

  • The request uri is always /xxx/yyyy/SOMETHING. We get the below mentioned JSON error response on first attempt but subsequent attempts which also has the same request uri somehow bypasses this F5 irule and is served by the weblogic server. Thats the reason the JSESSIONID is attached to the response headers, I have simplified the code as well as added some formatting. Please provide your inputs. *************************************************************************************************************** when CLIENT_ACCEPTED { set rewrite_response 1 } when HTTP_REQUEST { if { ([string tolower [HTTP::uri]] starts_with "/xxx/yyyy") && $rewrite_response==1 } { set json "{"error": "true"}" HTTP::respond 200 content $json "Content-Type" "application/json" unset rewrite_response return } } ***************************************************************************************************************
  • The rewrite_response variable being unset would cause subsequent requests on the same tcp connection to pass through to the server. If that's not the behavior you are after, remove the unset statement.

     

  • Christian_30338's avatar
    Christian_30338
    Historic F5 Account

    There is a problem with your HTTP::respond as well. You need to escape the "json" variable in your example as the quotation marks are not being handled correctly. I have used this in the past and I know it works, try adapting it.

    set jsonLogout "\{\"Status\":\"OK\"\}"
    HTTP::respond 200 content $jsonLogout Content-Type "application/json; charset=utf-8"