Forum Discussion
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
- IheartF5_45022
Nacreous
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....
- nitass
Employee
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)?
- Sandeep_Krishna
Nimbostratus
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 } } *************************************************************************************************************** - IheartF5_45022
Nacreous
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_30338Historic 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"
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com