Author: pmouawad
Date: Sun Apr 30 20:41:59 2017
New Revision: 1793276

URL: http://svn.apache.org/viewvc?rev=1793276&view=rev
Log:
Bug 61056 - HTTP : Support brotli decoding
Bugzilla Id: 61056

Added:
    jmeter/trunk/licenses/bin/dec-0.1.1.txt   (with props)
Modified:
    jmeter/trunk/build.properties
    jmeter/trunk/build.xml
    jmeter/trunk/lib/   (props changed)
    jmeter/trunk/lib/aareadme.txt
    jmeter/trunk/res/maven/ApacheJMeter_parent.pom
    
jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java
    jmeter/trunk/xdocs/changes.xml

Modified: jmeter/trunk/build.properties
URL: 
http://svn.apache.org/viewvc/jmeter/trunk/build.properties?rev=1793276&r1=1793275&r2=1793276&view=diff
==============================================================================
--- jmeter/trunk/build.properties (original)
+++ jmeter/trunk/build.properties Sun Apr 30 20:41:59 2017
@@ -80,6 +80,11 @@ bcpkix.jar                  = bcpkix-jdk
 bcpkix.loc                  = 
${maven2.repo}/org/bouncycastle/bcpkix-jdk15on/${bcprov.version}
 bcpkix.md5                  = cb025ef84fb991e14fdf62f6bef7be53
 
+brotli-dec.version          = 0.1.1
+brotli-dec.jar              = dec-${brotli-dec.version}.jar
+brotli-dec.loc              = 
${maven2.repo}/org/brotli/dec/${brotli-dec.version}
+brotli-dec.md5              = 8bb5a4369b73e923bb51fbf099a40f60
+
 caffeine.version            = 2.4.0
 caffeine.jar                = caffeine-${caffeine.version}.jar
 caffeine.loc                = 
${maven2.repo}/com/github/ben-manes/caffeine/caffeine/${caffeine.version}

Modified: jmeter/trunk/build.xml
URL: 
http://svn.apache.org/viewvc/jmeter/trunk/build.xml?rev=1793276&r1=1793275&r2=1793276&view=diff
==============================================================================
--- jmeter/trunk/build.xml (original)
+++ jmeter/trunk/build.xml Sun Apr 30 20:41:59 2017
@@ -385,6 +385,7 @@
     <include name="${lib.dir}/${apache-bsf.jar}"/>
     <include name="${lib.dir}/${asm.jar}"/>
     <include name="${lib.dir}/${beanshell.jar}"/>
+    <include name="${lib.dir}/${brotli-dec.jar}"/>
     <include name="${lib.dir}/${caffeine.jar}"/>
     <include name="${lib.dir}/${commons-codec.jar}"/>
     <include name="${lib.dir}/${commons-collections.jar}"/>
@@ -465,6 +466,7 @@
     <pathelement location="${lib.dir}/${apache-bsf.jar}"/>
     <pathelement location="${lib.dir}/${asm.jar}"/>
     <pathelement location="${lib.dir}/${beanshell.jar}"/>
+    <pathelement location="${lib.dir}/${brotli-dec.jar}"/>
     <pathelement location="${lib.dir}/${caffeine.jar}"/>
     <pathelement location="${lib.dir}/${commons-codec.jar}"/>
     <pathelement location="${lib.dir}/${commons-collections.jar}"/>
@@ -3108,6 +3110,7 @@ run JMeter unless all the JMeter jars ar
     <process_jarfile jarname="bcprov" dest.dir="${lib.api}"/>
     <process_jarfile jarname="bcpkix" dest.dir="${lib.api}"/>
     <process_jarfile jarname="beanshell"/>
+    <process_jarfile jarname="brotli-dec"/>
     <process_jarfile jarname="caffeine"/>
     <process_jarfile jarname="commons-codec"/>
     <process_jarfile jarname="commons-collections"/>

Propchange: jmeter/trunk/lib/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Sun Apr 30 20:41:59 2017
@@ -6,6 +6,7 @@ asm-5.2.jar
 bsf-2.4.0.jar
 bsh-2.0b5.jar
 bshclient.jar
