Search in sources :

Example 66 with JMeterProperty

use of org.apache.jmeter.testelement.property.JMeterProperty in project jmeter by apache.

the class ReplaceStringWithFunctions method transformValue.

@Override
public JMeterProperty transformValue(JMeterProperty prop) throws InvalidVariableException {
    JMeterProperty newValue = prop;
    getMasterFunction().clear();
    getMasterFunction().setParameters(prop.getStringValue());
    if (getMasterFunction().hasFunction()) {
        newValue = new FunctionProperty(prop.getName(), getMasterFunction().getFunction());
    }
    return newValue;
}
Also used : JMeterProperty(org.apache.jmeter.testelement.property.JMeterProperty) FunctionProperty(org.apache.jmeter.testelement.property.FunctionProperty)

Example 67 with JMeterProperty

use of org.apache.jmeter.testelement.property.JMeterProperty in project jmeter by apache.

the class HTTPJavaImpl method setConnectionHeaders.

/**
     * Extracts all the required headers for that particular URL request and
     * sets them in the <code>HttpURLConnection</code> passed in
     *
     * @param conn
     *            <code>HttpUrlConnection</code> which represents the URL
     *            request
     * @param u
     *            <code>URL</code> of the URL request
     * @param headerManager
     *            the <code>HeaderManager</code> containing all the cookies
     *            for this <code>UrlConfig</code>
     * @param cacheManager the CacheManager (may be null)
     */
private void setConnectionHeaders(HttpURLConnection conn, URL u, HeaderManager headerManager, CacheManager cacheManager) {
    // Add all the headers from the HeaderManager
    if (headerManager != null) {
        CollectionProperty headers = headerManager.getHeaders();
        if (headers != null) {
            for (JMeterProperty jMeterProperty : headers) {
                Header header = (Header) jMeterProperty.getObjectValue();
                String n = header.getName();
                String v = header.getValue();
                conn.addRequestProperty(n, v);
            }
        }
    }
    if (cacheManager != null) {
        cacheManager.setHeaders(conn, u);
    }
}
Also used : CollectionProperty(org.apache.jmeter.testelement.property.CollectionProperty) JMeterProperty(org.apache.jmeter.testelement.property.JMeterProperty) Header(org.apache.jmeter.protocol.http.control.Header)

Example 68 with JMeterProperty

use of org.apache.jmeter.testelement.property.JMeterProperty in project jmeter by apache.

the class HTTPSamplerBase method mergeFileProperties.

/**
     * JMeter 2.3.1 and earlier only had fields for one file on the GUI:
     * <ul>
     *   <li>FILE_NAME</li>
     *   <li>FILE_FIELD</li>
     *   <li>MIMETYPE</li>
     * </ul>
     * These were stored in their own individual properties.
     * <p>
     * Version 2.3.3 introduced a list of files, each with their own path, name and mimetype.
     * <p>
     * In order to maintain backwards compatibility of test plans, the 3 original properties
     * were retained; additional file entries are stored in an HTTPFileArgs class.
     * The HTTPFileArgs class was only present if there is more than 1 file; this means that
     * such test plans are backward compatible.
     * <p>
     * Versions after 2.3.4 dispense with the original set of 3 properties.
     * Test plans that use them are converted to use a single HTTPFileArgs list.
     *
     * @see HTTPSamplerBaseConverter
     */
void mergeFileProperties() {
    JMeterProperty fileName = getProperty(FILE_NAME);
    JMeterProperty paramName = getProperty(FILE_FIELD);
    JMeterProperty mimeType = getProperty(MIMETYPE);
    HTTPFileArg oldStyleFile = new HTTPFileArg(fileName, paramName, mimeType);
    HTTPFileArgs fileArgs = getHTTPFileArgs();
    HTTPFileArgs allFileArgs = new HTTPFileArgs();
    if (oldStyleFile.isNotEmpty()) {
        // OK, we have an old-style file definition
        // save it
        allFileArgs.addHTTPFileArg(oldStyleFile);
        // Now deal with any additional file arguments
        if (fileArgs != null) {
            HTTPFileArg[] infiles = fileArgs.asArray();
            for (HTTPFileArg infile : infiles) {
                allFileArgs.addHTTPFileArg(infile);
            }
        }
    } else {
        if (fileArgs != null) {
            // for new test plans that don't have FILE/PARAM/MIME properties
            allFileArgs = fileArgs;
        }
    }
    // Updated the property lists
    setHTTPFileArgs(allFileArgs);
    removeProperty(FILE_FIELD);
    removeProperty(FILE_NAME);
    removeProperty(MIMETYPE);
}
Also used : JMeterProperty(org.apache.jmeter.testelement.property.JMeterProperty) HTTPFileArgs(org.apache.jmeter.protocol.http.util.HTTPFileArgs) HTTPFileArg(org.apache.jmeter.protocol.http.util.HTTPFileArg)

Example 69 with JMeterProperty

use of org.apache.jmeter.testelement.property.JMeterProperty in project jmeter by apache.

the class AjpSampler method setConnectionHeaders.

