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 2013/02/04 21:19:37 UTC

svn commit: r1442330 - in /jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http: sampler/HTTPHC3Impl.java sampler/HTTPHC4Impl.java util/ConversionUtils.java

Author: pmouawad
Date: Mon Feb  4 20:19:36 2013
New Revision: 1442330

URL: http://svn.apache.org/viewvc?rev=1442330&view=rev
Log:
Bug 54482 - HC fails to follow redirects with non-encoded chars
Apply fix to HTTPHC3Impl
Factor out sanitize code in ConversionUtils
Bugzilla Id: 54482

Modified:
    jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC3Impl.java
    jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java
    jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/util/ConversionUtils.java

Modified: jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC3Impl.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC3Impl.java?rev=1442330&r1=1442329&r2=1442330&view=diff
==============================================================================
--- jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC3Impl.java (original)
+++ jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC3Impl.java Mon Feb  4 20:19:36 2013
@@ -23,6 +23,8 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.net.InetAddress;
+import java.net.URI;
+import java.net.URISyntaxException;
 import java.net.URL;
 import java.net.URLDecoder;
 import java.util.ArrayList;
@@ -70,6 +72,7 @@ import org.apache.jmeter.protocol.http.c
 import org.apache.jmeter.protocol.http.control.CacheManager;
 import org.apache.jmeter.protocol.http.control.CookieManager;
 import org.apache.jmeter.protocol.http.control.HeaderManager;
+import org.apache.jmeter.protocol.http.util.ConversionUtils;
 import org.apache.jmeter.protocol.http.util.EncoderCache;
 import org.apache.jmeter.protocol.http.util.HTTPArgument;
 import org.apache.jmeter.protocol.http.util.HTTPConstants;
@@ -203,23 +206,25 @@ public class HTTPHC3Impl extends HTTPHCA
 
         res.sampleStart(); // Count the retries as well in the time
         try {
+            URI uri = ConversionUtils.sanitizeUrl(url);
+            String uriAsString = uri.toString();
             // May generate IllegalArgumentException
             if (method.equals(HTTPConstants.POST)) {
-                httpMethod = new PostMethod(urlStr);
+                httpMethod = new PostMethod(uriAsString);
             } else if (method.equals(HTTPConstants.PUT)){
-                httpMethod = new PutMethod(urlStr);
+                httpMethod = new PutMethod(uriAsString);
             } else if (method.equals(HTTPConstants.HEAD)){
-                httpMethod = new HeadMethod(urlStr);
+                httpMethod = new HeadMethod(uriAsString);
             } else if (method.equals(HTTPConstants.TRACE)){
-                httpMethod = new TraceMethod(urlStr);
+                httpMethod = new TraceMethod(uriAsString);
             } else if (method.equals(HTTPConstants.OPTIONS)){
-                httpMethod = new OptionsMethod(urlStr);
+                httpMethod = new OptionsMethod(uriAsString);
             } else if (method.equals(HTTPConstants.DELETE)){
-                httpMethod = new DeleteMethod(urlStr);
+                httpMethod = new DeleteMethod(uriAsString);
             } else if (method.equals(HTTPConstants.GET)){
-                httpMethod = new GetMethod(urlStr);
+                httpMethod = new GetMethod(uriAsString);
             } else if (method.equals(HTTPConstants.PATCH)){
-                httpMethod = new EntityEnclosingMethod(urlStr) {
+                httpMethod = new EntityEnclosingMethod(uriAsString) {
                     @Override
                     public String getName() { // HC3.1 does not have the method
                         return "PATCH";
@@ -346,6 +351,10 @@ public class HTTPHC3Impl extends HTTPHCA
             }
             errorResult(e, res);
             return res;
+        } catch (URISyntaxException e) { // e.g. some kinds of invalid URL
+            res.sampleEnd();
+            errorResult(e, res);
+            return res;
         } catch (IOException e) {
             res.sampleEnd();
             // pick up headers if failed to execute the request

Modified: jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java?rev=1442330&r1=1442329&r2=1442330&view=diff
==============================================================================
--- jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java (original)
+++ jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java Mon Feb  4 20:19:36 2013
@@ -69,7 +69,6 @@ import org.apache.http.client.methods.Ht
 import org.apache.http.client.params.ClientPNames;
 import org.apache.http.client.params.CookiePolicy;
 import org.apache.http.client.protocol.ResponseContentEncoding;
-import org.apache.http.client.utils.URIBuilder;
 import org.apache.http.conn.params.ConnRoutePNames;
 import org.apache.http.conn.scheme.Scheme;
 import org.apache.http.conn.scheme.SchemeRegistry;
@@ -99,6 +98,7 @@ import org.apache.jmeter.protocol.http.c
 import org.apache.jmeter.protocol.http.control.CacheManager;
 import org.apache.jmeter.protocol.http.control.CookieManager;
 import org.apache.jmeter.protocol.http.control.HeaderManager;
+import org.apache.jmeter.protocol.http.util.ConversionUtils;
 import org.apache.jmeter.protocol.http.util.EncoderCache;
 import org.apache.jmeter.protocol.http.util.HC4TrustAllSSLSocketFactory;
 import org.apache.jmeter.protocol.http.util.HTTPArgument;
@@ -232,15 +232,7 @@ public class HTTPHC4Impl extends HTTPHCA
         
         HttpRequestBase httpRequest = null;
         try {
-            URIBuilder builder = 
-                    new URIBuilder()
-                .setScheme(url.getProtocol())
-                .setHost(url.getHost())
-                .setPort(url.getPort())
-                .setUserInfo(url.getUserInfo())
-                .setPath(url.getPath())
-                .setQuery(url.getQuery());
-            URI uri = builder.build();
+            URI uri = ConversionUtils.sanitizeUrl(url);
             if (method.equals(HTTPConstants.POST)) {
                 httpRequest = new HttpPost(uri);
             } else if (method.equals(HTTPConstants.PUT)) {

Modified: jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/util/ConversionUtils.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/util/ConversionUtils.java?rev=1442330&r1=1442329&r2=1442330&view=diff
==============================================================================
--- jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/util/ConversionUtils.java (original)
+++ jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/util/ConversionUtils.java Mon Feb  4 20:19:36 2013
@@ -19,6 +19,8 @@
 package org.apache.jmeter.protocol.http.util;
 
 import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
 import java.net.URL;
 import java.nio.charset.Charset;
 import java.util.ArrayList;
@@ -27,6 +29,7 @@ import java.util.StringTokenizer;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
+import org.apache.http.client.utils.URIBuilder;
 import org.apache.jorphan.util.JOrphanUtils;
 
 // @see TestHTTPUtils for unit tests
@@ -110,6 +113,26 @@ public class ConversionUtils {
         }
         return initial;
     }
+    
+
+    /**
+     * Escapes reserved chars in URL
+     * @param url URL
+     * @return URI
+     * @throws URISyntaxException
+     */
+    public static final URI sanitizeUrl(URL url) throws URISyntaxException {
+        URIBuilder builder = 
+                new URIBuilder()
+            .setScheme(url.getProtocol())
+            .setHost(url.getHost())
+            .setPort(url.getPort())
+            .setUserInfo(url.getUserInfo())
+            .setPath(url.getPath())
+            .setQuery(url.getQuery());
+        URI uri = builder.build();
+        return uri;
+    }
 
     /**
      * collapses absolute or relative URLs containing '/..' converting