+dec-0.1.1.jar
 caffeine-2.4.0.jar
 commons-codec-1.10.jar
 commons-collections-3.2.2.jar
@@ -22,7 +23,7 @@ dnsjava-2.1.8.jar
 freemarker-2.3.23.jar
 hamcrest-core-1.3.jar
 geronimo*.jar
-groovy-all-2.4.10.jar
+groovy-all-2.4.11.jar
 httpasyncclient-4.1.3.jar
 httpclient-4.5.3.jar
 httpcore-4.4.6.jar

Modified: jmeter/trunk/lib/aareadme.txt
URL: 
http://svn.apache.org/viewvc/jmeter/trunk/lib/aareadme.txt?rev=1793276&r1=1793275&r2=1793276&view=diff
==============================================================================
--- jmeter/trunk/lib/aareadme.txt (original)
+++ jmeter/trunk/lib/aareadme.txt Sun Apr 30 20:41:59 2017
@@ -30,6 +30,11 @@ bsh-2.0b5.jar (org.bsh)
 -------------
 - BeanShell test elements
 
+dec-0.1.1 (org.brotli.dec)
+-----------------
+https://github.com/google/brotli/tree/master/java/org/brotli
+- Used by HTTP4 HC Impl for brotli decoding
+
 caffeine 2.4.0
 -----------------
 https://github.com/ben-manes/caffeine/

Added: jmeter/trunk/licenses/bin/dec-0.1.1.txt
URL: 
http://svn.apache.org/viewvc/jmeter/trunk/licenses/bin/dec-0.1.1.txt?rev=1793276&view=auto
==============================================================================
--- jmeter/trunk/licenses/bin/dec-0.1.1.txt (added)
+++ jmeter/trunk/licenses/bin/dec-0.1.1.txt Sun Apr 30 20:41:59 2017
@@ -0,0 +1,19 @@
+Copyright (c) 2009, 2010, 2013-2016 by the Brotli Authors.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
\ No newline at end of file

Propchange: jmeter/trunk/licenses/bin/dec-0.1.1.txt
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jmeter/trunk/licenses/bin/dec-0.1.1.txt
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: jmeter/trunk/res/maven/ApacheJMeter_parent.pom
URL: 
http://svn.apache.org/viewvc/jmeter/trunk/res/maven/ApacheJMeter_parent.pom?rev=1793276&r1=1793275&r2=1793276&view=diff
==============================================================================
--- jmeter/trunk/res/maven/ApacheJMeter_parent.pom (original)
+++ jmeter/trunk/res/maven/ApacheJMeter_parent.pom Sun Apr 30 20:41:59 2017
@@ -59,6 +59,7 @@ under the License.
       <bcmail.version>1.49</bcmail.version>
       <bcprov.version>1.49</bcprov.version>
       <bcpkix.version>1.49</bcpkix.version>
+      <dec.version>0.1.1</dec.version>
       <caffeine.version>2.4.0</caffeine.version>
       <commons-codec.version>1.10</commons-codec.version>
       <commons-collections.version>3.2.2</commons-collections.version>
@@ -153,6 +154,11 @@ under the License.
         <version>${bcpkix.version}</version>
       </dependency>
       <dependency>
+        <groupId>org.brotli</groupId>
+        <artifactId>dec</artifactId>
+        <version>${dec.version}</version>
+      </dependency>
+      <dependency>
       <groupId>com.github.ben-manes.caffeine</groupId>
         <artifactId>caffeine</artifactId>
         <version>${caffeine.version}</version>

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=1793276&r1=1793275&r2=1793276&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
 Sun Apr 30 20:41:59 2017
@@ -37,6 +37,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.concurrent.TimeUnit;
 import java.util.regex.Pattern;
+import java.util.zip.GZIPInputStream;
 
 import javax.security.auth.Subject;
 
@@ -64,6 +65,8 @@ import org.apache.http.client.Credential
 import org.apache.http.client.HttpRequestRetryHandler;
 import org.apache.http.client.config.CookieSpecs;
 import org.apache.http.client.config.RequestConfig;
