use of org.apache.jmeter.threads.JMeterVariables in project jmeter by apache.
the class HTTPHC4Impl method setupClientContextBeforeSample.
/**
* Configure the UserToken so that the SSL context is reused
* See <a href="https://bz.apache.org/bugzilla/show_bug.cgi?id=57804">Bug 57804</a>
* @param localContext {@link HttpContext}
*/
private void setupClientContextBeforeSample(HttpContext localContext) {
Object userToken = null;
// During recording JMeterContextService.getContext().getVariables() is null
JMeterVariables jMeterVariables = JMeterContextService.getContext().getVariables();
if (jMeterVariables != null) {
userToken = jMeterVariables.getObject(USER_TOKEN);
}
if (userToken != null) {
log.debug("Found user token:{} as JMeter variable:{}, storing it in HttpContext", userToken, USER_TOKEN);
localContext.setAttribute(HttpClientContext.USER_TOKEN, userToken);
} else {
// It would be better to create a ClientSessionManager that would compute this value
// for now it can be Thread.currentThread().getName() but must be changed when we would change
// the Thread per User model
String userId = Thread.currentThread().getName();
log.debug("Storing in HttpContext the user token: {}", userId);
localContext.setAttribute(HttpClientContext.USER_TOKEN, userId);
}
}
use of org.apache.jmeter.threads.JMeterVariables in project jmeter by apache.
the class HTTPHC4Impl method extractClientContextAfterSample.
/**
* Store in JMeter Variables the UserToken so that the SSL context is reused
* See <a href="https://bz.apache.org/bugzilla/show_bug.cgi?id=57804">Bug 57804</a>
* @param localContext {@link HttpContext}
*/
private void extractClientContextAfterSample(HttpContext localContext) {
Object userToken = localContext.getAttribute(HttpClientContext.USER_TOKEN);
if (userToken != null) {
log.debug("Extracted from HttpContext user token:{} storing it as JMeter variable:{}", userToken, USER_TOKEN);
// During recording JMeterContextService.getContext().getVariables() is null
JMeterVariables jMeterVariables = JMeterContextService.getContext().getVariables();
if (jMeterVariables != null) {
jMeterVariables.putObject(USER_TOKEN, userToken);
}
}
}
use of org.apache.jmeter.threads.JMeterVariables in project jmeter-plugins by undera.
the class Base64EncodeTest method setUpClass.
@BeforeClass
public static void setUpClass() throws Exception {
TestJMeterUtils.createJmeterEnv();
JMeterContextService.getContext().setVariables(new JMeterVariables());
}
use of org.apache.jmeter.threads.JMeterVariables in project jmeter-plugins by undera.
the class CaseFormatTest method setUp.
@Before
public void setUp() {
changeCase = new CaseFormat();
result = new SampleResult();
JMeterContext jmctx = JMeterContextService.getContext();
String data = "dummy data";
result.setResponseData(data, null);
JMeterVariables vars = new JMeterVariables();
jmctx.setVariables(vars);
jmctx.setPreviousResult(result);
params = new LinkedList<>();
}
use of org.apache.jmeter.threads.JMeterVariables in project jmeter-plugins by undera.
the class Base64Encode method execute.
@Override
public synchronized String execute(SampleResult previousResult, Sampler currentSampler) throws InvalidVariableException {
String sourceString = values[0].execute();
String decodedValue = new String(Base64.encodeBase64(sourceString.getBytes()));
if (values.length > 1) {
String variableName = values[1].execute();
if (variableName.length() > 0) {
// Allow for empty name
final JMeterVariables variables = getVariables();
if (variables != null) {
variables.put(variableName, decodedValue);
}
}
}
return decodedValue;
}
Aggregations