Adding custom actions to requests

After an HTTP test is generated, you might want to add a few actions before or after a particular request is processed. For instance, for preprocessors, you can modify the headers before sending them to the server. Similarly, for postprocessors, you can extract data from the response and set it to a variable.

About this task

The actions to be processed must be coded in Java. Note that the pre processor is the last thing to be sent to the server after all the processing (data substitution) for the request is complete. Also, a postprocessor is the last thing to be received after all response processing is complete from the server.

You can add preprocessors and postprocessors at the test level and at the request level. When they are added at both the levels, the ones at the request level takes precedence.

The preprocessors and postprocessors for the HTTP extension uses the following interfaces and methods:
  • IHTTPRequestInterface: Use this interface to process an action before the request is processed.
    • setURI: Use this method to set or change the URL that is sent to the server.
    • getHeader: Use this method to get the name of the header that requires a value. If there are more than one header with the same name, only the first value is returned.
    • removeHeader: Use this method to remove the name of the header.
    • setHeader: Use this method to set the name and value for the header. If the header does not exist, it is created. If the header exists, the value is changed. If there is more than one header with the same name, only the first header is changed.
  • IHTTPResponseInterface: Use this interface to process an action after the request is processed.
    • getResponseContent: Use this method to view the content of the response. If the response content exceeds the specified limit, the content is truncated.
    • getResponseHeader: Use this method to view the name of the header. If there are more than one header with the same name in the response, only the first header is returned.
    • getReturnCode: Use this method to view the return code of the current response.
  • IHTTPRequestCommonInterface: Use this interface for both request and response interfaces.
    • getURI: Use this method to view the current URI of the request.
    • getHeaders: Use this method to view all of the headers associated with the request for pre processing or all of the headers associated with the response for post processing.

Procedure

To add a preprocessor or postprocessor:
  1. In the Test Content area of the Test editor, select a request.
  2. In the Test Details area of the Test editor, click the Advanced tab.
  3. To add a custom action before a request is processed, in Preprocessor, click Create.
  4. Specify a name for the Java file and click Finish.
    A new Java file opens. Add the custom actions to be processed before the request and save the file.
  5. To add a custom action after a request is processed, in Postprocessor, click Create and follow step 4.

What to do next

You can now run the test to verify if the actions specified in preprocessors or postprocessors returned expected results.