+import org.apache.http.client.entity.DeflateInputStream;
+import org.apache.http.client.entity.InputStreamFactory;
 import org.apache.http.client.entity.UrlEncodedFormEntity;
 import org.apache.http.client.methods.CloseableHttpResponse;
 import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
@@ -79,6 +82,9 @@ import org.apache.http.client.methods.Ht
 import org.apache.http.client.params.ClientPNames;
 import org.apache.http.client.protocol.HttpClientContext;
 import org.apache.http.client.protocol.ResponseContentEncoding;
+import org.apache.http.config.Lookup;
+import org.apache.http.config.Registry;
+import org.apache.http.config.RegistryBuilder;
 import org.apache.http.conn.ConnectionKeepAliveStrategy;
 import org.apache.http.conn.DnsResolver;
 import org.apache.http.conn.params.ConnRoutePNames;
@@ -139,6 +145,7 @@ import org.apache.jmeter.util.JMeterUtil
 import org.apache.jmeter.util.JsseSSLManager;
 import org.apache.jmeter.util.SSLManager;
 import org.apache.jorphan.util.JOrphanUtils;
+import org.brotli.dec.BrotliInputStream;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -151,6 +158,28 @@ public class HTTPHC4Impl extends HTTPHCA
     private static final int MAX_BODY_RETAIN_SIZE = 
JMeterUtils.getPropDefault("httpclient4.max_body_retain_size", 32 * 1024);
 
     private static final Logger log = 
LoggerFactory.getLogger(HTTPHC4Impl.class);
+    
+    private final static InputStreamFactory GZIP = new InputStreamFactory() {
+        @Override
+        public InputStream create(final InputStream instream) throws 
IOException {
+            return new GZIPInputStream(instream);
+        }
+    };
+
+    private final static InputStreamFactory DEFLATE = new InputStreamFactory() 
{
+        @Override
+        public InputStream create(final InputStream instream) throws 
IOException {
+            return new DeflateInputStream(instream);
+        }
+
+    };
+    
+    private final static InputStreamFactory BROTLI = new InputStreamFactory() {
+        @Override
+        public InputStream create(final InputStream instream) throws 
IOException {
+            return new BrotliInputStream(instream);
+        }
+    };
 
     /** retry count to be used (default 0); 0 = disable retries */
     private static final int RETRY_COUNT = 
JMeterUtils.getPropDefault("httpclient4.retrycount", 0);
@@ -216,7 +245,7 @@ public class HTTPHC4Impl extends HTTPHCA
      * that HC core {@link ResponseContentEncoding} removes after uncompressing
      * See Bug 59401
      */
-    private static final HttpResponseInterceptor RESPONSE_CONTENT_ENCODING = 
new ResponseContentEncoding() {
+    private static final HttpResponseInterceptor RESPONSE_CONTENT_ENCODING = 
new ResponseContentEncoding(createLookupRegistry()) {
         @Override
         public void process(HttpResponse response, HttpContext context)
                 throws HttpException, IOException {
@@ -311,6 +340,20 @@ public class HTTPHC4Impl extends HTTPHCA
     }
     
     /**
+     * Customize to plug Brotli
+     * @return {@link Lookup}
+     */
+    private static Lookup<InputStreamFactory> createLookupRegistry() {
+        Registry<InputStreamFactory> registry =
+                RegistryBuilder.<InputStreamFactory>create()
+                .register("gzip", GZIP)
+                .register("br", BROTLI)
+                .register("x-gzip", GZIP)
+                .register("deflate", DEFLATE).build();
+        return registry;
+    }
+
+    /**
      * Implementation that allows GET method to have a body
      */
     public static final class HttpGetWithEntity extends 
HttpEntityEnclosingRequestBase {

Modified: jmeter/trunk/xdocs/changes.xml
URL: 
http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1793276&r1=1793275&r2=1793276&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml [utf-8] (original)
+++ jmeter/trunk/xdocs/changes.xml [utf-8] Sun Apr 30 20:41:59 2017
@@ -86,6 +86,7 @@ Summary
 
 <h3>HTTP Samplers and Test Script Recorder</h3>
 <ul>
+    <li><bug>61056</bug>HTTP : Support brotli decoding</li>
 </ul>
 
 <h3>Other samplers</h3>


Reply via email to