You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-commits@axis.apache.org by ve...@apache.org on 2017/01/18 21:23:36 UTC

svn commit: r1779387 - in /axis/axis2/java/core/trunk/modules/transport: http-hc3/src/main/java/org/apache/axis2/transport/http/impl/httpclient3/ http/src/org/apache/axis2/transport/http/ http/src/org/apache/axis2/transport/http/impl/httpclient4/

Author: veithen
Date: Wed Jan 18 21:23:36 2017
New Revision: 1779387

URL: http://svn.apache.org/viewvc?rev=1779387&view=rev
Log:
Streamline the GZIP request compression handling in the HTTP transport:
- Move shared code to HTTPSender.
- Have a single place to decide whether GZIP is enabled or not.
- Allow GZIP compression even if chunking is disabled (AXIS2-5052).
- Use Axiom's Blob API to store the request content when chunking is disabled.

Modified:
    axis/axis2/java/core/trunk/modules/transport/http-hc3/src/main/java/org/apache/axis2/transport/http/impl/httpclient3/RequestImpl.java
    axis/axis2/java/core/trunk/modules/transport/http/src/org/apache/axis2/transport/http/AxisRequestEntity.java
    axis/axis2/java/core/trunk/modules/transport/http/src/org/apache/axis2/transport/http/HTTPSender.java
    axis/axis2/java/core/trunk/modules/transport/http/src/org/apache/axis2/transport/http/impl/httpclient4/RequestImpl.java

Modified: axis/axis2/java/core/trunk/modules/transport/http-hc3/src/main/java/org/apache/axis2/transport/http/impl/httpclient3/RequestImpl.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/transport/http-hc3/src/main/java/org/apache/axis2/transport/http/impl/httpclient3/RequestImpl.java?rev=1779387&r1=1779386&r2=1779387&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/transport/http-hc3/src/main/java/org/apache/axis2/transport/http/impl/httpclient3/RequestImpl.java (original)
+++ axis/axis2/java/core/trunk/modules/transport/http-hc3/src/main/java/org/apache/axis2/transport/http/impl/httpclient3/RequestImpl.java Wed Jan 18 21:23:36 2017
@@ -148,11 +148,6 @@ final class RequestImpl implements Reque
                     HTTPConstants.COMPRESSION_GZIP);
         }
 
