You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2009/05/28 11:33:23 UTC
svn commit: r779508 - in /camel/branches/camel-1.x: ./
components/camel-http/src/main/java/org/apache/camel/component/http/
components/camel-http/src/main/java/org/apache/camel/component/http/helper/
components/camel-http/src/test/java/org/apache/camel...
Author: davsclaus
Date: Thu May 28 09:33:23 2009
New Revision: 779508
URL: http://svn.apache.org/viewvc?rev=779508&view=rev
Log:
Merged revisions 779489 via svnmerge from
https://svn.apache.org/repos/asf/camel/trunk
........
r779489 | davsclaus | 2009-05-28 10:58:14 +0200 (Thu, 28 May 2009) | 1 line
CAMEL-1651: Fixed gzip content encoding only being applied if really needed. Polished the code as well.
........
Removed:
camel/branches/camel-1.x/components/camel-http/src/test/java/org/apache/camel/component/http/GZIPHelperTest.java
Modified:
camel/branches/camel-1.x/ (props changed)
camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java
camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/HttpConverter.java
camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java
camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/RequestEntityConverter.java
camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/helper/GZIPHelper.java
camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/helper/LoadingByteArrayOutputStream.java
camel/branches/camel-1.x/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyContentTypeTest.java
camel/branches/camel-1.x/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyImageFileTest.java
Propchange: camel/branches/camel-1.x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu May 28 09:33:23 2009
@@ -1 +1 @@
-/camel/trunk:736980,739733,739904,740251,740295,740306,740596,740663,741848,742231,742705,742739,742854,742856,742898,742906,743613,743762,743773,743920,743959-743960,744123,745105,745367,745541,745751,745826,745978,746269,746872,746895,746962,747258,747678-747704,748392,748436,748821,749563-749564,749574,749628-749629,749936,749956,750017,750334,750396,750761,750796,752068,752117,752418,752751-752755,752764-752773,752956,753087,753101,753175,755136,755487,756313,756348,756870,756939,757636,757693,757743,757865,758539,758563,758600,758617,758692,758990,759362,759453,759887,759931,760003,760890,760909,760937,761194,761536,761583,761607,762047,762633,762650,762935,763095,763484,763551,765154,765686,765729,765743,765824,766016,766289,766584,766588,766590,766602,766673,767403,767824,768342,769239,769346,769368,769434,770172,770906,771303,773193,773446,773781,774192,774383,774658-774659,776198,776289,776504,776975,778102,778689-778701,779121,779143
+/camel/trunk:736980,739733,739904,740251,740295,740306,740596,740663,741848,742231,742705,742739,742854,742856,742898,742906,743613,743762,743773,743920,743959-743960,744123,745105,745367,745541,745751,745826,745978,746269,746872,746895,746962,747258,747678-747704,748392,748436,748821,749563-749564,749574,749628-749629,749936,749956,750017,750334,750396,750761,750796,752068,752117,752418,752751-752755,752764-752773,752956,753087,753101,753175,755136,755487,756313,756348,756870,756939,757636,757693,757743,757865,758539,758563,758600,758617,758692,758990,759362,759453,759887,759931,760003,760890,760909,760937,761194,761536,761583,761607,762047,762633,762650,762935,763095,763484,763551,765154,765686,765729,765743,765824,766016,766289,766584,766588,766590,766602,766673,767403,767824,768342,769239,769346,769368,769434,770172,770906,771303,773193,773446,773781,774192,774383,774658-774659,776198,776289,776504,776975,778102,778689-778701,779121,779143,779489
Propchange: camel/branches/camel-1.x/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.
Modified: camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java?rev=779508&r1=779507&r2=779508&view=diff
==============================================================================
--- camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java (original)
+++ camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java Thu May 28 09:33:23 2009
@@ -16,20 +16,22 @@
*/
package org.apache.camel.component.http;
-import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Enumeration;
import java.util.Map;
-
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import org.apache.camel.InvalidTypeException;
import org.apache.camel.Message;
import org.apache.camel.component.http.helper.GZIPHelper;
import org.apache.camel.spi.HeaderFilterStrategy;
+import org.apache.camel.util.ExchangeHelper;
+import org.apache.camel.util.IOHelper;
+import org.apache.camel.util.ObjectHelper;
/**
* Binding between {@link HttpMessage} and {@link HttpServletResponse}.
@@ -102,8 +104,8 @@
}
private void copyProtocolHeaders(Message request, Message response) {
- if (request.getHeader(GZIPHelper.CONTENT_ENCODING) != null) {
- String contentEncoding = request.getHeader(GZIPHelper.CONTENT_ENCODING, String.class);
+ if (request.getHeader(GZIPHelper.CONTENT_ENCODING) != null) {
+ String contentEncoding = request.getHeader(GZIPHelper.CONTENT_ENCODING, String.class);
response.setHeader(GZIPHelper.CONTENT_ENCODING, contentEncoding);
}
}
@@ -144,47 +146,55 @@
}
}
- // write the body.
if (message.getBody() != null) {
- // try to stream the body since that would be the most efficient
- InputStream is = message.getBody(InputStream.class);
- if (is != null) {
- ServletOutputStream os = response.getOutputStream();
- try {
- ByteArrayOutputStream initialArray = new ByteArrayOutputStream();
- int c;
- while ((c = is.read()) >= 0) {
- initialArray.write(c);
- }
- byte[] processedArray = processReponseContent(message, initialArray.toByteArray(), response);
- os.write(processedArray);
- // set content length before we flush
- // Here the processedArray length is used instead of the
- // length of the characters in written to the initialArray
- // because if the method processReponseContent compresses
- // the data, the processedArray may contain a different length
- response.setContentLength(processedArray.length);
- os.flush();
- } finally {
- os.close();
- is.close();
- }
+ if (GZIPHelper.isGzip(message)) {
+ doWriteGZIPResponse(message, response);
} else {
- String data = message.getBody(String.class);
- if (data != null) {
- // set content length before we write data
- response.setContentLength(data.length());
- response.getWriter().print(data);
- response.getWriter().flush();
- }
+ doWriteDirectResponse(message, response);
}
+ }
+ }
+ protected void doWriteDirectResponse(Message message, HttpServletResponse response) throws IOException {
+ InputStream is = message.getBody(InputStream.class);
+ if (is != null) {
+ ServletOutputStream os = response.getOutputStream();
+ try {
+ // copy directly from input stream to output stream
+ IOHelper.copy(is, os);
+ } finally {
+ os.close();
+ is.close();
+ }
+ } else {
+ // not convertable as a stream so try as a String
+ String data = message.getBody(String.class);
+ if (data != null) {
+ // set content length before we write data
+ response.setContentLength(data.length());
+ response.getWriter().print(data);
+ response.getWriter().flush();
+ }
}
}
-
- protected byte[] processReponseContent(Message message, byte[] array, HttpServletResponse response) throws IOException {
- String gzipEncoding = message.getHeader(GZIPHelper.CONTENT_ENCODING, String.class);
- return GZIPHelper.compressArrayIfGZIPRequested(gzipEncoding, array, response);
+
+ protected void doWriteGZIPResponse(Message message, HttpServletResponse response) throws IOException {
+ byte[] bytes;
+ try {
+ bytes = ExchangeHelper.convertToMandatoryType(message.getExchange(), byte[].class, message.getBody());
+ } catch (InvalidTypeException e) {
+ throw ObjectHelper.wrapRuntimeCamelException(e);
+ }
+
+ byte[] data = GZIPHelper.compressGZIP(bytes);
+ ServletOutputStream os = response.getOutputStream();
+ try {
+ response.setContentLength(data.length);
+ os.write(data);
+ os.flush();
+ } finally {
+ os.close();
+ }
}
public Object parseBody(HttpMessage httpMessage) throws IOException {
@@ -197,7 +207,8 @@
if (isUseReaderForPayload()) {
return request.getReader();
} else {
- return GZIPHelper.getInputStream(request);
+ // otherwise use input stream
+ return HttpConverter.toInputStream(request);
}
}
Modified: camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/HttpConverter.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/HttpConverter.java?rev=779508&r1=779507&r2=779508&view=diff
==============================================================================
--- camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/HttpConverter.java (original)
+++ camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/HttpConverter.java Thu May 28 09:33:23 2009
@@ -19,7 +19,6 @@
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
-
import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServletRequest;
@@ -33,10 +32,13 @@
* @version $Revision$
*/
@Converter
-public class HttpConverter {
+public final class HttpConverter {
+
+ private HttpConverter() {
+ }
@Converter
- public HttpServletRequest toServletRequest(HttpMessage message) {
+ public static HttpServletRequest toServletRequest(HttpMessage message) {
if (message == null) {
return null;
}
@@ -44,7 +46,7 @@
}
@Converter
- public ServletInputStream toServletInputStream(HttpMessage message) throws IOException {
+ public static ServletInputStream toServletInputStream(HttpMessage message) throws IOException {
HttpServletRequest request = toServletRequest(message);
if (request != null) {
return request.getInputStream();
@@ -53,16 +55,12 @@
}
@Converter
- public InputStream toInputStream(HttpMessage message) throws Exception {
- HttpServletRequest request = toServletRequest(message);
- if (request != null) {
- return GZIPHelper.getInputStream(request);
- }
- return null;
+ public static InputStream toInputStream(HttpMessage message) throws Exception {
+ return toInputStream(toServletRequest(message));
}
@Converter
- public BufferedReader toReader(HttpMessage message) throws IOException {
+ public static BufferedReader toReader(HttpMessage message) throws IOException {
HttpServletRequest request = toServletRequest(message);
if (request != null) {
return request.getReader();
@@ -70,4 +68,13 @@
return null;
}
+ @Converter
+ public static InputStream toInputStream(HttpServletRequest request) throws IOException {
+ if (request == null) {
+ return null;
+ }
+ String contentEncoding = request.getHeader(GZIPHelper.CONTENT_ENCODING);
+ return GZIPHelper.toGZIPInputStream(contentEncoding, request.getInputStream());
+ }
+
}
Modified: camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java?rev=779508&r1=779507&r2=779508&view=diff
==============================================================================
--- camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java (original)
+++ camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java Thu May 28 09:33:23 2009
@@ -29,12 +29,11 @@
import org.apache.camel.Producer;
import org.apache.camel.RuntimeCamelException;
import org.apache.camel.component.http.helper.GZIPHelper;
-import org.apache.camel.component.http.helper.LoadingByteArrayOutputStream;
import org.apache.camel.converter.stream.CachedOutputStream;
import org.apache.camel.impl.DefaultProducer;
import org.apache.camel.spi.HeaderFilterStrategy;
import org.apache.camel.util.ExchangeHelper;
-import org.apache.camel.util.MessageHelper;
+import org.apache.camel.util.IOHelper;
import org.apache.camel.util.ObjectHelper;
import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HttpClient;
@@ -42,7 +41,6 @@
import org.apache.commons.httpclient.methods.EntityEnclosingMethod;
import org.apache.commons.httpclient.methods.RequestEntity;
import org.apache.commons.httpclient.methods.StringRequestEntity;
-import org.apache.commons.io.IOUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -154,17 +152,23 @@
* @throws IOException can be thrown
*/
protected static InputStream extractResponseBody(HttpMethod method, Exchange exchange) throws IOException {
+ InputStream is = method.getResponseBodyAsStream();
+ if (is == null) {
+ return null;
+ }
+
+ Header header = method.getRequestHeader(GZIPHelper.CONTENT_ENCODING);
+ String contentEncoding = header != null ? header.getValue() : null;
+
+ is = GZIPHelper.toGZIPInputStream(contentEncoding, is);
+ return doExtractResponseBody(is, exchange);
+ }
+
+ private static InputStream doExtractResponseBody(InputStream is, Exchange exchange) throws IOException {
CachedOutputStream cos = null;
- InputStream is = null;
try {
cos = new CachedOutputStream(exchange.getContext().getProperties());
- is = GZIPHelper.getInputStream(method);
- // in case of no response stream
- if (is == null) {
- return null;
- }
- IOUtils.copy(is, cos);
- cos.flush();
+ IOHelper.copy(is, cos);
return cos.getInputStream();
} finally {
ObjectHelper.close(is, "Extracting response body", LOG);
@@ -211,7 +215,7 @@
}
if (methodToUse.isEntityEnclosing()) {
((EntityEnclosingMethod)method).setRequestEntity(requestEntity);
- if (requestEntity.getContentType() == null) {
+ if (requestEntity != null && requestEntity.getContentType() == null) {
LOG.warn("Missing the ContentType in the request entity for the URI " + uri + ". The method is " + method);
}
}
Modified: camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/RequestEntityConverter.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/RequestEntityConverter.java?rev=779508&r1=779507&r2=779508&view=diff
==============================================================================
--- camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/RequestEntityConverter.java (original)
+++ camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/RequestEntityConverter.java Thu May 28 09:33:23 2009
@@ -16,68 +16,64 @@
*/
package org.apache.camel.component.http;
-import java.io.BufferedReader;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
+import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
-import java.util.zip.GZIPOutputStream;
-
-import javax.servlet.ServletInputStream;
import org.apache.camel.Converter;
import org.apache.camel.Exchange;
-import org.apache.camel.Message;
import org.apache.camel.component.http.helper.GZIPHelper;
import org.apache.camel.util.ExchangeHelper;
import org.apache.commons.httpclient.methods.InputStreamRequestEntity;
import org.apache.commons.httpclient.methods.RequestEntity;
-
/**
* Some converter methods to make it easier to convert the body to RequestEntity types.
*
*/
-
@Converter
public class RequestEntityConverter {
@Converter
public RequestEntity toRequestEntity(ByteBuffer buffer, Exchange exchange) throws Exception {
- return new InputStreamRequestEntity(
- GZIPHelper.toGZIPInputStreamIfRequested(
- exchange.getIn().getHeader(GZIPHelper.CONTENT_ENCODING, String.class),
- buffer.array()), ExchangeHelper.getContentType(exchange));
+ return asRequestEntity(buffer.array(), exchange);
}
@Converter
- public RequestEntity toRequestEntity(byte[] array, Exchange exchange) throws Exception {
- return new InputStreamRequestEntity(
- GZIPHelper.toGZIPInputStreamIfRequested(
- exchange.getIn().getHeader(GZIPHelper.CONTENT_ENCODING, String.class),
- array), ExchangeHelper.getContentType(exchange));
+ public RequestEntity toRequestEntity(byte[] data, Exchange exchange) throws Exception {
+ return asRequestEntity(data, exchange);
}
@Converter
public RequestEntity toRequestEntity(InputStream inStream, Exchange exchange) throws Exception {
- return new InputStreamRequestEntity(
- GZIPHelper.getGZIPWrappedInputStream(
- exchange.getIn().getHeader(GZIPHelper.CONTENT_ENCODING, String.class),
- inStream), ExchangeHelper.getContentType(exchange));
+ return asRequestEntity(inStream, exchange);
}
@Converter
public RequestEntity toRequestEntity(String str, Exchange exchange) throws Exception {
- if (GZIPHelper.containsGzip(exchange.getIn().getHeader(GZIPHelper.CONTENT_ENCODING, String.class))) {
- return new InputStreamRequestEntity(
- GZIPHelper.toGZIPInputStreamIfRequested(
- exchange.getIn().getHeader(GZIPHelper.CONTENT_ENCODING, String.class),
- str.getBytes()), ExchangeHelper.getContentType(exchange));
+ if (GZIPHelper.isGzip(exchange.getIn())) {
+ byte[] data = exchange.getContext().getTypeConverter().convertTo(byte[].class, str);
+ return asRequestEntity(data, exchange);
} else {
// will use the default StringRequestEntity
return null;
}
}
+
+ private RequestEntity asRequestEntity(InputStream in, Exchange exchange) throws IOException {
+ return new InputStreamRequestEntity(
+ GZIPHelper.toGZIPInputStream(
+ exchange.getIn().getHeader(GZIPHelper.CONTENT_ENCODING, String.class),
+ in), ExchangeHelper.getContentType(exchange));
+ }
+
+ private RequestEntity asRequestEntity(byte[] data, Exchange exchange) throws Exception {
+ return new InputStreamRequestEntity(
+ GZIPHelper.toGZIPInputStream(
+ exchange.getIn().getHeader(GZIPHelper.CONTENT_ENCODING, String.class),
+ data), ExchangeHelper.getContentType(exchange));
+ }
+
}
Modified: camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/helper/GZIPHelper.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/helper/GZIPHelper.java?rev=779508&r1=779507&r2=779508&view=diff
==============================================================================
--- camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/helper/GZIPHelper.java (original)
+++ camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/helper/GZIPHelper.java Thu May 28 09:33:23 2009
@@ -16,116 +16,98 @@
*/
package org.apache.camel.component.http.helper;
-import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
-
-import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.camel.Message;
-import org.apache.commons.httpclient.Header;
-import org.apache.commons.httpclient.HttpMethod;
+import org.apache.camel.util.ObjectHelper;
/**
- *
- * Helper/Utility class to help wrapping
- * content into GZIP Input/Output Streams.
- *
- *
+ * Helper class to help wrapping content into GZIP input and output streams.
*/
public final class GZIPHelper {
public static final String CONTENT_ENCODING = "Content-Encoding";
public static final String GZIP = "gzip";
-
+
// No need for instatiating, so avoid it.
- private GZIPHelper() { }
+ private GZIPHelper() {
+ }
+ /**
+ * @deprecated set the header using {@link Message#setHeader(String, Object)}
+ */
public static void setGZIPMessageHeader(Message message) {
message.setHeader(CONTENT_ENCODING, GZIP);
}
-
+
+ /**
+ * @deprecated set the header using {@link HttpServletResponse#setHeader(String, String)}
+ */
public static void setGZIPContentEncoding(HttpServletResponse response) {
response.setHeader(CONTENT_ENCODING, GZIP);
}
- // --------- Methods To Decompress ----------
-
- public static InputStream getInputStream(HttpMethod method)
- throws IOException {
-
- Header header = method.getRequestHeader(CONTENT_ENCODING);
- String contentEncoding = header != null ? header.getValue() : null;
- return getGZIPWrappedInputStream(contentEncoding,
- method.getResponseBodyAsStream());
- }
-
- public static InputStream getInputStream(HttpServletRequest request) throws IOException {
- InputStream dataStream = request.getInputStream();
- String contentEncoding = request.getHeader(CONTENT_ENCODING);
- return getGZIPWrappedInputStream(contentEncoding, dataStream);
- }
-
- public static InputStream getGZIPWrappedInputStream(String gzipEncoding,
- InputStream inStream) throws IOException {
- if (containsGzip(gzipEncoding)) {
- return new GZIPInputStream(new BufferedInputStream(inStream));
+ public static InputStream toGZIPInputStream(String contentEncoding, InputStream in) throws IOException {
+ if (isGzip(contentEncoding)) {
+ return new GZIPInputStream(in);
} else {
- return inStream;
+ return in;
}
}
- public static InputStream toGZIPInputStreamIfRequested(String gzipEncoding, byte[] array)
- throws Exception {
- if (containsGzip(gzipEncoding)) {
- // GZip byte array content
- ByteArrayOutputStream outputByteArray = new ByteArrayOutputStream();
- GZIPOutputStream gzipOutputStream = new GZIPOutputStream(
- outputByteArray);
- gzipOutputStream.write(array);
- gzipOutputStream.close();
- return new ByteArrayInputStream(outputByteArray.toByteArray());
+ public static InputStream toGZIPInputStream(String contentEncoding, byte[] data) throws Exception {
+ if (isGzip(contentEncoding)) {
+ ByteArrayOutputStream os = null;
+ GZIPOutputStream gzip = null;
+ try {
+ os = new ByteArrayOutputStream();
+ gzip = new GZIPOutputStream(os);
+ gzip.write(data);
+ gzip.finish();
+ return new ByteArrayInputStream(os.toByteArray());
+ } finally {
+ ObjectHelper.close(gzip, "gzip", null);
+ ObjectHelper.close(os, "byte array", null);
+ }
} else {
- return new ByteArrayInputStream(array);
+ return new ByteArrayInputStream(data);
}
}
- // -------------- Methods To Compress --------------
-
- public static byte[] compressArrayIfGZIPRequested(String gzipEncoding,
- byte[] array) throws IOException {
- if (containsGzip(gzipEncoding)) {
- return getGZIPWrappedOutputStream(array).toByteArray();
- } else {
- return array;
+ public static byte[] compressGZIP(byte[] data) throws IOException {
+ ByteArrayOutputStream os = new ByteArrayOutputStream();
+ GZIPOutputStream gzip = new GZIPOutputStream(os);
+ try {
+ gzip.write(data);
+ gzip.finish();
+ return os.toByteArray();
+ } finally {
+ gzip.close();
+ os.close();
}
}
-
- public static byte[] compressArrayIfGZIPRequested(String gzipEncoding,
- byte[] array, HttpServletResponse response) throws IOException {
- if (containsGzip(gzipEncoding)) {
- return getGZIPWrappedOutputStream(array).toByteArray();
- } else {
- return array;
- }
+
+ public static boolean isGzip(Message message) {
+ return isGzip(message.getHeader(CONTENT_ENCODING, String.class));
}
-
- public static ByteArrayOutputStream getGZIPWrappedOutputStream(byte[] array) throws IOException {
- ByteArrayOutputStream compressed = new ByteArrayOutputStream();
- GZIPOutputStream gzout = new GZIPOutputStream(compressed);
- gzout.write(array);
- gzout.close();
- return compressed;
+
+ public static boolean isGzip(String header) {
+ return header != null && header.toLowerCase().contains("gzip");
}
+ /**
+ * @deprecated use isGzip
+ */
public static boolean containsGzip(String str) {
return str != null && str.toLowerCase().indexOf(GZIP) >= 0;
}
+
}
Modified: camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/helper/LoadingByteArrayOutputStream.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/helper/LoadingByteArrayOutputStream.java?rev=779508&r1=779507&r2=779508&view=diff
==============================================================================
--- camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/helper/LoadingByteArrayOutputStream.java (original)
+++ camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/helper/LoadingByteArrayOutputStream.java Thu May 28 09:33:23 2009
@@ -33,11 +33,13 @@
* is using.
*/
public class LoadingByteArrayOutputStream extends ByteArrayOutputStream {
+
public LoadingByteArrayOutputStream() {
super(1024);
}
- public LoadingByteArrayOutputStream(int i) {
- super(i);
+
+ public LoadingByteArrayOutputStream(int size) {
+ super(size);
}
public ByteArrayInputStream createInputStream() {
Modified: camel/branches/camel-1.x/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyContentTypeTest.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyContentTypeTest.java?rev=779508&r1=779507&r2=779508&view=diff
==============================================================================
--- camel/branches/camel-1.x/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyContentTypeTest.java (original)
+++ camel/branches/camel-1.x/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyContentTypeTest.java Thu May 28 09:33:23 2009
@@ -34,7 +34,7 @@
exchange.getIn().setHeader("user", "Claus");
exchange.getIn().setHeader("Content-Type", "text/xml");
if (usingGZip) {
- GZIPHelper.setGZIPMessageHeader(exchange.getIn());
+ exchange.getIn().setHeader(GZIPHelper.CONTENT_ENCODING, "gzip");
}
template.send(endpoint, exchange);
Modified: camel/branches/camel-1.x/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyImageFileTest.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyImageFileTest.java?rev=779508&r1=779507&r2=779508&view=diff
==============================================================================
--- camel/branches/camel-1.x/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyImageFileTest.java (original)
+++ camel/branches/camel-1.x/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyImageFileTest.java Thu May 28 09:33:23 2009
@@ -34,7 +34,7 @@
Endpoint endpoint = context.getEndpoint("http://localhost:9080/myapp/myservice");
Exchange exchange = endpoint.createExchange();
if (usingGZip) {
- GZIPHelper.setGZIPMessageHeader(exchange.getIn());
+ exchange.getIn().setHeader(GZIPHelper.CONTENT_ENCODING, "gzip");
}
template.send(endpoint, exchange);