Search in sources :

Example 1 with RowResult

use of org.apache.jmeter.visualizers.SamplerResultTab.RowResult 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 (Map.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"), 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<Map.Entry<String, String[]>> keys = RequestViewHTTP.getQueryMap(queryGet).entrySet();
                for (Map.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) MultipartUrlConfig(org.apache.jmeter.protocol.http.config.MultipartUrlConfig) HTTPSampleResult(org.apache.jmeter.protocol.http.sampler.HTTPSampleResult) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

URL (java.net.URL)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Argument (org.apache.jmeter.config.Argument)1 MultipartUrlConfig (org.apache.jmeter.protocol.http.config.MultipartUrlConfig)1 HTTPSampleResult (org.apache.jmeter.protocol.http.sampler.HTTPSampleResult)1 JMeterProperty (org.apache.jmeter.testelement.property.JMeterProperty)1 RowResult (org.apache.jmeter.visualizers.SamplerResultTab.RowResult)1