You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jmeter.apache.org by pm...@apache.org on 2016/02/01 23:26:16 UTC

svn commit: r1728019 - in /jmeter/trunk: src/protocol/http/org/apache/jmeter/protocol/http/visualizers/RequestViewHTTP.java xdocs/changes.xml

Author: pmouawad
Date: Mon Feb  1 22:26:16 2016
New Revision: 1728019

URL: http://svn.apache.org/viewvc?rev=1728019&view=rev
Log:
Bug 58955 - Request view http does not correctly display http parameters in multipart/form-data
#resolve #99
Bugzilla Id: 58955

Modified:
    jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/visualizers/RequestViewHTTP.java
    jmeter/trunk/xdocs/changes.xml

Modified: jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/visualizers/RequestViewHTTP.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/visualizers/RequestViewHTTP.java?rev=1728019&r1=1728018&r2=1728019&view=diff
==============================================================================
--- jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/visualizers/RequestViewHTTP.java (original)
+++ jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/visualizers/RequestViewHTTP.java Mon Feb  1 22:26:16 2016
@@ -38,9 +38,13 @@ import javax.swing.table.TableCellRender
 import javax.swing.table.TableColumn;
 
 import org.apache.commons.lang3.StringUtils;
+import org.apache.jmeter.config.Argument;
 import org.apache.jmeter.gui.util.HeaderAsPropertyRenderer;
 import org.apache.jmeter.gui.util.TextBoxDialoger.TextBoxDoubleClick;
+import org.apache.jmeter.protocol.http.config.MultipartUrlConfig;
 import org.apache.jmeter.protocol.http.sampler.HTTPSampleResult;
+import org.apache.jmeter.protocol.http.util.HTTPConstants;
+import org.apache.jmeter.testelement.property.JMeterProperty;
 import org.apache.jmeter.util.JMeterUtils;
 import org.apache.jmeter.visualizers.RequestView;
 import org.apache.jmeter.visualizers.SamplerResultTab.RowResult;
@@ -181,6 +185,12 @@ public class RequestViewHTTP implements
                     JMeterUtils.getResString("view_results_table_request_http_method"), //$NON-NLS-1$
                     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
@@ -198,11 +208,13 @@ public class RequestViewHTTP implements
                         hUrl.getPath()));
     
                 String queryGet = hUrl.getQuery() == null ? "" : hUrl.getQuery(); //$NON-NLS-1$
+                boolean isMultipart = isMultipart(lhm);
+
                 // Concatenate query post if exists
                 String queryPost = sampleResult.getQueryString();
-                if (queryPost != null && queryPost.length() > 0) {
+                if (!isMultipart && StringUtils.isNotBlank(queryPost)) {
                     if (queryGet.length() > 0) {
-                        queryGet += PARAM_CONCATENATE; 
+                        queryGet += PARAM_CONCATENATE;
                     }
                     queryGet += queryPost;
                 }
@@ -211,10 +223,22 @@ public class RequestViewHTTP implements
                     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));                            
+                            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)
@@ -224,14 +248,9 @@ public class RequestViewHTTP implements
                         JMeterUtils.getParsedLabel("view_results_table_request_http_cookie"), //$NON-NLS-1$
                         sampleResult.getCookies()));
             }
-            
-            // 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()));
-            }
 
-        } else {
+        }
+        else {
             // add a message when no http sample
             requestModel.addRow(new RowResult("", //$NON-NLS-1$
                     JMeterUtils.getResString("view_results_table_request_http_nohttp"))); //$NON-NLS-1$
@@ -239,6 +258,35 @@ public class RequestViewHTTP implements
     }
 
     /**
+     * Extract the multipart boundary
+     * @param contentType the content type header
+     * @return  the boundary string
+     */
+    private String extractBoundary(String contentType) {
+        // Get the boundary string for the multiparts from the content type
+        String boundaryString = contentType.substring(contentType.toLowerCase(java.util.Locale.ENGLISH).indexOf("boundary=") + "boundary=".length());
+        //TODO check in the RFC if other char can be used as separator
+        String[] split = boundaryString.split(";");
+        if(split.length > 1) {
+            boundaryString = split[0];
+        }
+        return boundaryString;
+    }
+    
+    /**
+     * check if the request is multipart
+     * @param headers the http request headers
+     * @return true if the request is multipart
+     */
+    private boolean isMultipart(LinkedHashMap<String, String> headers) {
+        String contentType = headers.get(HTTPConstants.HEADER_CONTENT_TYPE);
+        if (contentType != null && contentType.startsWith(HTTPConstants.MULTIPART_FORM_DATA)) {
+            return true;
+        }
+        return false;
+    }
+
+    /**
      * @param query query to parse for param and value pairs
      * @return Map params and values
      */

Modified: jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1728019&r1=1728018&r2=1728019&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml (original)
+++ jmeter/trunk/xdocs/changes.xml Mon Feb  1 22:26:16 2016
@@ -132,6 +132,7 @@ Summary
 <li><bug>58791</bug>Deprecate listeners:Distribution Graph (alpha) and Spline Visualizer</li>
 <li><bug>58849</bug>View Results Tree : Add a search panel to the request http view to be able to search in the parameters table. Contributed by Benoit Wiart (benoit dot wiart at gmail.com)</li>
 <li><bug>58857</bug>View Results Tree : the request view http does not allow to resize the parameters table first column. Contributed by Benoit Wiart (benoit dot wiart at gmail.com)</li>
+<li><bug>58955</bug>Request view http does not correctly display http parameters in multipart/form-data. Contributed by Benoit Wiart (benoit dot wiart at gmail.com)</li>
 </ul>
 
 <h3>Timers, Assertions, Config, Pre- &amp; Post-Processors</h3>