Post-processor Action is a piece of custom logic that allows you to manipulate/override the mock response defined in the virtualization rule before it is returned to the consumer by the virtualization server. A Post Processor action,
- should belong to a Context named AQ$V12NPostProcessor
- should not include any input or output parameters
Post-processor action is powerful enough to support all commands like JSON, Fetching data from the database, message queues, and executing custom scripts, etc. Using these commands, write business logic to provide a new response or process the request/response to modify the response.
It is important to note that you should only use the commands that are mentioned in this article in a post-processor Action, as it is intended to be used in the context of virtualization response processing.
Post-processor Action has access to both the request and the mock response. Below are the details:
Get Info
The below commands are used to retrieve request and response information from the current virtualized/mocked request.
Get request info of current virtualization request
To use this command, you need to specify the type of request information you want to retrieve. There are several options available:
-
endpoint: This option retrieves the endpoint of the current request.
-
method type: This option retrieves the HTTP method (e.g. GET, POST, PUT, DELETE) of the current request.
-
payload: This option retrieves the payload (request body) of the current request.
-
header: This option retrieves the value of a specific request header. You need to specify the name of the header you want to retrieve as an additional parameter.
-
query param value: This option retrieves the value of the given parameter from the query string (a set of key-value pairs appended to the end of a URL) of the current request.
This command has three parameters:
-
request info: This parameter specifies the type of request information you want to retrieve. You can choose from the options listed above.
-
request header: This parameter is used to specify the name of a request header when you have chosen "header" as the request info. It is required if you have chosen "header" as the request info, and it should be the name of the header you want to retrieve.
- query parameter name: This parameter is used to specify the name of a query parameter when you have chosen "query param value" as the request info. It is required if you have chosen the "query param value" as the request info, and it should be the name of the query parameter you want to retrieve.
This command returns a string containing the requested request information. You can use this information to provide a customized response to the current matched virtualization service.
Get response info of current virtualization request
To use this command, you need to specify the type of response information you want to retrieve. There are several options available:
-
status code: This option retrieves the HTTP status code (e.g. 200, 404, 500) of the current response.
-
response body: This option retrieves the body (response payload) of the current response.
-
header: This option retrieves the value of a specific response header. You need to specify the name of the header you want to retrieve as an additional parameter.
This command has two parameters:
-
response info: This parameter specifies the type of response information you want to retrieve. You can choose from the options listed above.
-
response header: This parameter is used to specify the name of a response header when you have chosen "header" as the response info. It is required if you have chosen "header" as the response info, and it should be the name of the header you want to retrieve.
This command returns a string containing the requested response information. You can use this information as a base and update it as required in the post-processing of a mock response.
Modify Response
You can use the below commands to overwrite the mock response status code, response body, and headers with a new status code, response body, and headers as part of the post-processing of the mock response.
Update virtualization response body (post process)
This command is used to update the body (response payload) of the current virtualized/mocked service.
To use this command, you need to specify the new body you want to set as the response payload.
This command has one parameter:
-
new response body: This parameter specifies the new body you want to set as the response payload. It should be a string containing the new payload.
This command does not return any value. It simply updates the body of the mock response generated by the virtualization rule.
Update virtualization response status code (post process)
This command is used to update the HTTP status code of the current virtualized/mocked service.
To use this command, you need to specify the new status code you want to set as the response status code.
This command has one parameter:
-
new status code: This parameter specifies the new status code you want to set as the response status code. It should be a string containing the new status code.
This command does not return any value. It simply updates the status code of the mock response generated by the virtualization rule.
Update virtualization response headers (post process)
This command is used to modify the HTTP headers of the current virtualized/mocked service.
To use this command, you need to specify the type of modification you want to perform on the headers, as well as any additional parameters that are required depending on the type of modification.
This command has four parameters:
-
modification type: This parameter specifies the type of modification you want to perform on the headers. It should be a string containing one of the following values: "Add/Update", "Remove", or "Remove all".
-
Add/Update: This value indicates that you want to add or update a header with a new value.
-
Remove: This value indicates that you want to remove a specific header.
-
Remove all: This value indicates that you want to remove all headers.
-
-
header name: This parameter specifies the name of the header you want to modify. It is required if the "modification type" is set to "Add/Update" or "Remove". It should be a string containing the header name.
-
header value: This parameter specifies the new value you want to set for the header. It is required if the "modification type" is set to "Add/Update". It should be a string containing the new value.
-
header value type: This parameter specifies the type of the header value. It is required if the "modification type" is set to "Add/Update". Select one of the following values: "string", "number", or "JSON array/object".
This command does not return any value. It simply modifies the headers of the mock response generated.
Example:
The following Post-Processor Action updates the response by fetching data from the database for the employee with the id mentioned in the request query parameter.
How dynamic response/response update is supported?
- Provide the post-process action name which is defined in the context "AQ$V12NPostProcessor" using the command "Apply post processor to virtualization rule" when you define the virtualization rule.
- Whenever this mock request is invoked from browser/API commands, configured post-processor action will execute and provides the updated response.
- Post-processor action is powerful enough to support all commands like JSON, Fetching data from the database, message queues, executing custom scripts, etc.
- You can write business logic to provide a new response or process the request/response that the current request hold. - Once you are done with the response modification, use the below commands to make available changes to the virtualization server
- Update virtualization response body (post process)
- Update virtualization response status code (post process)
- Update virtualization response headers (post process)
Is it possible to access data from the current invoked request to modify the response?
- Post-processor action has complete access to the currently invoked request which is invoked through Accelq (browser/API commands).
- Using the "Get request info of current virtualization request/Get response info of current virtualization request" commands we can get the request or response info. Which further can be used for further processing.
-
Is Post processor chaining possible?
- Provide comma-separated post-processor action names when you define the virtualization rule. When a mock request is invoked all these defined post-processor actions will execute in the order you mention for the request.
Comments
0 comments
Please sign in to leave a comment.