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 22:22:34 UTC

svn commit: r1728009 - in /jmeter/trunk: src/protocol/http/org/apache/jmeter/protocol/http/visualizers/ test/src/org/apache/jmeter/protocol/http/visualizers/ xdocs/

Author: pmouawad
Date: Mon Feb  1 21:22:33 2016
New Revision: 1728009

URL: http://svn.apache.org/viewvc?rev=1728009&view=rev
Log:
Bug 58413 - ViewResultsTree : Request HTTP Renderer does not show correctly parameters that contain &
Bug 58954 - Request view http does not correctly display http parameter if it contains '&'.
#resolve #98
Bugzilla Id: 58413

Added:
    jmeter/trunk/test/src/org/apache/jmeter/protocol/http/visualizers/
    jmeter/trunk/test/src/org/apache/jmeter/protocol/http/visualizers/RequestViewHTTPTest.java   (with props)
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=1728009&r1=1728008&r2=1728009&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 21:22:33 2016
@@ -37,6 +37,7 @@ import javax.swing.JTable;
 import javax.swing.table.TableCellRenderer;
 import javax.swing.table.TableColumn;
 
+import org.apache.commons.lang3.StringUtils;
 import org.apache.jmeter.gui.util.HeaderAsPropertyRenderer;
 import org.apache.jmeter.gui.util.TextBoxDialoger.TextBoxDoubleClick;
 import org.apache.jmeter.protocol.http.sampler.HTTPSampleResult;
@@ -206,8 +207,7 @@ public class RequestViewHTTP implements
                     queryGet += queryPost;
                 }
                 
