Search in sources :

Example 1 with Argument

use of org.apache.jmeter.config.Argument in project jmeter by apache.

the class RequestViewHTTP method setSamplerResult.

/* (non-Javadoc)
     * @see org.apache.jmeter.visualizers.request.RequestView#setSamplerResult(java.lang.Object)
     */
@Override
public void setSamplerResult(Object objectResult) {
    this.searchTextExtension.resetTextToFind();
    if (objectResult instanceof HTTPSampleResult) {
        HTTPSampleResult sampleResult = (HTTPSampleResult) objectResult;
        // Display with same order HTTP protocol
        requestModel.addRow(new RowResult(//$NON-NLS-1$
        JMeterUtils.getResString("view_results_table_request_http_method"), sampleResult.getHTTPMethod()));
        // Parsed request headers
        LinkedHashMap<String, String> lhm = JMeterUtils.parseHeaders(sampleResult.getRequestHeaders());
        for (Entry<String, String> entry : lhm.entrySet()) {
            headersModel.addRow(new RowResult(entry.getKey(), entry.getValue()));
        }
        URL hUrl = sampleResult.getURL();
        if (hUrl != null) {
            // can be null - e.g. if URL was invalid
            requestModel.addRow(new RowResult(JMeterUtils.getResString(//$NON-NLS-1$
            "view_results_table_request_http_protocol"), hUrl.getProtocol()));
            requestModel.addRow(new RowResult(//$NON-NLS-1$
            JMeterUtils.getResString("view_results_table_request_http_host"), hUrl.getHost()));
            int port = hUrl.getPort() == -1 ? hUrl.getDefaultPort() : hUrl.getPort();
            requestModel.addRow(new RowResult(//$NON-NLS-1$
            JMeterUtils.getResString("view_results_table_request_http_port"), Integer.valueOf(port)));
            requestModel.addRow(new RowResult(//$NON-NLS-1$
            JMeterUtils.getResString("view_results_table_request_http_path"), hUrl.getPath()));
            //$NON-NLS-1$
            String queryGet = hUrl.getQuery() == null ? "" : hUrl.getQuery();
            boolean isMultipart = isMultipart(lhm);
            // Concatenate query post if exists
            String queryPost = sampleResult.getQueryString();
            if (!isMultipart && StringUtils.isNotBlank(queryPost)) {
                if (queryGet.length() > 0) {
                    queryGet += PARAM_CONCATENATE;
                }
                queryGet += queryPost;
            }
            if (StringUtils.isNotBlank(queryGet)) {
                Set<Entry<String, String[]>> keys = RequestViewHTTP.getQueryMap(queryGet).entrySet();
                for (Entry<String, String[]> entry : keys) {
                    for (String value : entry.getValue()) {
                        paramsModel.addRow(new RowResult(entry.getKey(), value));
                    }
                }
            }
            if (isMultipart && StringUtils.isNotBlank(queryPost)) {
                String contentType = lhm.get(HTTPConstants.HEADER_CONTENT_TYPE);
                String boundaryString = extractBoundary(contentType);
                MultipartUrlConfig urlconfig = new MultipartUrlConfig(boundaryString);
                urlconfig.parseArguments(queryPost);
                for (JMeterProperty prop : urlconfig.getArguments()) {
                    Argument arg = (Argument) prop.getObjectValue();
                    paramsModel.addRow(new RowResult(arg.getName(), arg.getValue()));
                }
            }
        }
        // Display cookie in headers table (same location on http protocol)
        String cookie = sampleResult.getCookies();
        if (cookie != null && cookie.length() > 0) {
            headersModel.addRow(new RowResult(//$NON-NLS-1$
            JMeterUtils.getParsedLabel("view_results_table_request_http_cookie"), sampleResult.getCookies()));
        }
    } else {
        // add a message when no http sample
        requestModel.addRow(new //$NON-NLS-1$
        RowResult(//$NON-NLS-1$
        "", //$NON-NLS-1$
        JMeterUtils.getResString("view_results_table_request_http_nohttp")));
    }
}
Also used : JMeterProperty(org.apache.jmeter.testelement.property.JMeterProperty) Argument(org.apache.jmeter.config.Argument) URL(java.net.URL) RowResult(org.apache.jmeter.visualizers.SamplerResultTab.RowResult) Entry(java.util.Map.Entry) MultipartUrlConfig(org.apache.jmeter.protocol.http.config.MultipartUrlConfig) HTTPSampleResult(org.apache.jmeter.protocol.http.sampler.HTTPSampleResult)

