You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
jens_0 (Bug 49975):
For tagging of load test requests in a monitoring tool I needed the possiility to add the name of the current sampler to the HTTP header. I implemented the following new function that can be used in the test's HTTP Header Manager.
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */packageorg.apache.jmeter.functions;
importjava.util.Collection;
importjava.util.LinkedList;
importjava.util.List;
importorg.apache.jmeter.engine.util.CompoundVariable;
importorg.apache.jmeter.functions.AbstractFunction;
importorg.apache.jmeter.functions.InvalidVariableException;
importorg.apache.jmeter.samplers.SampleResult;
importorg.apache.jmeter.samplers.Sampler;
/** * Function to return the name of the current sampler. */publicclassSamplerNameextendsAbstractFunction {
privatestaticfinalStringKEY = "__samplerName"; //$NON-NLS-1$privatestaticfinalList<String> desc = newLinkedList<String>();
/** {@inheritDoc} */@OverridepublicStringexecute(SampleResultpreviousResult, SamplercurrentSampler)
throwsInvalidVariableException {
// return JMeterContextService.getContext().getCurrentSampler().getName();returncurrentSampler.getName();
}
/** {@inheritDoc} */@OverridepublicvoidsetParameters(Collection<CompoundVariable> parameters)
throwsInvalidVariableException {
checkParameterCount(parameters, 0, 0);
}
/** {@inheritDoc} */@OverridepublicStringgetReferenceKey() {
returnKEY;
}
/** {@inheritDoc} */publicList<String> getArgumentDesc() {
returndesc;
}
}
OS: Windows XP
The text was updated successfully, but these errors were encountered:
Also, the code needs to check for null Sammpler object (which can happen e.g. if the function is used on the Test Plan - not that it makes sense there).
jens_0 (Bug 49975):
For tagging of load test requests in a monitoring tool I needed the possiility to add the name of the current sampler to the HTTP header. I implemented the following new function that can be used in the test's HTTP Header Manager.
Created attachment samplername.java: function sampler name
samplername.java
OS: Windows XP
The text was updated successfully, but these errors were encountered: