jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pmoua...@apache.org
Subject svn commit: r1416080 - in /jmeter/trunk: src/protocol/http/org/apache/jmeter/protocol/http/proxy/DefaultSamplerCreator.java test/src/org/apache/jmeter/protocol/http/proxy/TestHttpRequestHdr.java xdocs/changes.xml
Date Sat, 01 Dec 2012 23:26:38 GMT
Author: pmouawad
Date: Sat Dec  1 23:26:37 2012
New Revision: 1416080

URL: http://svn.apache.org/viewvc?rev=1416080&view=rev
Log:
Bug 53840 - Proxy Recording : Response message: URLDecoder: Illegal hex characters in escape
(%) pattern - For input string: "" "
Bugzilla Id: 53840

Modified:
    jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/proxy/DefaultSamplerCreator.java
    jmeter/trunk/test/src/org/apache/jmeter/protocol/http/proxy/TestHttpRequestHdr.java
    jmeter/trunk/xdocs/changes.xml

Modified: jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/proxy/DefaultSamplerCreator.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/proxy/DefaultSamplerCreator.java?rev=1416080&r1=1416079&r2=1416080&view=diff
==============================================================================
--- jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/proxy/DefaultSamplerCreator.java
(original)
+++ jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/proxy/DefaultSamplerCreator.java
Sat Dec  1 23:26:37 2012
@@ -20,10 +20,15 @@ package org.apache.jmeter.protocol.http.
 
 import java.io.File;
 import java.io.IOException;
+import java.io.StringReader;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.Map;
 
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.jmeter.protocol.http.config.MultipartUrlConfig;
@@ -37,6 +42,11 @@ import org.apache.jmeter.protocol.http.u
 import org.apache.jmeter.testelement.TestElement;
 import org.apache.jorphan.logging.LoggingManager;
 import org.apache.log.Logger;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+import org.xml.sax.XMLReader;
