This plugin allows to intercept every call made to every protocol and to modify it within your preferred environment
You write your server code, setup it on TPM and that's it
An example is in UiSeleniumTest::httpRestPluginsPlugin where the server handler is
into the handleMessage function. It simply replaces the Google logo with the Bing's one
- Create a REST api able to answer to POST request. e.g. 'http://host:91/callinterceptor'
- Deserialize the JSON of the request and parse input and proposed output (when present)
- Do your operations and eventually modify the output
- Respond with the output, error and blocking flags as needed
- The request will be in the following format
{
"inputType":"",
"outputType":"",
"phase":"",
"input":"",
"output:""
}
Where
- inputType: The simple class name of the input object, Object for any (included null). For DB calls can use
JdbcCall, for Http/sRequest - outputType: The simple class name of the output object, Object for any (included null). For DB calls can use
SelectResult, for Http/sResponse - phase: the protocol phase
And the response
- blocking: If the protocol should respond directly with the response given
- message: The JSON serialized object of the response. For DB calls can use
SelectResult, for Http/sResponse - withError: True when there is an error
- error: The error message
{
"blocking":true,
"message":"",
"error":"",
"withError":false
}
- The inputType would be Request, the output Response
- The phase will be
POST_CALL, that means the original server had been called already - Then we can deserialize the Request json (simplified)
- If it's from google (in pseudocode
input.host contains google) - Then change int the
output.responseTextall the "google.png" into "bing.png" - Re-serialize the output to JSON and send it into
messagefield
{
"input": {
"host": "www.google.com",
...
},
"outuput:{
"responseText": "<html><body><img src='google.png'/></body></html>
},
"inputType": "Request",
"outputType": "Response",
"phase":"POST_CALL"
...
}
Just set in the settings file the relative interceptor where
- name: Mnemonic for the interceptor
- phase: The phase (
POST_CALLin this case) - destinationAddress: The API to call
- inputType:
Request - outputType:
Response - inMatcher: The matcher for the input content, can be a
- regexp, prepend
@ - tpmQl, prepend
! - contains, just the string that should be founded
- regexp, prepend
If you need it exists even the outputMatcher that follows the same rules
{
"protocols":{
"http-01":{
"plugins":{
"rest-plugins-plugin": {
"interceptors": [
{
"name": "MyInterceptor",
"phase": "POST_CALL",
"destinationAddress": "http://host:91/callinterceptor",
"inputType": "Request",
"outputType": "Response",
"inMatcher": "!CONTAINS(host,'google')"
}
]
},
}
}
}