Set and clear cookies for a virtual user
Overview
The SetCookieFixedValue class sets a Cookie for a virtual user, and the ClearCookies class clears all cookies for a virtual user.
The SetCookieFixedValue class sets a Cookie, defined in the newCookie variable, for a virtual user just as if the server had returned a Set-Cookie.
Note that you cannot correlate values for ServerSuppliedCookie in the request header. ServerSuppliedCookie values are dynamically generated by RPT based on Set-Cookie response headers from the server. The ServerSuppliedCookie in the script is essentially a comment. Any correlations you do for these values are ignored during playback.
SetCookieFixedValue
package customcode; import com.ibm.rational.test.lt.kernel.services.ITestExecutionServices; import com.ibm.rational.test.lt.execution.http.cookie.IHTTPVirtualUserInfo; import com.ibm.rational.test.lt.kernel.IDataArea; import java.text.ParseException; /** * The SetCookieFixedValue class sets a Cookie, defined in the newCookie * variable, for a virtual user just as if the server had returned a Set-Cookie. */ /** * @author IBM Custom Code Samples */ public class SetCookieFixedValue implements com.ibm.rational.test.lt.kernel.custom.ICustomCode2 { /** * Instances of this will be created using the no-arg constructor. */ public SetCookieFixedValue() { } public String exec(ITestExecutionServices tes, String[] args) { String newCookie = "MyCookie=CookieValue;path=/;domain=.ibm.com"; IDataArea dataArea = tes.findDataArea(IDataArea.VIRTUALUSER); IHTTPVirtualUserInfo httpInfo = (IHTTPVirtualUserInfo)dataArea.get(IHTTPVirtualUserInfo.KEY); try { httpInfo.getCookieCache().setCookie(newCookie); } catch (ParseException e) { tes.getTestLogManager().reportMessage("Unable to parse Cookie " + newCookie); } return null; }}
ClearCookies
The ClearCookies class clears all Cookies for a virtual user.package customcode; import com.ibm.rational.test.lt.kernel.services.ITestExecutionServices; import com.ibm.rational.test.lt.execution.http.util.CookieCacheUtil; /** * The ClearCookies class clears all Cookies for a virtual user. */ /** * @author IBM Custom Code Samples */ public class ClearCookies implements com.ibm.rational.test.lt.kernel.custom.ICustomCode2 { /** * Instances of this will be created using the no-arg constructor. */ public ClearCookies() { } public String exec(ITestExecutionServices tes, String[] args) { CookieCacheUtil.clearCookieCache(tes); return null; }}
Error 404 - Not Found Error 404 - Not Found
The document you are looking for may have been removed or re-named. Please contact the web site owner for further assistance.