mirror of https://github.com/apache/jmeter.git
Compare commits
8 Commits
7c14f6a225
...
1c67ca07cd
| Author | SHA1 | Date |
|---|---|---|
|
|
1c67ca07cd | |
|
|
bbce13d538 | |
|
|
4ea8f7e3de | |
|
|
33e0cf467c | |
|
|
ad1638154d | |
|
|
75f5376a05 | |
|
|
45c45e7ba8 | |
|
|
06085e2866 |
|
|
@ -23,11 +23,13 @@ import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.apache.commons.collections4.iterators.FilterIterator;
|
||||||
import org.apache.jmeter.testelement.property.CollectionProperty;
|
import org.apache.jmeter.testelement.property.CollectionProperty;
|
||||||
import org.apache.jmeter.testelement.property.JMeterProperty;
|
import org.apache.jmeter.testelement.property.JMeterProperty;
|
||||||
import org.apache.jmeter.testelement.property.PropertyIterator;
|
import org.apache.jmeter.testelement.property.PropertyIterator;
|
||||||
import org.apache.jmeter.testelement.property.TestElementProperty;
|
import org.apache.jmeter.testelement.property.TestElementProperty;
|
||||||
import org.apache.jmeter.testelement.schema.PropertiesAccessor;
|
import org.apache.jmeter.testelement.schema.PropertiesAccessor;
|
||||||
|
import org.apiguardian.api.API;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A set of Argument objects.
|
* A set of Argument objects.
|
||||||
|
|
@ -100,7 +102,7 @@ public class Arguments extends ConfigTestElement implements Serializable, Iterab
|
||||||
// that this element's values prevail over defaults provided by
|
// that this element's values prevail over defaults provided by
|
||||||
// configuration
|
// configuration
|
||||||
// elements:
|
// elements:
|
||||||
if (!argMap.containsKey(arg.getName())) {
|
if (!argMap.containsKey(arg.getName()) && arg.isEnabled()) {
|
||||||
argMap.put(arg.getName(), arg.getValue());
|
argMap.put(arg.getName(), arg.getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -173,6 +175,18 @@ public class Arguments extends ConfigTestElement implements Serializable, Iterab
|
||||||
return getArguments().iterator();
|
return getArguments().iterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the list of enabled arguments.
|
||||||
|
* @return the list of enabled arguments
|
||||||
|
*/
|
||||||
|
@API(since = "5.6", status = API.Status.EXPERIMENTAL)
|
||||||
|
public Iterable<JMeterProperty> getEnabledArguments() {
|
||||||
|
return () -> new FilterIterator<>(iterator(), property -> {
|
||||||
|
Object value = property.getObjectValue();
|
||||||
|
return value instanceof Argument && ((Argument) value).isEnabled();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a string representation of the arguments.
|
* Create a string representation of the arguments.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -261,7 +261,7 @@ public class UrlConfigGui extends JPanel implements ChangeListener {
|
||||||
*/
|
*/
|
||||||
private static String computePostBody(Arguments arguments, boolean crlfToLF) {
|
private static String computePostBody(Arguments arguments, boolean crlfToLF) {
|
||||||
StringBuilder postBody = new StringBuilder();
|
StringBuilder postBody = new StringBuilder();
|
||||||
for (JMeterProperty argument : arguments) {
|
for (JMeterProperty argument : arguments.getEnabledArguments()) {
|
||||||
HTTPArgument arg = (HTTPArgument) argument.getObjectValue();
|
HTTPArgument arg = (HTTPArgument) argument.getObjectValue();
|
||||||
String value = arg.getValue();
|
String value = arg.getValue();
|
||||||
if (crlfToLF) {
|
if (crlfToLF) {
|
||||||
|
|
|
||||||
|
|
@ -39,12 +39,15 @@ import org.apache.jorphan.reflect.Functor;
|
||||||
/**
|
/**
|
||||||
* A GUI panel allowing the user to enter HTTP Parameters.
|
* A GUI panel allowing the user to enter HTTP Parameters.
|
||||||
* These have names and values, as well as check-boxes to determine whether or not to
|
* These have names and values, as well as check-boxes to determine whether or not to
|
||||||
* include the "=" sign in the output and whether or not to encode the output.
|
* include the "=" sign in the output and whether or not to encode the output and
|
||||||
|
* whether or not to enable them.
|
||||||
*/
|
*/
|
||||||
public class HTTPArgumentsPanel extends ArgumentsPanel {
|
public class HTTPArgumentsPanel extends ArgumentsPanel {
|
||||||
|
|
||||||
private static final long serialVersionUID = 240L;
|
private static final long serialVersionUID = 240L;
|
||||||
|
|
||||||
|
private static final String ENABLE = "enable"; //$NON-NLS-1$
|
||||||
|
|
||||||
private static final String ENCODE_OR_NOT = "encode?"; //$NON-NLS-1$
|
private static final String ENCODE_OR_NOT = "encode?"; //$NON-NLS-1$
|
||||||
|
|
||||||
private static final String INCLUDE_EQUALS = "include_equals"; //$NON-NLS-1$
|
private static final String INCLUDE_EQUALS = "include_equals"; //$NON-NLS-1$
|
||||||
|
|
@ -60,21 +63,23 @@ public class HTTPArgumentsPanel extends ArgumentsPanel {
|
||||||
@Override
|
@Override
|
||||||
protected void initializeTableModel() {
|
protected void initializeTableModel() {
|
||||||
tableModel = new ObjectTableModel(new String[] {
|
tableModel = new ObjectTableModel(new String[] {
|
||||||
ArgumentsPanel.COLUMN_RESOURCE_NAMES_0, ArgumentsPanel.COLUMN_RESOURCE_NAMES_1, ENCODE_OR_NOT, CONTENT_TYPE, INCLUDE_EQUALS },
|
ENABLE, ArgumentsPanel.COLUMN_RESOURCE_NAMES_0, ArgumentsPanel.COLUMN_RESOURCE_NAMES_1, ENCODE_OR_NOT, CONTENT_TYPE, INCLUDE_EQUALS },
|
||||||
HTTPArgument.class,
|
HTTPArgument.class,
|
||||||
new Functor[] {
|
new Functor[] {
|
||||||
|
new Functor("isEnabled"), //$NON-NLS-1$
|
||||||
new Functor("getName"), //$NON-NLS-1$
|
new Functor("getName"), //$NON-NLS-1$
|
||||||
new Functor("getValue"), //$NON-NLS-1$
|
new Functor("getValue"), //$NON-NLS-1$
|
||||||
new Functor("isAlwaysEncoded"), //$NON-NLS-1$
|
new Functor("isAlwaysEncoded"), //$NON-NLS-1$
|
||||||
new Functor("getContentType"), //$NON-NLS-1$
|
new Functor("getContentType"), //$NON-NLS-1$
|
||||||
new Functor("isUseEquals") }, //$NON-NLS-1$
|
new Functor("isUseEquals") }, //$NON-NLS-1$
|
||||||
new Functor[] {
|
new Functor[] {
|
||||||
|
new Functor("setEnabled"), //$NON-NLS-1$
|
||||||
new Functor("setName"), //$NON-NLS-1$
|
new Functor("setName"), //$NON-NLS-1$
|
||||||
new Functor("setValue"), //$NON-NLS-1$
|
new Functor("setValue"), //$NON-NLS-1$
|
||||||
new Functor("setAlwaysEncoded"), //$NON-NLS-1$
|
new Functor("setAlwaysEncoded"), //$NON-NLS-1$
|
||||||
new Functor("setContentType"),
|
new Functor("setContentType"),
|
||||||
new Functor("setUseEquals")}, //$NON-NLS-1$
|
new Functor("setUseEquals")}, //$NON-NLS-1$
|
||||||
new Class[] {String.class, String.class, Boolean.class, String.class, Boolean.class });
|
new Class[] {Boolean.class, String.class, String.class, Boolean.class, String.class, Boolean.class });
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean testFunctors(){
|
public static boolean testFunctors(){
|
||||||
|
|
@ -85,6 +90,7 @@ public class HTTPArgumentsPanel extends ArgumentsPanel {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void sizeColumns(JTable table) {
|
protected void sizeColumns(JTable table) {
|
||||||
|
GuiUtils.fixSize(table.getColumn(ENABLE), table);
|
||||||
GuiUtils.fixSize(table.getColumn(INCLUDE_EQUALS), table);
|
GuiUtils.fixSize(table.getColumn(INCLUDE_EQUALS), table);
|
||||||
GuiUtils.fixSize(table.getColumn(ENCODE_OR_NOT), table);
|
GuiUtils.fixSize(table.getColumn(ENCODE_OR_NOT), table);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -279,7 +279,7 @@ public class AjpSampler extends HTTPSamplerBase implements Interruptible {
|
||||||
setString(HTTPConstants.APPLICATION_X_WWW_FORM_URLENCODED);
|
setString(HTTPConstants.APPLICATION_X_WWW_FORM_URLENCODED);
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
boolean first = true;
|
boolean first = true;
|
||||||
for (JMeterProperty arg : getArguments()) {
|
for (JMeterProperty arg : getArguments().getEnabledArguments()) {
|
||||||
if (first) {
|
if (first) {
|
||||||
first = false;
|
first = false;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -159,7 +159,6 @@ import org.apache.jmeter.samplers.SampleResult;
|
||||||
import org.apache.jmeter.services.FileServer;
|
import org.apache.jmeter.services.FileServer;
|
||||||
import org.apache.jmeter.testelement.property.CollectionProperty;
|
import org.apache.jmeter.testelement.property.CollectionProperty;
|
||||||
import org.apache.jmeter.testelement.property.JMeterProperty;
|
import org.apache.jmeter.testelement.property.JMeterProperty;
|
||||||
import org.apache.jmeter.testelement.property.PropertyIterator;
|
|
||||||
import org.apache.jmeter.threads.JMeterContextService;
|
import org.apache.jmeter.threads.JMeterContextService;
|
||||||
import org.apache.jmeter.threads.JMeterVariables;
|
import org.apache.jmeter.threads.JMeterVariables;
|
||||||
import org.apache.jmeter.util.JMeterUtils;
|
import org.apache.jmeter.util.JMeterUtils;
|
||||||
|
|
@ -1571,7 +1570,7 @@ public class HTTPHC4Impl extends HTTPHCAbstractImpl {
|
||||||
}
|
}
|
||||||
// Create the parts
|
// Create the parts
|
||||||
// Add any parameters
|
// Add any parameters
|
||||||
for (JMeterProperty jMeterProperty : getArguments()) {
|
for (JMeterProperty jMeterProperty : getArguments().getEnabledArguments()) {
|
||||||
HTTPArgument arg = (HTTPArgument) jMeterProperty.getObjectValue();
|
HTTPArgument arg = (HTTPArgument) jMeterProperty.getObjectValue();
|
||||||
String parameterName = arg.getName();
|
String parameterName = arg.getName();
|
||||||
if (arg.isSkippable(parameterName)) {
|
if (arg.isSkippable(parameterName)) {
|
||||||
|
|
@ -1653,7 +1652,7 @@ public class HTTPHC4Impl extends HTTPHCAbstractImpl {
|
||||||
|
|
||||||
// Just append all the parameter values, and use that as the post body
|
// Just append all the parameter values, and use that as the post body
|
||||||
StringBuilder postBody = new StringBuilder();
|
StringBuilder postBody = new StringBuilder();
|
||||||
for (JMeterProperty jMeterProperty : getArguments()) {
|
for (JMeterProperty jMeterProperty : getArguments().getEnabledArguments()) {
|
||||||
HTTPArgument arg = (HTTPArgument) jMeterProperty.getObjectValue();
|
HTTPArgument arg = (HTTPArgument) jMeterProperty.getObjectValue();
|
||||||
postBody.append(arg.getEncodedValue(contentEncoding));
|
postBody.append(arg.getEncodedValue(contentEncoding));
|
||||||
}
|
}
|
||||||
|
|
@ -1796,10 +1795,9 @@ public class HTTPHC4Impl extends HTTPHCAbstractImpl {
|
||||||
private UrlEncodedFormEntity createUrlEncodedFormEntity(final String urlContentEncoding) throws UnsupportedEncodingException {
|
private UrlEncodedFormEntity createUrlEncodedFormEntity(final String urlContentEncoding) throws UnsupportedEncodingException {
|
||||||
// It is a normal request, with parameter names and values
|
// It is a normal request, with parameter names and values
|
||||||
// Add the parameters
|
// Add the parameters
|
||||||
PropertyIterator args = getArguments().iterator();
|
|
||||||
List<NameValuePair> nvps = new ArrayList<>();
|
List<NameValuePair> nvps = new ArrayList<>();
|
||||||
while (args.hasNext()) {
|
for (JMeterProperty jMeterProperty: getArguments().getEnabledArguments()) {
|
||||||
HTTPArgument arg = (HTTPArgument) args.next().getObjectValue();
|
HTTPArgument arg = (HTTPArgument) jMeterProperty.getObjectValue();
|
||||||
// The HTTPClient always urlencodes both name and value,
|
// The HTTPClient always urlencodes both name and value,
|
||||||
// so if the argument is already encoded, we have to decode
|
// so if the argument is already encoded, we have to decode
|
||||||
// it before adding it to the post request
|
// it before adding it to the post request
|
||||||
|
|
|
||||||
|
|
@ -81,7 +81,6 @@ import org.apache.jmeter.testelement.TestStateListener;
|
||||||
import org.apache.jmeter.testelement.ThreadListener;
|
import org.apache.jmeter.testelement.ThreadListener;
|
||||||
import org.apache.jmeter.testelement.property.CollectionProperty;
|
import org.apache.jmeter.testelement.property.CollectionProperty;
|
||||||
import org.apache.jmeter.testelement.property.JMeterProperty;
|
import org.apache.jmeter.testelement.property.JMeterProperty;
|
||||||
import org.apache.jmeter.testelement.property.PropertyIterator;
|
|
||||||
import org.apache.jmeter.testelement.schema.PropertiesAccessor;
|
import org.apache.jmeter.testelement.schema.PropertiesAccessor;
|
||||||
import org.apache.jmeter.testelement.schema.PropertyDescriptor;
|
import org.apache.jmeter.testelement.schema.PropertyDescriptor;
|
||||||
import org.apache.jmeter.threads.JMeterContext;
|
import org.apache.jmeter.threads.JMeterContext;
|
||||||
|
|
@ -409,7 +408,7 @@ public abstract class HTTPSamplerBase extends AbstractSampler
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
boolean hasArguments = false;
|
boolean hasArguments = false;
|
||||||
for (JMeterProperty jMeterProperty : getArguments()) {
|
for (JMeterProperty jMeterProperty : getArguments().getEnabledArguments()) {
|
||||||
hasArguments = true;
|
hasArguments = true;
|
||||||
HTTPArgument arg = (HTTPArgument) jMeterProperty.getObjectValue();
|
HTTPArgument arg = (HTTPArgument) jMeterProperty.getObjectValue();
|
||||||
if (arg.getName() != null && !arg.getName().isEmpty()) {
|
if (arg.getName() != null && !arg.getName().isEmpty()) {
|
||||||
|
|
@ -1155,9 +1154,10 @@ public abstract class HTTPSamplerBase extends AbstractSampler
|
||||||
*/
|
*/
|
||||||
public String getQueryString(final String contentEncoding) {
|
public String getQueryString(final String contentEncoding) {
|
||||||
|
|
||||||
CollectionProperty arguments = getArguments().getArguments();
|
Arguments args = getArguments();
|
||||||
|
Iterator<JMeterProperty> iter = args.getEnabledArguments().iterator();
|
||||||
// Optimisation : avoid building useless objects if empty arguments
|
// Optimisation : avoid building useless objects if empty arguments
|
||||||
if(arguments.isEmpty()) {
|
if (!iter.hasNext()) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
String lContentEncoding = contentEncoding;
|
String lContentEncoding = contentEncoding;
|
||||||
|
|
@ -1167,8 +1167,7 @@ public abstract class HTTPSamplerBase extends AbstractSampler
|
||||||
lContentEncoding = EncoderCache.URL_ARGUMENT_ENCODING;
|
lContentEncoding = EncoderCache.URL_ARGUMENT_ENCODING;
|
||||||
}
|
}
|
||||||
|
|
||||||
StringBuilder buf = new StringBuilder(arguments.size() * 15);
|
StringBuilder buf = new StringBuilder(args.getArgumentCount() * 15);
|
||||||
PropertyIterator iter = arguments.iterator();
|
|
||||||
boolean first = true;
|
boolean first = true;
|
||||||
while (iter.hasNext()) {
|
while (iter.hasNext()) {
|
||||||
HTTPArgument item = null;
|
HTTPArgument item = null;
|
||||||
|
|
|
||||||
|
|
@ -190,7 +190,7 @@ public class PostWriter {
|
||||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||||
OutputStreamWriter osw = new OutputStreamWriter(bos, contentEncoding);
|
OutputStreamWriter osw = new OutputStreamWriter(bos, contentEncoding);
|
||||||
// Add any parameters
|
// Add any parameters
|
||||||
for (JMeterProperty jMeterProperty : sampler.getArguments()) {
|
for (JMeterProperty jMeterProperty : sampler.getArguments().getEnabledArguments()) {
|
||||||
HTTPArgument arg = (HTTPArgument) jMeterProperty.getObjectValue();
|
HTTPArgument arg = (HTTPArgument) jMeterProperty.getObjectValue();
|
||||||
String parameterName = arg.getName();
|
String parameterName = arg.getName();
|
||||||
if (arg.isSkippable(parameterName)) {
|
if (arg.isSkippable(parameterName)) {
|
||||||
|
|
@ -299,7 +299,7 @@ public class PostWriter {
|
||||||
|
|
||||||
// Just append all the parameter values, and use that as the post body
|
// Just append all the parameter values, and use that as the post body
|
||||||
StringBuilder postBodyBuffer = new StringBuilder();
|
StringBuilder postBodyBuffer = new StringBuilder();
|
||||||
for (JMeterProperty jMeterProperty : sampler.getArguments()) {
|
for (JMeterProperty jMeterProperty : sampler.getArguments().getEnabledArguments()) {
|
||||||
HTTPArgument arg = (HTTPArgument) jMeterProperty.getObjectValue();
|
HTTPArgument arg = (HTTPArgument) jMeterProperty.getObjectValue();
|
||||||
postBodyBuffer.append(arg.getEncodedValue(contentEncoding));
|
postBodyBuffer.append(arg.getEncodedValue(contentEncoding));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -84,7 +84,7 @@ public class PutWriter extends PostWriter {
|
||||||
|
|
||||||
// Just append all the parameter values, and use that as the put body
|
// Just append all the parameter values, and use that as the put body
|
||||||
StringBuilder putBodyBuffer = new StringBuilder();
|
StringBuilder putBodyBuffer = new StringBuilder();
|
||||||
for (JMeterProperty jMeterProperty : sampler.getArguments()) {
|
for (JMeterProperty jMeterProperty : sampler.getArguments().getEnabledArguments()) {
|
||||||
HTTPArgument arg = (HTTPArgument) jMeterProperty.getObjectValue();
|
HTTPArgument arg = (HTTPArgument) jMeterProperty.getObjectValue();
|
||||||
putBodyBuffer.append(arg.getEncodedValue(contentEncoding));
|
putBodyBuffer.append(arg.getEncodedValue(contentEncoding));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue