IBM Support

How to use custom code to explicitly set the Cookie in RPT

Question & Answer


How can you use custom code to explicitly set the Cookie in IBM® Rational® Performance Tester (RPT)?


In RPT if a request in the script contains a "Cookie" entry in the Request Headers, the corresponding Cookie name and value will be included in the request on all subsequent playbacks. In this case, the Cookie was "created" by the client (with a Java applet for example) during recording instead of being supplied by the server.

A user should be able to modify the value of a Cookie (as opposed to a ServerSuppliedCookie) in the header just like you can modify other strings. Please find the sample custom code below to explicitly set the Cookie. Note that httpInfo.getCookieCache().setCookie() class uses the undocumented IHTTPVirtualUserInfo interface. Since RPT does not document this, it is subject to change without notice.

When creating the new Cookie, it will use the same Path and Domain (either explicitly supplied or default) as the original, server-supplied Cookie.

package test;

import java.text.ParseException;



* @author IBM Level Three Support
* Version 2 - March 16, 2005

public class SetCookieValue implements {

* Instances of this will be created using the no-arg constructor.
public SetCookieValue() {

// args[0] Set-Cookie format:<cookieName>=<cookieValue>[;path=<cookiePath>][;domain=<cookieDomain>]

public String exec(ITestExecutionServices tes, String[] args) {
IDataArea dataArea = tes.findDataArea(IDataArea.VIRTUALUSER);
IHTTPVirtualUserInfo httpInfo =
IVirtualUserInfo userInfo =

String cookieName = args[0].split("=", 2)[0];
ICookie serverSuppliedCookie[] = httpInfo.getCookieCache().getCookieByName(cookieName);
if (serverSuppliedCookie.length != 1)
if (serverSuppliedCookie.length == 0)
tes.getTestLogManager().reportMessage("Cannot find existing Cookie named " + cookieName);
tes.getTestLogManager().reportMessage("Found more than 1 cookie named " + cookieName);
return null;

String newCookieValue = "Generated_Cookie_for_" + userInfo.getUserName();
String newCookie = cookieName + "=" + newCookieValue + ";Path=" + serverSuppliedCookie[0].getPath() +
";Domain=" + serverSuppliedCookie[0].getDomain();

tes.getTestLogManager().reportMessage("Cookie from Server: " + serverSuppliedCookie[0].toString());
tes.getTestLogManager().reportMessage("New Cookie: " + newCookie);

try {
} catch (ParseException e) {
tes.getTestLogManager().reportMessage("ERROR: Can't parse Cookie string: " + newCookie);
return null;

[{"Product":{"code":"SSMMM5","label":"Rational Performance Tester"},"Business Unit":{"code":"BU053","label":"Cloud & Data Platform"},"Component":"General Information","Platform":[{"code":"PF033","label":"Windows"}],"Version":"6.1;;6.1.1;6.1.2;7.0;;;7.0.1;;;7.0.2;;8.0","Edition":"","Line of Business":{"code":"LOB36","label":"IBM Automation"}}]

Document Information

Modified date:
16 June 2018