+import org.xml.sax.helpers.DefaultHandler;
 
 /**
  * Default implementation that handles classical HTTP textual + Multipart requests
@@ -173,7 +183,7 @@ public class DefaultSamplerCreator exten
                 // Set the file uploads
                 sampler.setHTTPFiles(urlConfig.getHTTPFileArgs().asArray());
             // used when postData is pure xml (eg. an xml-rpc call) or for PUT
-            } else if (postData.trim().startsWith("<?") || HTTPConstants.PUT.equals(sampler.getMethod()))
{
+            } else if ((postData.trim().startsWith("<?") || isPotentialXml(postData))
|| HTTPConstants.PUT.equals(sampler.getMethod())) {
                 sampler.addNonEncodedArgument("", postData, "");
             } else if (contentType == null || 
                     (contentType.startsWith(HTTPConstants.APPLICATION_X_WWW_FORM_URLENCODED)
&& 
@@ -202,6 +212,58 @@ public class DefaultSamplerCreator exten
     }
 
     /**
+     * Tries parsing to see if content is xml
+     * @param postData String
+     * @return boolean
+     */
+    private static final boolean isPotentialXml(String postData) {
+        try {
+            SAXParserFactory spf = SAXParserFactory.newInstance();
+            SAXParser saxParser = spf.newSAXParser();
+            XMLReader xmlReader = saxParser.getXMLReader();
+            ErrorDetectionHandler detectionHandler =
+                    new ErrorDetectionHandler();
+            xmlReader.setContentHandler(detectionHandler);
+            xmlReader.parse(new InputSource(new StringReader(postData)));
+            return detectionHandler.isErrorDetected();
+        } catch (ParserConfigurationException e) {
+            return false;
+        } catch (SAXException e) {
+            return false;
+        } catch (IOException e) {
+            return false;
+        }
+    }
+    
+    private static final class ErrorDetectionHandler extends DefaultHandler {
+        private boolean errorDetected = false;
+        public ErrorDetectionHandler() {
+            super();
+        }
+        /* (non-Javadoc)
+         * @see org.xml.sax.helpers.DefaultHandler#error(org.xml.sax.SAXParseException)
+         */
+        @Override
+        public void error(SAXParseException e) throws SAXException {
+            this.errorDetected = true;
+        }
+
+        /* (non-Javadoc)
+         * @see org.xml.sax.helpers.DefaultHandler#fatalError(org.xml.sax.SAXParseException)
+         */
+        @Override
+        public void fatalError(SAXParseException e) throws SAXException {
+            this.errorDetected = true;
+        }
+        /**
+         * @return the errorDetected
+         */
+        public boolean isErrorDetected() {
+            return errorDetected;
+        }
+        
+    }
+    /**
      * Compute sampler name
      * @param sampler {@link HTTPSamplerBase}
      * @param request {@link HttpRequestHdr}

Modified: jmeter/trunk/test/src/org/apache/jmeter/protocol/http/proxy/TestHttpRequestHdr.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jmeter/protocol/http/proxy/TestHttpRequestHdr.java?rev=1416080&r1=1416079&r2=1416080&view=diff
==============================================================================
--- jmeter/trunk/test/src/org/apache/jmeter/protocol/http/proxy/TestHttpRequestHdr.java (original)
+++ jmeter/trunk/test/src/org/apache/jmeter/protocol/http/proxy/TestHttpRequestHdr.java Sat
Dec  1 23:26:37 2012
@@ -136,6 +136,40 @@ public class TestHttpRequestHdr  extends
         arguments = s.getArguments();
         assertEquals(1, arguments.getArgumentCount());
         checkArgument((HTTPArgument)arguments.getArgument(0), "", postBody, postBody, contentEncoding,
false);
+        
+        // A HTTP POST request, with content-type text/plain; charset=UTF-8
+        // The encoding should be picked up from the header we send with the request
+        contentEncoding = "UTF-8";
+        url =  "http://vmdal-hqqa9/retalixhq/GG_Implementation/ScreenEntity/ScreenEntityHTTP.aspx?Action=Save&ET=Vendor&TT=Single&Sid=1347280336092";
+        postBody = "<Action UIStatus=\"2\"><Vendor Id=\"9292\" HOST_ID=\"0\" VENDOR=\"9292\"
TERMS_TYPE=\"No Terms\" TERMS=\"0 %\" AUTO_PRICE=\"Use System Default\" VM_VENDOR_TYPE=\"DSD
Vendor\" ITEM_FORMAT=\"PLU\" COST_ENTRY_SORT=\"UPC/EAN\" VM_REPORT_SORT=\"UPC/EAN\" VM_ORDER_SORT=\"UPC/EAN\"
VM_RECEIVING_SORT=\"UPC/EAN\" VM_MAX_BACK_ORDERS=\"99\" MAX_OPEN_DAYS=\"99\" PAY_BASED_ON=\"System
Cost\" ORDER_COST_DATE=\"Use System Rule\" VM_CONSIDER_FREE=\"False\" VM_SHOW_DETAIL=\"False\"
VM_UPDATE_COST=\"No\" RD_USE_VENDOR_CC=\"False\" BLIND_RECEIVING=\"Default\" EXCLUDE_RECEIVED_COST=\"False\"
PRINT_ITEM_ADJ=\"False\" PRINT_OVERALL_ADJ=\"False\" PRINT_TAX_DETAIL=\"False\" BLOCK_PRICE_VIEW=\"False\"
DELIVERY_STATUS=\"No Delivery\" AUTO_RECEIVE=\"False\" TARGET_GM_FLAG=\"%\" MINIMUM_GM_FLAG=\"%\"
MARGIN_TYPE=\"Gross Margin\" HOLD_REGULAR=\"Default\" HOLD_SPECIALS=\"Default\" TRUSTING_VENDOR=\"False\"
AUTO_ACCEPT=\"All\" EARLY_RCPT_AFFECTS=\"All Costs\" SBT_ELIGIBLE=\"Not eligibl
 e\" SBT_REPORTING_DAY=\"Monday\" AUTO_BALANCE_FLAG=\"$\" DAX_MANAGED=\"False\" CHANGE_ID=\"QA\"
CHANGE_SOURCE=\"Manual Change\" ORIGINAL_SOURCE=\"Manual Change\" RECORD_STATUS=\"Add\" RECORD_STATUS_DATE=\"9/7/2012
8:34:58 AM\" VENDOR_NAME=\"test\" UIStatus=\"2\"/></Action>";
+        testPostRequest = "POST " + url + " HTTP/1.1\r\n"
+                + "x-requested-with: XMLHttpRequest" + "\r\n"
+                + "Accept-Language: en-us" + "\r\n"
+                + "Referer: http://vmdal-hqqa9/retalixhq/GG_Implementation/ScreenEntity/ScreenEntityPage.aspx?ET=Vendor&TT=Single&WM=2&UID=9292&Sid=1347280331908&UITH=Blue&MUID=window_0"
+ "\r\n"
+                + "Accept: */*" + "\r\n"
+                + "Content-Type: application/x-www-form-urlencoded" + "\r\n"
+                + "Accept-Encoding: gzip, deflate" + "\r\n"
+                + "User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0;
SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C;
Tablet PC 2.0)" + "\r\n"
+                + "Host: vmdal-hqqa9" + "\r\n"
+                + "Content-Length: "+ getBodyLength(postBody, contentEncoding) + "\r\n"
+                + "Proxy-Connection: Keep-Alive" + "\r\n"
+                + "Pragma: no-cache" + "\r\n"
+                + "Cookie: RHQ=sid=5aaeb66c-e174-4f4c-9928-83cffcc62150" + "\r\n"
+                + "\r\n"
+                + postBody;
+        // Use null for url to simulate that HttpRequestHdr do not
+        // know the encoding for the page. Specify contentEncoding, so the
+        // request is "sent" using that encoding
+        s = getSamplerForRequest(null, testPostRequest, contentEncoding);
+        assertEquals(HTTPConstants.POST, s.getMethod());
+        assertFalse(s.getDoMultipartPost());
+        // TODO Should this be OK ?
+        //assertEquals(contentEncoding, s.getContentEncoding());
+        // Check arguments
+        // We should have one argument, with the value equal to the post body
+        arguments = s.getArguments();
+        assertEquals(1, arguments.getArgumentCount());
+        checkArgument((HTTPArgument)arguments.getArgument(0), "", postBody, postBody, contentEncoding,
false);
     }
 
     public void testEncodedArguments() throws Exception {

Modified: jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1416080&r1=1416079&r2=1416080&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml (original)
+++ jmeter/trunk/xdocs/changes.xml Sat Dec  1 23:26:37 2012
@@ -113,6 +113,7 @@ It has been removed so now size of these
 <li>Don't log spurious warning messages when using concurrent pool embedded downloads
with Cache Manager or CookieManager</li>
 <li><bugzilla>54057</bugzilla>- Proxy option to set user and password at
startup (-u and -a) not working with HTTPClient 4</li>
 <li><bugzilla>54187</bugzilla> - Request tab does not show headers if request
fails</li>
+<li>Bug 53840 - Proxy Recording : Response message: URLDecoder: Illegal hex characters
in escape (%) pattern - For input string: "" "</li>
 </ul>
 
 <h3>Other Samplers</h3>



Mime
View raw message