You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by di...@apache.org on 2006/03/29 23:17:29 UTC
svn commit: r389892 - in
/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2:
transport/http/ util/
Author: dims
Date: Wed Mar 29 13:17:26 2006
New Revision: 389892
URL: http://svn.apache.org/viewcvs?rev=389892&view=rev
Log:
Port gzip support from Axis1.X, with this check in you can specify the accept gzip flag to signal the server that we can understand a gzip response
stub._getServiceClient().getOptions().setProperty(HTTPConstants.MC_ACCEPT_GZIP, Boolean.TRUE);
TODO:
add support to *send* GZIP requests.
Modified:
webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/AbstractHTTPSender.java
webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/CommonsHTTPTransportSender.java
webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/HTTPConstants.java
webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/SOAPOverHTTPSender.java
webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/util/Utils.java
Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/AbstractHTTPSender.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/AbstractHTTPSender.java?rev=389892&r1=389891&r2=389892&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/AbstractHTTPSender.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/AbstractHTTPSender.java Wed Mar 29 13:17:26 2006
@@ -5,6 +5,7 @@
import org.apache.axiom.om.OMOutputFormat;
import org.apache.axis2.AxisFault;
import org.apache.axis2.Constants;
+import org.apache.axis2.util.Utils;
import org.apache.axis2.context.MessageContext;
import org.apache.axis2.context.OperationContext;
import org.apache.axis2.description.Parameter;
@@ -36,6 +37,7 @@
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Iterator;
+import java.util.zip.GZIPInputStream;
public abstract class AbstractHTTPSender {
protected static final String ANONYMOUS = "anonymous";
@@ -230,6 +232,21 @@
InputStream in = httpMethod.getResponseBodyAsStream();
+ Header contentEncoding =
+ httpMethod.getResponseHeader(HTTPConstants.HEADER_CONTENT_ENCODING);
+ if (contentEncoding != null) {
+ if (contentEncoding.getValue().
+ equalsIgnoreCase(HTTPConstants.COMPRESSION_GZIP)) {
+ in =
+ new GZIPInputStream(in);
+ } else {
+ throw new AxisFault("HTTP :"
+ + "unsupported content-encoding of '"
+ + contentEncoding.getValue()
+ + "' found");
+ }
+ }
+
if (in == null) {
throw new AxisFault(
Messages.getMessage("canNotBeNull", "InputStream"));
@@ -485,7 +502,7 @@
} else {
httpClient = new HttpClient();
}
-
+
// Get the timeout values set in the runtime
getTimeoutValues(msgContext);
@@ -500,6 +517,17 @@
protected void executeMethod(HttpClient httpClient, MessageContext msgContext, URL url, HttpMethod method) throws IOException {
HostConfiguration config = this.getHostConfiguration(httpClient, msgContext, url);
msgContext.setProperty(HTTPConstants.HTTP_METHOD, method);
+
+ // add compression headers if needed
+ if (Utils.isExplicitlyTrue(msgContext, HTTPConstants.MC_ACCEPT_GZIP)) {
+ method.addRequestHeader(HTTPConstants.HEADER_ACCEPT_ENCODING,
+ HTTPConstants.COMPRESSION_GZIP);
+ }
+ if (Utils.isExplicitlyTrue(msgContext, HTTPConstants.MC_GZIP_REQUEST)) {
+ method.addRequestHeader(HTTPConstants.HEADER_CONTENT_ENCODING,
+ HTTPConstants.COMPRESSION_GZIP);
+ }
+
httpClient.executeMethod(config, method);
}
}
Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/CommonsHTTPTransportSender.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/CommonsHTTPTransportSender.java?rev=389892&r1=389891&r2=389892&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/CommonsHTTPTransportSender.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/CommonsHTTPTransportSender.java Wed Mar 29 13:17:26 2006
@@ -200,17 +200,7 @@
if (epr != null) {
if (!epr.getAddress().equals(AddressingConstants.Final.WSA_NONE_URI)) {
-// try {
- writeMessageWithCommons(msgContext, epr, dataOut, format);
-// } catch (AxisFault axisFault) {
-// // if the given to epr is an unreachable one, we should try to send it
-// // over the output stream. See AddressingInterop.test1260(http://www.w3.org/2002/ws/addr/testsuite/testcases/#test1260)
-// if (axisFault != null && axisFault.getCause() instanceof IOException) {
-// sendUsingOutputStream(msgContext, format, dataOut);
-// } else {
-// throw axisFault;
-// }
-// }
+ writeMessageWithCommons(msgContext, epr, dataOut, format);
}
} else {
sendUsingOutputStream(msgContext, format, dataOut);
Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/HTTPConstants.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/HTTPConstants.java?rev=389892&r1=389891&r2=389892&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/HTTPConstants.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/HTTPConstants.java Wed Mar 29 13:17:26 2006
@@ -421,7 +421,25 @@
* Field HTTP_METHOD
*/
public static final String HTTP_METHOD = "HTTP_METHOD";
-
+
+ public static final String HEADER_ACCEPT_ENCODING = "Accept-Encoding";
+ public static final String HEADER_CONTENT_ENCODING = "Content-Encoding";
+
+ public static final String COMPRESSION_GZIP = "gzip";
+
+ /**
+ * If you want the HTTP sender to indicate that it can accept a gziped
+ * response, set this message context property to true. The sender will
+ * automatically unzip the response if its gzipped.
+ */
+ public static final String MC_ACCEPT_GZIP = "transport.http.acceptGzip";
+
+ /**
+ * by default the HTTP request body is not compressed. set this message
+ * context property to true to have the request body gzip compressed.
+ */
+ public static final String MC_GZIP_REQUEST = "transport.http.gzipRequest";
+
/**
* Method getBytes.
*
Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/SOAPOverHTTPSender.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/SOAPOverHTTPSender.java?rev=389892&r1=389891&r2=389892&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/SOAPOverHTTPSender.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/SOAPOverHTTPSender.java Wed Mar 29 13:17:26 2006
@@ -9,11 +9,9 @@
import org.apache.axis2.context.MessageContext;
import org.apache.axis2.i18n.Messages;
import org.apache.commons.httpclient.Header;
-import org.apache.commons.httpclient.HostConfiguration;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.HttpVersion;
-import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.RequestEntity;
Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/util/Utils.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/util/Utils.java?rev=389892&r1=389891&r2=389892&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/util/Utils.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/util/Utils.java Wed Mar 29 13:17:26 2006
@@ -339,4 +339,12 @@
}
messageContext.setProperty(SOAP12Constants.SOAP_FAULT_CODE_LOCAL_NAME, soapFaultCode);
}
+
+ public static boolean isExplicitlyTrue(MessageContext messageContext, String propertyName) {
+ Boolean flag = (Boolean) messageContext.getProperty(propertyName);
+ if(flag != null) {
+ return flag.booleanValue();
+ }
+ return false;
+ }
}