private String setConnectionHeaders(URL url, String host, String method) throws IOException {
    HeaderManager headers = getHeaderManager();
    AuthManager auth = getAuthManager();
    StringBuilder hbuf = new StringBuilder();
    // Allow Headers to override Host setting
    //$NON-NLS-1$
    hbuf.append("Host").append(COLON_SPACE).append(host).append(NEWLINE);
    //Host
    setInt(0xA00b);
    setString(host);
    if (headers != null) {
        for (JMeterProperty jMeterProperty : headers.getHeaders()) {
            Header header = (Header) jMeterProperty.getObjectValue();
            String n = header.getName();
            String v = header.getValue();
            hbuf.append(n).append(COLON_SPACE).append(v).append(NEWLINE);
            int hc = translateHeader(n);
            if (hc > 0) {
                setInt(hc + AJP_HEADER_BASE);
            } else {
                setString(n);
            }
            setString(v);
        }
    }
    if (method.equals(HTTPConstants.POST)) {
        int cl = -1;
        HTTPFileArg[] hfa = getHTTPFiles();
        if (hfa.length > 0) {
            HTTPFileArg fa = hfa[0];
            String fn = fa.getPath();
            File input = new File(fn);
            cl = (int) input.length();
            if (body != null) {
                JOrphanUtils.closeQuietly(body);
                body = null;
            }
            body = new BufferedInputStream(new FileInputStream(input));
            setString(HTTPConstants.HEADER_CONTENT_DISPOSITION);
            setString("form-data; name=\"" + encode(fa.getParamName()) + "\"; filename=\"" + encode(fn) + //$NON-NLS-1$ //$NON-NLS-2$
            "\"");
            String mt = fa.getMimeType();
            hbuf.append(HTTPConstants.HEADER_CONTENT_TYPE).append(COLON_SPACE).append(mt).append(NEWLINE);
            // content-type
            setInt(0xA007);
            setString(mt);
        } else {
            hbuf.append(HTTPConstants.HEADER_CONTENT_TYPE).append(COLON_SPACE).append(HTTPConstants.APPLICATION_X_WWW_FORM_URLENCODED).append(NEWLINE);
            // content-type
            setInt(0xA007);
            setString(HTTPConstants.APPLICATION_X_WWW_FORM_URLENCODED);
            StringBuilder sb = new StringBuilder();
            boolean first = true;
            for (JMeterProperty arg : getArguments()) {
                if (first) {
                    first = false;
                } else {
                    sb.append('&');
                }
                sb.append(arg.getStringValue());
            }
            stringBody = sb.toString();
            // TODO - charset?
            byte[] sbody = stringBody.getBytes();
            cl = sbody.length;
            body = new ByteArrayInputStream(sbody);
        }
        hbuf.append(HTTPConstants.HEADER_CONTENT_LENGTH).append(COLON_SPACE).append(String.valueOf(cl)).append(NEWLINE);
        // Content-length
        setInt(0xA008);
        setString(String.valueOf(cl));
    }
    if (auth != null) {
        String authHeader = auth.getAuthHeaderForURL(url);
        if (authHeader != null) {
            // Authorization
            setInt(0xA005);
            setString(authHeader);
            hbuf.append(HTTPConstants.HEADER_AUTHORIZATION).append(COLON_SPACE).append(authHeader).append(NEWLINE);
        }
    }
    return hbuf.toString();
}
Also used : JMeterProperty(org.apache.jmeter.testelement.property.JMeterProperty) AuthManager(org.apache.jmeter.protocol.http.control.AuthManager) HTTPFileArg(org.apache.jmeter.protocol.http.util.HTTPFileArg) FileInputStream(java.io.FileInputStream) HeaderManager(org.apache.jmeter.protocol.http.control.HeaderManager) Header(org.apache.jmeter.protocol.http.control.Header) BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) File(java.io.File)

Example 70 with JMeterProperty

use of org.apache.jmeter.testelement.property.JMeterProperty in project jmeter by apache.

the class HTTPArgument method convertArgumentsToHTTP.

/**
     * Converts all {@link Argument} entries in the collection to {@link HTTPArgument} entries.
     * 
     * @param args collection of {@link Argument} and/or {@link HTTPArgument} entries
     */
public static void convertArgumentsToHTTP(Arguments args) {
    List<Argument> newArguments = new LinkedList<>();
    for (JMeterProperty jMeterProperty : args.getArguments()) {
        Argument arg = (Argument) jMeterProperty.getObjectValue();
        if (!(arg instanceof HTTPArgument)) {
            newArguments.add(new HTTPArgument(arg));
        } else {
            newArguments.add(arg);
        }
    }
    args.removeAllArguments();
    args.setArguments(newArguments);
}
Also used : JMeterProperty(org.apache.jmeter.testelement.property.JMeterProperty) Argument(org.apache.jmeter.config.Argument) LinkedList(java.util.LinkedList)

Aggregations

JMeterProperty (org.apache.jmeter.testelement.property.JMeterProperty)87 StringProperty (org.apache.jmeter.testelement.property.StringProperty)23 Test (org.junit.Test)23 PropertyIterator (org.apache.jmeter.testelement.property.PropertyIterator)13 CollectionProperty (org.apache.jmeter.testelement.property.CollectionProperty)12 Argument (org.apache.jmeter.config.Argument)11 ArrayList (java.util.ArrayList)9 HTTPArgument (org.apache.jmeter.protocol.http.util.HTTPArgument)8 File (java.io.File)7 Arguments (org.apache.jmeter.config.Arguments)7 HTTPFileArg (org.apache.jmeter.protocol.http.util.HTTPFileArg)6 TestElement (org.apache.jmeter.testelement.TestElement)6 ConfigTestElement (org.apache.jmeter.config.ConfigTestElement)5 URL (java.net.URL)4 TestElementProperty (org.apache.jmeter.testelement.property.TestElementProperty)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 HashMap (java.util.HashMap)3 Sampler (org.apache.jmeter.samplers.Sampler)3 TestPlan (org.apache.jmeter.testelement.TestPlan)3 NullProperty (org.apache.jmeter.testelement.property.NullProperty)3