History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: XFIRE-467
Type: New Feature New Feature
Status: Closed Closed
Resolution: Duplicate
Priority: Minor Minor
Assignee: Dan Diephouse
Reporter: Gum Shoe
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
XFire

CLONE -Added optional gzip content encoding support to CommonsHttpMessageSender.

Created: 19/Jun/06 04:47 PM   Updated: 19/Jun/06 04:47 PM
Component/s: Core
Affects Version/s: 1.1
Fix Version/s: 1.2-RC

Time Tracking:
Not Specified


 Description  « Hide
Added optional gzip content encoding support to CommonsHttpMessageSender. To enable set the property CommonsHttpMessageSender.GZIP_ENABLED to Boolean true. When enabled all requests will have the header Accept-Encoding set to 'gzip' and responses with or without Content-Encoding set to 'gzip' will be handled appropriately. Outgoing requests will not be compressed.

The patch:

Index: E:/work/eclipseworkspace/xfire/xfire-core/src/main/org/codehaus/xfire/transport/http/CommonsHttpMessageSender.java
===================================================================
--- E:/work/eclipseworkspace/xfire/xfire-core/src/main/org/codehaus/xfire/transport/http/CommonsHttpMessageSender.java	(revision 1590)
+++ E:/work/eclipseworkspace/xfire/xfire-core/src/main/org/codehaus/xfire/transport/http/CommonsHttpMessageSender.java	(working copy)
@@ -3,9 +3,11 @@
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.util.zip.GZIPInputStream;
 
 import javax.activation.DataHandler;
 
+import org.apache.commons.httpclient.Header;
 import org.apache.commons.httpclient.HttpClient;
 import org.apache.commons.httpclient.HttpException;
 import org.apache.commons.httpclient.HttpState;
@@ -46,6 +48,8 @@
     private HttpClient client;
 
     private HttpState state;
+    
+    private static final String GZIP = "gzip";
 
     public static final String HTTP_CLIENT_PARAMS = "httpClient.params";
     public static final String USER_AGENT =  
@@ -54,6 +58,7 @@
     public static final String HTTP_PROXY_PORT = "http.proxyPort";
     public static final String HTTP_STATE = "httpClient.httpstate";
     public static final String HTTP_CLIENT = "httpClient";
+    public static final String GZIP_ENABLED = "gzip.enabled";
     
     public CommonsHttpMessageSender(OutMessage message, MessageContext context)
     {
@@ -140,6 +145,14 @@
         {
             postMethod.setRequestHeader("Content-Type", HttpChannel.getSoapMimeType(getMessage()));
         }
+        Object o = context.getContextualProperty(GZIP_ENABLED);
+        if(null != o)
+        {
+	          if(((Boolean)o).booleanValue())
+	          {
+		            postMethod.setRequestHeader("Accept-Encoding", GZIP);
+	          }
+        }
     }
 
     public void send()
@@ -215,7 +228,23 @@
         throws IOException
     {
         String ct = postMethod.getResponseHeader("Content-Type").getValue();
-        InputStream in = postMethod.getResponseBodyAsStream();
+        Header hce = postMethod.getResponseHeader("Content-Encoding");
+        InputStream in = null;
+        if(null != hce)
+        {
+	          if(hce.getValue().equals(GZIP))
+	          {
+		            in = new GZIPInputStream(postMethod.getResponseBodyAsStream());
+	          }
+	          else
+	          {
+		            //better hope this never happens
+	          }
+        }
+        else
+        {
+            in = postMethod.getResponseBodyAsStream();
+        }
         if (ct.toLowerCase().indexOf("multipart/related") != -1)
         {
             Attachments atts = new StreamedAttachments(in, ct);


 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Gum Shoe - 19/Jun/06 04:47 PM
Tried to clone in order to change the affected version to 1.1.1 but no luck.