Search in sources :

Example 21 with HTTPArgument

use of org.apache.jmeter.protocol.http.util.HTTPArgument in project jmeter by apache.

the class HTTPSamplerBase method addNonEncodedArgument.

public void addNonEncodedArgument(String name, String value, String metadata) {
    HTTPArgument arg = new HTTPArgument(name, value, metadata, false);
    arg.setAlwaysEncoded(false);
    this.getArguments().addArgument(arg);
}
Also used : HTTPArgument(org.apache.jmeter.protocol.http.util.HTTPArgument)

Example 22 with HTTPArgument

use of org.apache.jmeter.protocol.http.util.HTTPArgument in project jmeter by apache.

the class HTTPSamplerBase method getQueryString.

/**
     * Gets the QueryString attribute of the UrlConfig object, using the
     * specified encoding to encode the parameter values put into the URL
     *
     * @param contentEncoding the encoding to use for encoding parameter values
     * @return the QueryString value
     */
public String getQueryString(final String contentEncoding) {
    CollectionProperty arguments = getArguments().getArguments();
    // Optimisation : avoid building useless objects if empty arguments
    if (arguments.size() == 0) {
        return "";
    }
    String lContentEncoding = contentEncoding;
    // Check if the sampler has a specified content encoding
    if (JOrphanUtils.isBlank(lContentEncoding)) {
        // We use the encoding which should be used according to the HTTP spec, which is UTF-8
        lContentEncoding = EncoderCache.URL_ARGUMENT_ENCODING;
    }
    StringBuilder buf = new StringBuilder(arguments.size() * 15);
    PropertyIterator iter = arguments.iterator();
    boolean first = true;
    while (iter.hasNext()) {
        HTTPArgument item = null;
        /*
             * N.B. Revision 323346 introduced the ClassCast check, but then used iter.next()
             * to fetch the item to be cast, thus skipping the element that did not cast.
             * Reverted to work more like the original code, but with the check in place.
             * Added a warning message so can track whether it is necessary
             */
        Object objectValue = iter.next().getObjectValue();
        try {
            item = (HTTPArgument) objectValue;
        } catch (ClassCastException e) {
            // NOSONAR
            log.warn("Unexpected argument type: " + objectValue.getClass().getName() + " cannot be cast to HTTPArgument");
            item = new HTTPArgument((Argument) objectValue);
        }
        final String encodedName = item.getEncodedName();
        if (encodedName.length() == 0) {
            // Skip parameters with a blank name (allows use of optional variables in parameter lists)
            continue;
        }
        if (!first) {
            buf.append(QRY_SEP);
        } else {
            first = false;
        }
        buf.append(encodedName);
        if (item.getMetaData() == null) {
            buf.append(ARG_VAL_SEP);
        } else {
            buf.append(item.getMetaData());
        }
        // Encode the parameter value in the specified content encoding
        try {
            buf.append(item.getEncodedValue(lContentEncoding));
        } catch (UnsupportedEncodingException e) {
            // NOSONAR
            log.warn("Unable to encode parameter in encoding " + lContentEncoding + ", parameter value not included in query string");
        }
    }
    return buf.toString();
}
Also used : CollectionProperty(org.apache.jmeter.testelement.property.CollectionProperty) HTTPArgument(org.apache.jmeter.protocol.http.util.HTTPArgument) PropertyIterator(org.apache.jmeter.testelement.property.PropertyIterator) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 23 with HTTPArgument

use of org.apache.jmeter.protocol.http.util.HTTPArgument in project jmeter by apache.

the class HTTPArgumentsPanel method makeNewArgument.

@Override
protected HTTPArgument makeNewArgument() {
    HTTPArgument arg = new HTTPArgument("", "");
    arg.setAlwaysEncoded(false);
    arg.setUseEquals(true);
    return arg;
}
Also used : HTTPArgument(org.apache.jmeter.protocol.http.util.HTTPArgument)

Aggregations

HTTPArgument (org.apache.jmeter.protocol.http.util.HTTPArgument)23 Arguments (org.apache.jmeter.config.Arguments)9 JMeterProperty (org.apache.jmeter.testelement.property.JMeterProperty)8 HTTPFileArg (org.apache.jmeter.protocol.http.util.HTTPFileArg)5 File (java.io.File)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 HttpEntity (org.apache.http.HttpEntity)2 FileEntity (org.apache.http.entity.FileEntity)2 StringEntity (org.apache.http.entity.StringEntity)2 ValueReplacer (org.apache.jmeter.engine.util.ValueReplacer)2 TestPlan (org.apache.jmeter.testelement.TestPlan)2 PropertyIterator (org.apache.jmeter.testelement.property.PropertyIterator)2 JMeterVariables (org.apache.jmeter.threads.JMeterVariables)2 InputStream (java.io.InputStream)1 URLConnection (java.net.URLConnection)1 Charset (java.nio.charset.Charset)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 GZIPInputStream (java.util.zip.GZIPInputStream)1