Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
IBM Rational Performance Tester - Custom code to modify Cookie Name
package customcode;
import java.text.ParseException;
import java.util.Iterator;
import com.ibm.rational.test.lt.execution.http.cookie.ICookie;
import com.ibm.rational.test.lt.execution.http.cookie.IHTTPVirtualUserInfo;
import com.ibm.rational.test.lt.kernel.IDataArea;
import com.ibm.rational.test.lt.kernel.services.ITestExecutionServices;
import com.ibm.rational.test.lt.kernel.services.IVirtualUserInfo;
import com.ibm.rational.test.lt.kernel.services.ITestLogManager;
/**
* @author IBM L3 Support
* Version 2 - March 22, 2016
*/
public class RenameURLCookie implements
com.ibm.rational.test.lt.kernel.custom.ICustomCode2 {
/**
* Instances of this will be created using the no-arg constructor.
*/
public RenameURLCookie() {
}
// 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 =
(IHTTPVirtualUserInfo)dataArea.get(IHTTPVirtualUserInfo.KEY);
IVirtualUserInfo userInfo =
(IVirtualUserInfo)dataArea.get(IVirtualUserInfo.KEY);
ITestLogManager tlm = tes.getTestLogManager();
//String cookieName = args[0].split("=", 2)[0];
//Dump all cookies to test log
Iterator <ICookie> cookieIterator = httpInfo.getCookieCache().getAllCookies();
while (cookieIterator.hasNext()){
ICookie currentCookie = cookieIterator.next();
String cookieName = currentCookie.getName();
String cookieDomain = currentCookie.getDomain();
String cookiePath = currentCookie.getPath();
String cookieValue = currentCookie.getValue();
tlm.reportMessage("Found a cookie. It's name is :" + cookieName);
tlm.reportMessage("Cookie domain : " + cookieDomain + " Cookie Path : " + cookiePath + " Cookie Value : " + cookieValue);
}
// This is the static cookie generated by client-side code.
// WASReqURLOidc2022219777=http://asampleapp.mybluemix.net/POEMCaseMgr/views/index.xhtml?set-locale=ca_ES
// The numeric portion is dynamic and is received from a reference which is an arg here
// Cookie Domain from a related cookie is: .mybluemix.net
// Cookie Path from a related cookie is: /
String cookieName = args[0];
String cookieValue = args[1];
String newCookie = cookieName + "=" + cookieValue + "; path=/;" + " domain=asampleapp.mybluemix.net;";
tes.getTestLogManager().reportMessage("New Cookie: " + newCookie);
try {
httpInfo.getCookieCache().setCookie(newCookie);
} catch (ParseException e) {
tes.getTestLogManager().reportMessage("ERROR: Can't parse Cookie string: " + newCookie);
}
return newCookie;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.