Example 2 with Argument

use of org.apache.jmeter.config.Argument in project jmeter by apache.

the class JavaConfigGui method configureClassName.

/**
     * 
     */
private void configureClassName() {
    String className = classNameLabeledChoice.getText().trim();
    try {
        JavaSamplerClient client = (JavaSamplerClient) Class.forName(className, true, Thread.currentThread().getContextClassLoader()).newInstance();
        Arguments currArgs = new Arguments();
        argsPanel.modifyTestElement(currArgs);
        Map<String, String> currArgsMap = currArgs.getArgumentsAsMap();
        Arguments newArgs = new Arguments();
        Arguments testParams = null;
        try {
            testParams = client.getDefaultParameters();
        } catch (AbstractMethodError e) {
            log.warn("JavaSamplerClient doesn't implement " + "getDefaultParameters.  Default parameters won't " + "be shown.  Please update your client class: " + className);
        }
        if (testParams != null) {
            for (JMeterProperty jMeterProperty : testParams.getArguments()) {
                Argument arg = (Argument) jMeterProperty.getObjectValue();
                String name = arg.getName();
                String value = arg.getValue();
                // values that they did in the original test.
                if (currArgsMap.containsKey(name)) {
                    String newVal = currArgsMap.get(name);
                    if (newVal != null && newVal.length() > 0) {
                        value = newVal;
                    }
                }
                newArgs.addArgument(name, value);
            }
        }
        argsPanel.configure(newArgs);
        warningLabel.setVisible(false);
    } catch (Exception e) {
        log.error("Error getting argument list for " + className, e);
        warningLabel.setVisible(true);
    }
}
Also used : JMeterProperty(org.apache.jmeter.testelement.property.JMeterProperty) Argument(org.apache.jmeter.config.Argument) Arguments(org.apache.jmeter.config.Arguments) JavaSamplerClient(org.apache.jmeter.protocol.java.sampler.JavaSamplerClient)

Example 3 with Argument

use of org.apache.jmeter.config.Argument in project jmeter by apache.

the class TestHTTPSamplers method testParseArguments.

// Parse arguments singly
@Test
public void testParseArguments() {
    HTTPSamplerBase sampler = new HTTPNullSampler();
    Arguments args;
    Argument arg;
    args = sampler.getArguments();
    assertEquals(0, args.getArgumentCount());
    assertEquals(0, sampler.getHTTPFileCount());
    sampler.parseArguments("");
    args = sampler.getArguments();
    assertEquals(0, args.getArgumentCount());
    assertEquals(0, sampler.getHTTPFileCount());
    sampler.parseArguments("name1");
    args = sampler.getArguments();
    assertEquals(1, args.getArgumentCount());
    arg = args.getArgument(0);
    assertEquals("name1", arg.getName());
    assertEquals("", arg.getMetaData());
    assertEquals("", arg.getValue());
    assertEquals(0, sampler.getHTTPFileCount());
    sampler.parseArguments("name2=");
    args = sampler.getArguments();
    assertEquals(2, args.getArgumentCount());
    arg = args.getArgument(1);
    assertEquals("name2", arg.getName());
    assertEquals("=", arg.getMetaData());
    assertEquals("", arg.getValue());
    assertEquals(0, sampler.getHTTPFileCount());
    sampler.parseArguments("name3=value3");
    args = sampler.getArguments();
    assertEquals(3, args.getArgumentCount());
    arg = args.getArgument(2);
    assertEquals("name3", arg.getName());
    assertEquals("=", arg.getMetaData());
    assertEquals("value3", arg.getValue());
    assertEquals(0, sampler.getHTTPFileCount());
}
Also used : Argument(org.apache.jmeter.config.Argument) Arguments(org.apache.jmeter.config.Arguments) Test(org.junit.Test)

