1
0
mirror of https://github.com/moparisthebest/davmail synced 2024-12-13 11:12:22 -05:00

EWS: implement gzip encoding on response

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1705 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2011-06-17 09:17:31 +00:00
parent 0f8153d8a5
commit 63fdfb111c
3 changed files with 27 additions and 15 deletions

View File

@ -1997,7 +1997,7 @@ public class DavExchangeSession extends ExchangeSession {
InputStream inputStream = null;
try {
DavGatewayHttpClientFacade.executeGetMethod(httpClient, method, true);
if (isGzipEncoded(method)) {
if (DavGatewayHttpClientFacade.isGzipEncoded(method)) {
inputStream = (new GZIPInputStream(method.getResponseBodyAsStream()));
} else {
inputStream = method.getResponseBodyAsStream();
@ -2425,18 +2425,6 @@ public class DavExchangeSession extends ExchangeSession {
}
}
protected boolean isGzipEncoded(HttpMethod method) {
Header[] contentEncodingHeaders = method.getResponseHeaders("Content-Encoding");
if (contentEncodingHeaders != null) {
for (Header header : contentEncodingHeaders) {
if ("gzip".equals(header.getValue())) {
return true;
}
}
}
return false;
}
// wrong hostname fix flag
protected boolean restoreHostName;
@ -2568,7 +2556,7 @@ public class DavExchangeSession extends ExchangeSession {
InputStream inputStream;
try {
DavGatewayHttpClientFacade.executeGetMethod(httpClient, method, true);
if (isGzipEncoded(method)) {
if (DavGatewayHttpClientFacade.isGzipEncoded(method)) {
inputStream = new GZIPInputStream(method.getResponseBodyAsStream());
} else {
inputStream = method.getResponseBodyAsStream();

View File

@ -19,6 +19,7 @@
package davmail.exchange.ews;
import davmail.exchange.XMLStreamUtil;
import davmail.http.DavGatewayHttpClientFacade;
import davmail.util.StringUtil;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.httpclient.Header;
@ -35,6 +36,7 @@ import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import java.io.*;
import java.util.*;
import java.util.zip.GZIPInputStream;
/**
* EWS SOAP method.
@ -102,6 +104,7 @@ public abstract class EWSMethod extends PostMethod {
this.itemType = itemType;
this.methodName = methodName;
this.responseCollectionName = responseCollectionName;
setRequestHeader("Accept-Encoding", "gzip");
setRequestEntity(new RequestEntity() {
byte[] content;
@ -988,7 +991,11 @@ public abstract class EWSMethod extends PostMethod {
Header contentTypeHeader = getResponseHeader("Content-Type");
if (contentTypeHeader != null && "text/xml; charset=utf-8".equals(contentTypeHeader.getValue())) {
try {
processResponseStream(getResponseBodyAsStream());
if (DavGatewayHttpClientFacade.isGzipEncoded(this)) {
processResponseStream(new GZIPInputStream(getResponseBodyAsStream()));
} else {
processResponseStream(getResponseBodyAsStream());
}
} catch (IOException e) {
LOGGER.error("Error while parsing soap response: " + e, e);
}

View File

@ -663,6 +663,23 @@ public final class DavGatewayHttpClientFacade {
}
}
/**
* Test if the method response is gzip encoded
* @param method http method
* @return true if response is gzip encoded
*/
public static boolean isGzipEncoded(HttpMethod method) {
Header[] contentEncodingHeaders = method.getResponseHeaders("Content-Encoding");
if (contentEncodingHeaders != null) {
for (Header header : contentEncodingHeaders) {
if ("gzip".equals(header.getValue())) {
return true;
}
}
}
return false;
}
/**
* Stop HttpConnectionManager.
*/