-        if (msgContext.isPropertyTrue(HTTPConstants.MC_GZIP_REQUEST)) {
-            method.addRequestHeader(HTTPConstants.HEADER_CONTENT_ENCODING,
-                    HTTPConstants.COMPRESSION_GZIP);
-        }
-
         if (msgContext.getProperty(HTTPConstants.HTTP_METHOD_PARAMS) != null) {
             HttpMethodParams params = (HttpMethodParams) msgContext
                     .getProperty(HTTPConstants.HTTP_METHOD_PARAMS);

Modified: axis/axis2/java/core/trunk/modules/transport/http/src/org/apache/axis2/transport/http/AxisRequestEntity.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/transport/http/src/org/apache/axis2/transport/http/AxisRequestEntity.java?rev=1779387&r1=1779386&r2=1779387&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/transport/http/src/org/apache/axis2/transport/http/AxisRequestEntity.java (original)
+++ axis/axis2/java/core/trunk/modules/transport/http/src/org/apache/axis2/transport/http/AxisRequestEntity.java Wed Jan 18 21:23:36 2017
@@ -19,13 +19,13 @@
 
 package org.apache.axis2.transport.http;
 
+import org.apache.axiom.blob.Blobs;
+import org.apache.axiom.blob.MemoryBlob;
 import org.apache.axiom.om.OMOutputFormat;
 import org.apache.axis2.AxisFault;
 import org.apache.axis2.context.MessageContext;
 import org.apache.axis2.transport.MessageFormatter;
-import org.apache.axis2.util.JavaUtils;
 
-import javax.xml.stream.FactoryConfigurationError;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.util.zip.GZIPOutputStream;
@@ -39,10 +39,12 @@ public final class AxisRequestEntity  {
     private MessageFormatter messageFormatter;
 
     private final boolean chunked;
+    
+    private final boolean gzip;
 
     private MessageContext messageContext;
 
-    private byte[] bytes;
+    private final MemoryBlob content;
 
     private final boolean preserve;
 
@@ -55,16 +57,30 @@ public final class AxisRequestEntity  {
      * message formatter object.
      *
      * @param messageFormatter
+     * @throws AxisFault 
      */
     AxisRequestEntity(MessageFormatter messageFormatter,
                       MessageContext msgContext, OMOutputFormat format, String contentType,
-                      boolean chunked, boolean preserve) {
+                      boolean chunked, boolean gzip, boolean preserve) throws AxisFault {
         this.messageFormatter = messageFormatter;
         this.messageContext = msgContext;
         this.chunked = chunked;
+        this.gzip = gzip;
         this.preserve = preserve;
         this.format = format;
         this.contentType = contentType;
+        if (chunked) {
+            content = null;
+        } else {
+            content = Blobs.createMemoryBlob();
+            OutputStream out = content.getOutputStream();
+            try {
+                internalWriteRequest(out);
+                out.close();
+            } catch (IOException ex) {
+                throw AxisFault.makeFault(ex);
+            }
+        }
     }
 
     public boolean isRepeatable() {
@@ -75,25 +91,23 @@ public final class AxisRequestEntity  {
     }
 
     public void writeRequest(OutputStream outStream) throws IOException {
-        Object gzip = messageContext.getOptions().getProperty(HTTPConstants.MC_GZIP_REQUEST);
-        if (gzip != null && JavaUtils.isTrueExplicitly(gzip) && chunked) {
+        if (chunked) {
+            internalWriteRequest(outStream);
+        } else {
+            content.writeTo(outStream);
+        }
+    }
+    
+    private void internalWriteRequest(OutputStream outStream) throws IOException {
+        if (gzip) {
             outStream = new GZIPOutputStream(outStream);
         }
         try {
-            if (chunked) {
-                messageFormatter.writeTo(messageContext, format, outStream, preserve);
-            } else {
-                if (bytes == null) {
-                    bytes = messageFormatter.getBytes(messageContext, format);
-                }
-                outStream.write(bytes);
-            }
-            if (outStream instanceof GZIPOutputStream) {
+            messageFormatter.writeTo(messageContext, format, outStream, preserve);
+            if (gzip) {
                 ((GZIPOutputStream) outStream).finish();
             }
             outStream.flush();
-        } catch (FactoryConfigurationError e) {
-            throw AxisFault.makeFault(e);
         } catch (IOException e) {
             throw AxisFault.makeFault(e);
         }
@@ -103,15 +117,9 @@ public final class AxisRequestEntity  {
     public long getContentLength() {
         if (chunked) {
             return -1;
+        } else {
+            return content.getSize();
         }
-        if (bytes == null) {
-            try {
-                bytes = messageFormatter.getBytes(messageContext, format);
-            } catch (AxisFault e) {
-                return -1;
-            }
-        }
-        return bytes.length;
     }
 
     public String getContentType() {

Modified: axis/axis2/java/core/trunk/modules/transport/http/src/org/apache/axis2/transport/http/HTTPSender.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/transport/http/src/org/apache/axis2/transport/http/HTTPSender.java?rev=1779387&r1=1779386&r2=1779387&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/transport/http/src/org/apache/axis2/transport/http/HTTPSender.java (original)
+++ axis/axis2/java/core/trunk/modules/transport/http/src/org/apache/axis2/transport/http/HTTPSender.java Wed Jan 18 21:23:36 2017
@@ -94,13 +94,16 @@ public abstract class HTTPSender extends
         }
 
         AxisRequestEntity requestEntity;
+        boolean gzip;
         if (Constants.Configuration.HTTP_METHOD_GET.equalsIgnoreCase(httpMethod)
                 || Constants.Configuration.HTTP_METHOD_DELETE.equalsIgnoreCase(httpMethod)) {
             requestEntity = null;
+            gzip = false;
         } else if (Constants.Configuration.HTTP_METHOD_POST.equalsIgnoreCase(httpMethod)
                 || Constants.Configuration.HTTP_METHOD_PUT.equalsIgnoreCase(httpMethod)) {
+            gzip = msgContext.isPropertyTrue(HTTPConstants.MC_GZIP_REQUEST);
             requestEntity = new AxisRequestEntity(messageFormatter, msgContext, format,
-                    contentType, chunked, authenticator != null && authenticator.isAllowedRetry());
+                    contentType, chunked, gzip, authenticator != null && authenticator.isAllowedRetry());
         } else {
             throw new AxisFault("Unsupported HTTP method " + httpMethod);
         }
@@ -130,6 +133,11 @@ public abstract class HTTPSender extends
             request.setHeader(HTTPConstants.HEADER_SOAP_ACTION, soapAction);
         }
 
+        if (gzip) {
+            request.setHeader(HTTPConstants.HEADER_CONTENT_ENCODING,
+                    HTTPConstants.COMPRESSION_GZIP);
+        }
+        
         // set the custom headers, if available
         addCustomHeaders(msgContext, request);
         

Modified: axis/axis2/java/core/trunk/modules/transport/http/src/org/apache/axis2/transport/http/impl/httpclient4/RequestImpl.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/transport/http/src/org/apache/axis2/transport/http/impl/httpclient4/RequestImpl.java?rev=1779387&r1=1779386&r2=1779387&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/transport/http/src/org/apache/axis2/transport/http/impl/httpclient4/RequestImpl.java (original)
+++ axis/axis2/java/core/trunk/modules/transport/http/src/org/apache/axis2/transport/http/impl/httpclient4/RequestImpl.java Wed Jan 18 21:23:36 2017
@@ -154,11 +154,6 @@ final class RequestImpl implements Reque
                              HTTPConstants.COMPRESSION_GZIP);
         }
 
-        if (msgContext.isPropertyTrue(HTTPConstants.MC_GZIP_REQUEST)) {
-            method.addHeader(HTTPConstants.HEADER_CONTENT_ENCODING,
-                             HTTPConstants.COMPRESSION_GZIP);
-        }
-
         if (msgContext.getProperty(HTTPConstants.HTTP_METHOD_PARAMS) != null) {
             HttpParams params = (HttpParams) msgContext
                     .getProperty(HTTPConstants.HTTP_METHOD_PARAMS);