-                queryGet = RequestViewHTTP.decodeQuery(queryGet);
-                if (queryGet != null) {
+                if (StringUtils.isNotBlank(queryGet)) {
                     Set<Entry<String, String[]>> keys = RequestViewHTTP.getQueryMap(queryGet).entrySet();
                     for (Entry<String, String[]> entry : keys) {
                         for (String value : entry.getValue()) {
@@ -239,40 +239,34 @@ public class RequestViewHTTP implements
     }
 
     /**
-     * @param query
-     *            query to parse for param and value pairs
-     * @return Map params and Svalue
+     * @param query query to parse for param and value pairs
+     * @return Map params and values
      */
     //TODO: move to utils class (JMeterUtils?)
     public static Map<String, String[]> getQueryMap(String query) {
 
         Map<String, String[]> map = new HashMap<>();
-        if (query.trim().startsWith("<?")) { // $NON-NLS-1$
-            // SOAP request (generally)
-            map.put(" ", new String[] {query}); //blank name // $NON-NLS-1$
-            return map;
-        }
-        
         String[] params = query.split(PARAM_CONCATENATE);
         for (String param : params) {
-            String[] paramSplit = param.split("="); // $NON-NLS-1$
-            if (paramSplit.length > 2 ) {// detected invalid syntax (Bug 52491)
-                // Return as for SOAP above
-                map.clear();
+            String[] paramSplit = param.split("=");
+            String name = paramSplit[0];
+            name = decodeQuery(name);
+            
+            // hack for SOAP request (generally)
+            if (name.trim().startsWith("<?")) { // $NON-NLS-1$
                 map.put(" ", new String[] {query}); //blank name // $NON-NLS-1$
                 return map;
             }
             
-            String name = null;
-            if (paramSplit.length > 0) {
-                name = paramSplit[0];
-            }
-            String value = ""; // empty init // $NON-NLS-1$
-            if (paramSplit.length > 1) {
-                // We use substring to keep = sign (Bug 54055), we are sure = is present
-                value = param.substring(param.indexOf("=")+1); // $NON-NLS-1$
+            // the post payload is not key=value
+            if(paramSplit.length == 1 || paramSplit.length > 2) {
+                map.put(" ", new String[] {query}); //blank name // $NON-NLS-1$
+                return map;
             }
             
+            String value = paramSplit[1];
+            value = decodeQuery(value);
+            
             String[] known = map.get(name);
             if(known == null) {
                 known = new String[] {value};
@@ -285,6 +279,7 @@ public class RequestViewHTTP implements
             }
             map.put(name, known);
         }
+        
         return map;
     }
 

Added: jmeter/trunk/test/src/org/apache/jmeter/protocol/http/visualizers/RequestViewHTTPTest.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jmeter/protocol/http/visualizers/RequestViewHTTPTest.java?rev=1728009&view=auto
==============================================================================
--- jmeter/trunk/test/src/org/apache/jmeter/protocol/http/visualizers/RequestViewHTTPTest.java (added)
+++ jmeter/trunk/test/src/org/apache/jmeter/protocol/http/visualizers/RequestViewHTTPTest.java Mon Feb  1 21:22:33 2016
@@ -0,0 +1,175 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.jmeter.protocol.http.visualizers;
+
+import java.util.Map;
+
+import org.apache.commons.lang3.StringUtils;
+import org.junit.Assert;
+import org.junit.Test;
+
+import junit.framework.TestCase;
+
+public class RequestViewHTTPTest extends TestCase {
+    @Test
+    public void testGetQueryMapValueContainingAmpersand() {
+        // see https://bz.apache.org/bugzilla/show_bug.cgi?id=58413
+        String query = "login=toto1&pwd=Welcome%261";
+        Map<String, String[]> params = RequestViewHTTP.getQueryMap(query);
+        
+        Assert.assertNotNull(params);
+        Assert.assertEquals(2, params.size());
+        
+        String[] param1 = params.get("login");
+        Assert.assertNotNull(param1);
+        Assert.assertEquals(1, param1.length);
+        Assert.assertEquals("toto1", param1[0]);
+        
+        String[] param2 = params.get("pwd");
+        Assert.assertNotNull(param2);
+        Assert.assertEquals(1, param2.length);
+        Assert.assertEquals("Welcome&1", param2[0]);
+    }
+    
+    @Test
+    public void testGetQueryMapMultipleValues() {
+        String query = "param2=15&param1=12&param2=baulpismuth";
+        Map<String, String[]> params = RequestViewHTTP.getQueryMap(query);
+        
+        Assert.assertNotNull(params);
+        Assert.assertEquals(2, params.size());
+        
+        String[] param1 = params.get("param1");
+        Assert.assertNotNull(param1);
+        Assert.assertEquals(1, param1.length);
+        Assert.assertEquals("12", param1[0]);
+        
+        String[] param2 = params.get("param2");
+        Assert.assertNotNull(param2);
+        Assert.assertEquals(2, param2.length);
+        Assert.assertEquals("15", param2[0]);
+        Assert.assertEquals("baulpismuth", param2[1]);
+    }
+    
+    @Test
+    public void testGetQueryMapAmpInValue() {
+        String query = "param2=15&param1=12&param3=baul%26Pismuth";
+        Map<String, String[]> params = RequestViewHTTP.getQueryMap(query);
+        
+        Assert.assertNotNull(params);
+        Assert.assertEquals(3, params.size());
+        
+        String[] param1 = params.get("param1");
+        Assert.assertNotNull(param1);
+        Assert.assertEquals(1, param1.length);
+        Assert.assertEquals("12", param1[0]);
+        
+        String[] param2 = params.get("param2");
+        Assert.assertNotNull(param2);
+        Assert.assertEquals(1, param2.length);
+        Assert.assertEquals("15", param2[0]);
+        
+        String[] param3 = params.get("param3");
+        Assert.assertNotNull(param3);
+        Assert.assertEquals(1, param3.length);
+        Assert.assertEquals("baul&Pismuth", param3[0]);
+    }
+    
+    @Test
+    public void testGetQueryMapBug54055() {
+        String query = "param2=15&param1=12&param3=bu4m1KzFvsozCnR4lra0%2Be69YzpnRcF09nDjc3VJvl8%3D";
+        Map<String, String[]> params = RequestViewHTTP.getQueryMap(query);
+        
+        Assert.assertNotNull(params);
+        Assert.assertEquals(3, params.size());
+        
+        String[] param1 = params.get("param1");
+        Assert.assertNotNull(param1);
+        Assert.assertEquals(1, param1.length);
+        Assert.assertEquals("12", param1[0]);
+        
+        String[] param2 = params.get("param2");
+        Assert.assertNotNull(param2);
+        Assert.assertEquals(1, param2.length);
+        Assert.assertEquals("15", param2[0]);
+        
+        String[] param3 = params.get("param3");
+        Assert.assertNotNull(param3);
+        Assert.assertEquals(1, param3.length);
+        Assert.assertEquals("bu4m1KzFvsozCnR4lra0+e69YzpnRcF09nDjc3VJvl8=", param3[0]);
+    }
+    
+    @Test
+    public void testGetQueryMapBug52491() {
+        String query = "<envelope><header><context><conversationId>119</conversationId></context></header><body><call component=\"OrderTransfer\" method=\"getSourceManifestID\" id=\"2\">\n" + 
+                "<params></params><refs></refs></call></body></envelope>";
+        Map<String, String[]> params = RequestViewHTTP.getQueryMap(query);
+        
+        Assert.assertNotNull(params);
+        Assert.assertEquals(1, params.size());
+        
+        Map.Entry<String, String[]> param1 = params.entrySet().iterator().next();
+        Assert.assertNotNull(param1);
+        Assert.assertEquals(1, param1.getValue().length);
+        Assert.assertEquals(query, param1.getValue()[0]);
+        Assert.assertTrue(StringUtils.isBlank(param1.getKey()));
+    }
+    
+    @Test
+    public void testGetQueryMapSoapHack() {
+        String query = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
+                + "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"\n" + 
+                "xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\"\n" + 
+                "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" + 
+                "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">\n" + 
+                "    <SOAP-ENV:Header>\n" + 
+                "        <m:Security\n" + 
+                "xmlns:m=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\">\n" + 
+                "            <UsernameToken>\n" + 
+                "                <Username>hello</Username>\n" + 
+                "                <Password>world</Password>\n" + 
+                "            </UsernameToken>\n" + 
+                "        </m:Security>\n" + 
+                "    </SOAP-ENV:Header>\n" + 
+                "    <SOAP-ENV:Body>     \n" + 
+                "        <m:GeefPersoon xmlns:m=\"http://webservice.namespace\">\n" + 
+                "            <Vraag>\n" + 
+                "                <Context>\n" + 
+                "                    <Naam>GeefPersoon</Naam>\n" + 
+                "                    <Versie>01.00.0000</Versie>\n" + 
+                "                </Context>\n" + 
+                "                <Inhoud>\n" + 
+                "                    <INSZ>650602505589</INSZ>\n" + 
+                "                </Inhoud>\n" + 
+                "            </Vraag>\n" + 
+                "        </m:GeefPersoon>\n" + 
+                "    </SOAP-ENV:Body>\n" + 
+                "</SOAP-ENV:Envelope>";
+        Map<String, String[]> params = RequestViewHTTP.getQueryMap(query);
+        
+        Assert.assertNotNull(params);
+        Assert.assertEquals(1, params.size());
+        
+        Map.Entry<String, String[]> param1 = params.entrySet().iterator().next();
+        Assert.assertNotNull(param1);
+        Assert.assertEquals(1, param1.getValue().length);
+        Assert.assertEquals(query, param1.getValue()[0]);
+        Assert.assertTrue(StringUtils.isBlank(param1.getKey()));
+    }
+}

Propchange: jmeter/trunk/test/src/org/apache/jmeter/protocol/http/visualizers/RequestViewHTTPTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1728009&r1=1728008&r2=1728009&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml (original)
+++ jmeter/trunk/xdocs/changes.xml Mon Feb  1 21:22:33 2016
@@ -255,6 +255,7 @@ Summary
 <ul>
 <li><bug>58033</bug>SampleResultConverter should note that it cannot record non-TEXT data</li>
 <li><bug>58845</bug>Request http view doesn't display all the parameters. Contributed by Benoit Wiart (benoit dot wiart at gmail.com)</li>
+<li><bug>58413</bug>ViewResultsTree : Request HTTP Renderer does not show correctly parameters that contain ampersand (&amp;). Contributed by Benoit Wiart (benoit dot wiart at gmail.com)</li>
 </ul>
 
 <h3>Timers, Assertions, Config, Pre- &amp; Post-Processors</h3>