Details
-
Type:
New Feature
-
Status:
Closed
-
Priority:
Minor
-
Resolution: Duplicate
-
Affects Version/s: 1.1.1
-
Fix Version/s: None
-
Component/s: Core
-
Labels:None
-
Number of attachments :
Description
This issue is a continuation of http://jira.codehaus.org/browse/XFIRE-444; it was for 1.1 and now this is for 1.1.1.
Added optional gzip content encoding support to CommonsHttpMessageSender.
To enable response compression set the property CommonsHttpMessageSender.GZIP_RESPONSE 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.
To enable request compression set the property CommonsHttpMessageSender.GZIP_REQUEST to Boolean true. When enabled all requests will have the Content-Encoding header set to 'gzip' and the content will be compressed. There is no negotiation with the server to ensure that it supports this.
I tested this with a pre-release of 1.6 http://sourceforge.net/projects/pjl-comp-filter with added request compression support, a formal release is expected within a week or so.
Dan, you mentioned unit tests. Do you see the need to add gzip support to the stand alone server in order to test this?
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 1672)
+++ E:/work/eclipseworkspace/xfire/xfire-core/src/main/org/codehaus/xfire/transport/http/CommonsHttpMessageSender.java (working copy)
@@ -3,9 +3,13 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.zip.GZIPInputStream;
+import java.util.zip.GZIPOutputStream;
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;
@@ -19,6 +23,7 @@
import org.apache.commons.httpclient.params.HttpClientParams;
import org.codehaus.xfire.MessageContext;
import org.codehaus.xfire.XFireException;
+import org.codehaus.xfire.XFireRuntimeException;
import org.codehaus.xfire.attachments.Attachments;
import org.codehaus.xfire.attachments.JavaMailAttachments;
import org.codehaus.xfire.attachments.SimpleAttachment;
@@ -45,6 +50,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 =
@@ -53,6 +60,10 @@
public static final String HTTP_PROXY_PORT = "http.proxyPort";
public static final String HTTP_STATE = "httpClient.httpstate";
public static final String HTTP_CLIENT = "httpClient";
+ /** Request GZIP encoded responses. */
+ public static final String GZIP_RESPONSE = "gzip.response";
+ /** GZIP the requests. */
+ public static final String GZIP_REQUEST = "gzip.requests";
private InputStream msgIs;
@@ -141,6 +152,22 @@
{
postMethod.setRequestHeader("Content-Type", HttpChannel.getSoapMimeType(getMessage(), true));
}
+ Object o = context.getContextualProperty(GZIP_RESPONSE);
+ if(null != o)
+ {
+ if(((Boolean)o).booleanValue())
+ {
+ postMethod.setRequestHeader("Accept-Encoding", GZIP);
+ }
+ }
+ o = context.getContextualProperty(GZIP_REQUEST);
+ if(null != o)
+ {
+ if(((Boolean)o).booleanValue())
+ {
+ postMethod.setRequestHeader("Content-Encoding", GZIP);
+ }
+ }
}
public void send()
@@ -193,16 +220,34 @@
OutMessage message = getMessage();
MessageContext context = getMessageContext();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
+
+ OutputStream os = bos;
+ boolean bGZIP = false;
+ Object o = context.getContextualProperty(GZIP_REQUEST);
+ if(null != o)
+ {
+ if(((Boolean)o).booleanValue())
+ {
+ bGZIP = true;
+ GZIPOutputStream gzOut = new GZIPOutputStream(bos);
+ os = gzOut;
+ }
+ }
Attachments atts = message.getAttachments();
if (atts != null)
{
- atts.write(bos);
+ atts.write(os);
}
else
{
- HttpChannel.writeWithoutAttachments(context, message, bos);
+ HttpChannel.writeWithoutAttachments(context, message, os);
}
+ if(bGZIP)
+ {
+ ((GZIPOutputStream)os).finish();
+ }
+ os.close();
return new ByteArrayRequestEntity(bos.toByteArray());
}
@@ -211,7 +256,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
+ {
+ throw new XFireRuntimeException("Response contains Content-Encoding '" + hce.getValue() + "', which is not the requested type of '" + GZIP + "'.");
+ }
+ }
+ else
+ {
+ in = postMethod.getResponseBodyAsStream();
+ }
if (ct.toLowerCase().indexOf("multipart/related") != -1)
{
Attachments atts = new StreamedAttachments(in, ct);
Some confusion over not being able to switch versions of the original issue. closing so we can keep on working on
XFIRE-444