Example 4 with Argument

use of org.apache.jmeter.config.Argument in project jmeter by apache.

the class TestHtmlParsingUtils method testIsArgumentMatched.

@Test
public void testIsArgumentMatched() throws Exception {
    Argument arg = new Argument();
    Argument argp = new Argument();
    assertTrue(HtmlParsingUtils.isArgumentMatched(arg, argp));
    arg = new Argument("test", "abcd");
    argp = new Argument("test", "a.*d");
    assertTrue(HtmlParsingUtils.isArgumentMatched(arg, argp));
    arg = new Argument("test", "abcd");
    argp = new Argument("test", "a.*e");
    assertFalse(HtmlParsingUtils.isArgumentMatched(arg, argp));
}
Also used : Argument(org.apache.jmeter.config.Argument) Test(org.junit.Test)

Example 5 with Argument

use of org.apache.jmeter.config.Argument in project jmeter by apache.

the class ArgumentsPanel method addFromClipboard.

/**
     * Add values from the clipboard
     */
protected void addFromClipboard() {
    GuiUtils.stopTableEditing(table);
    int rowCount = table.getRowCount();
    try {
        String clipboardContent = GuiUtils.getPastedText();
        if (clipboardContent == null) {
            return;
        }
        String[] clipboardLines = clipboardContent.split("\n");
        for (String clipboardLine : clipboardLines) {
            String[] clipboardCols = clipboardLine.split("\t");
            if (clipboardCols.length > 0) {
                Argument argument = createArgumentFromClipboard(clipboardCols);
                tableModel.addRow(argument);
            }
        }
        if (table.getRowCount() > rowCount) {
            checkButtonsStatus();
            // Highlight (select) and scroll to the appropriate rows.
            int rowToSelect = tableModel.getRowCount() - 1;
            table.setRowSelectionInterval(rowCount, rowToSelect);
            table.scrollRectToVisible(table.getCellRect(rowCount, 0, true));
        }
    } catch (IOException ioe) {
        JOptionPane.showMessageDialog(this, "Could not add read arguments from clipboard:\n" + ioe.getLocalizedMessage(), "Error", JOptionPane.ERROR_MESSAGE);
    } catch (UnsupportedFlavorException ufe) {
        JOptionPane.showMessageDialog(this, "Could not add retrieve " + DataFlavor.stringFlavor.getHumanPresentableName() + " from clipboard" + ufe.getLocalizedMessage(), "Error", JOptionPane.ERROR_MESSAGE);
    }
}
Also used : Argument(org.apache.jmeter.config.Argument) IOException(java.io.IOException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException)

Aggregations

Argument (org.apache.jmeter.config.Argument)28 Arguments (org.apache.jmeter.config.Arguments)13 JMeterProperty (org.apache.jmeter.testelement.property.JMeterProperty)11 Test (org.junit.Test)7 PropertyIterator (org.apache.jmeter.testelement.property.PropertyIterator)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 BasicAttribute (javax.naming.directory.BasicAttribute)3 CollectionProperty (org.apache.jmeter.testelement.property.CollectionProperty)3 File (java.io.File)2 BasicAttributes (javax.naming.directory.BasicAttributes)2 JTextField (javax.swing.JTextField)2 HTTPSampleResult (org.apache.jmeter.protocol.http.sampler.HTTPSampleResult)2 HTTPSamplerBase (org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase)2 HTTPFileArg (org.apache.jmeter.protocol.http.util.HTTPFileArg)2 HTTPFileArgs (org.apache.jmeter.protocol.http.util.HTTPFileArgs)2 SampleResult (org.apache.jmeter.samplers.SampleResult)2 Sampler (org.apache.jmeter.samplers.Sampler)2 UnsupportedFlavorException (java.awt.datatransfer.UnsupportedFlavorException)1 BufferedInputStream (java.io.BufferedInputStream)1