How to Replace Parameters in URL Request
When you capture a web application by using the Web Application Editor, it may include unique information in one or more requests that changes each time you connect to the application. This information is typically included in the response to a request and then used by one or more subsequent requests.
For example, an application might create a unique session ID when a user logs on. This session ID must be included in each request after the logon process. Without the correct session ID, each of these requests will fail. Because you will not know what this value will be until the first request is run, it can’t be explicitly included in the configuration of the request. If you create the web application by recording a browser session, then the session ID will be collected in the URL of each request. However, when the application is run, the requests will fail because the session ID will have a value that is different from the recorded one.
In order to configure such an application, you can extract a context parameter from the body of the response of one request and use the value of that parameter in one or more subsequent requests. You then replace the explicit value in subsequent requests with a variable representing the parameter. Each time the synthetic transaction is run, the parameter will be populated in the request where it is defined. When the variable is used in the subsequent requests, it is replaced with the collected value before the request is sent to the application.
A single application can use any number of context parameters. Any number of requests can use a single parameter but must be run after the request where the parameter is defined.
Parameter extraction requires System Center Operations Manager 2007 R2 Cumulative Update 3.
Session ID Example
Consider the example where an application creates a session ID when a user logs on. This session ID is required in each request after the logon page. In order to implement this scenario, you need to capture the session ID when it is first generated and then use that value in each subsequent request.
You start by using the process described in How to Capture a Web Application Recording in Operations Manager 2007 to capture the logon and subsequent actions. The recorded session for logging on to the application and performing some actions might look similar to the following:
http://www.myapp.com/home.aspx http://www.myapp.com/search.aspx?query=testing&sessionid=32793279321721 http://www.myapp.com/results.aspx?sessionid=32793279321721 http://www.myapp.com/submit.aspx?sessionid=32793279321721
In this request sequence, the session ID is created by the first request and used in the second, third, and fourth requests. When you run this monitor, it will fail because the first request will generate a new session ID that would not match the session ID used when the session was captured.
In order to configure this request sequence with parameter replacement you would create an extraction rule on the first request to create a context parameter for the session ID. The extraction rule would inspect the body of the request to locate the value for the sessionid variable. You would then modify the subsequent requests to use this parameter instead of the value for the session ID.
The modified requests would look similar to the following:
http://www.myapp.com/home.aspx http://www.myapp.com/search.aspx?query=testing&sessionid=$ParametersContext/sessionID$ http://www.myapp.com/results.aspx?sessionid=$ParametersContext/sessionID$ http://www.myapp.com/submit.aspx?sessionid=$ParametersContext/sessionID$
Creating an Extraction Rule
Context parameters are collected by an extraction rule, and each extraction rule collects a single context parameter. You create an extraction rule in the Properties dialog box of the request that initially generates the required data. In order to identify the value to extract, you must view the body of the response returned from the particular request. You can do this by viewing the source of the page returned in the browser or by using a utility that allows you to inspect the details of HTTP responses. The Web Application Editor does not provide the ability to view this text.
Once you have identified the request that contains the information you need to extract, you view the Extraction Rules tab in the properties of that request and create one or more extraction rules. The details of each extraction rule are shown in the following table.
Context parameter name
Name to give the context parameter.
Text in the body of the response that identifies the start of the parameter value. You should specify enough characters to ensure that the string is unique. The value for the parameter will start immediately after the last specified character.
Text in the body of the response that identifies the end of the parameter value. The value for the parameter will end immediately before the first specified character.
If the text in the Starts with field occurs more than once, then this value indicates which value to use. If the text only appears once or the first occurrence of it is the one to extract, then the value should be 0. If the second value should be extracted, the value should be 1, and so on.
Ignore case during search for matching text
Specifies whether the case of the characters being searched by the Starts with and Ends with boxes should be ignored.
Perform URI encoding of extracted strings
Specifies whether the extracted string should be encoded after it is collected.
Inserting a parameter into a request
You use a parameter in a request by replacing the explicit value with a variable representing the parameter. The format of the variable is $ParametersContext/<ContextParameterName>$. When the request is run, the variable is replaced with the data extracted by the parameter.
You can insert the variable into the request using either of the following methods:
Modify the Request URL on the General tab in the Request Properties dialog box for the request.
Use the Insert Parameter dialog box for the request. This is accessed from the Insert parameter button on the General tab in the Request Properties dialog box for the request.
Sample web application using parameter extraction
The following procedure provides an example of using parameter extraction in a web application. This example performs a query for the first entry in the Popular Now section of the Bing homepage. Because this value changes regularly, you need to first connect to the main page and collect the search term from the body of the response. You then use this term to build the request to perform the actual search.
The main Bing page is shown below with the Popular Now section highlighted.
In order to determine where in the response body the search term appears, you can view the source of the page. A portion of the source is shown below with the HTML of the Popular Now section. The only portion of this HTML that you need is the search string which is highlighted in the following image. The request will be formed from http://www.bing.com followed by this string.
You could just pull out the term itself, but it will be more straightforward to include the entire string in the parameter. This string is preceded by the characters <h3>Popular now</h3><ul><li><a href=" and ends with the next occurrence of ". Those are the values that you will use when you define the parameter extraction.
To record sample web application
Use the procedure in How to Capture a Web Application Recording in Operations Manager 2007 to record a web application.
While recording, connect to http://www.bing.com.
Optionally, use the option on your browser to view the source of the Bing home page and locate the Popular Now section of the HTML.
Click the first search term under Popular Now.
Save the recording to the web application.
Remove the last request since this is not required. Do this by selecting the request and clicking Delete in the Actions pane. The resulting requests should look similar to the following:
To create extraction rule
Select the first request, and then click Properties in the Actions pane.
Select the Extraction Rules tab.
If the Extraction Rules tab does not exist, then Operations Manager CU3 is not installed on the workstation.
In the Context parameter name box, type SearchString.
In the Starts with box, type <h3>Popular now</h3><ul><li><a href=".
In the Ends with box, type ". The extraction rule should look similar to the following:
Click OK to save and close the extraction rule.
Click OK to save and close the request.
To insert parameter into request
Select the second request, and then click Properties in the Actions pane.
On the General tab, click Insert parameter.
In the String box, delete all text after www.bing.com/.
With the cursor positioned at the end of the URL just after www.bing.com, select SearchString in the Parameters box, and then click Insert. This inserts the variable $ParametersContext/SearchString$. The final request will look similar to the following:
Click OK to close the dialog box.
Click OK to save and close the request. The modified request sequence should look similar to the following:
Click Apply to apply the changes and then close the Web Application Editor.