Author: ningjiang Date: Tue Feb 10 09:07:49 2009 New Revision: 742898 URL: http://svn.apache.org/viewvc?rev=742898&view=rev Log: CAMEL-1327 applied the patch with thanks to Roberto, also added some unit tests in camel-jetty
Added: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/RequestEntityConverter.java (with props) camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/helper/GZIPHelper.java (with props) camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/GZIPHelperTest.java (with props) Modified: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpConverter.java camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpHeaderFilterStrategy.java camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/ConvertPayloadToInputStreamTest.java camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/ExplicitHttpsRouteTest.java camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpRouteTest.java camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpRouteUsingUrlPostTest.java camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpsRouteTest.java camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyContentTypeTest.java camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyHttpBindingRefTest.java camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyHttpClientOptionsTest.java camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyImageFileTest.java camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyResponseBodyWhenErrorTest.java camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyRouteTest.java Modified: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java?rev=742898&r1=742897&r2=742898&view=diff ============================================================================== --- camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java (original) +++ camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java Tue Feb 10 09:07:49 2009 @@ -16,15 +16,20 @@ */ package org.apache.camel.component.http; +import java.io.ByteArrayOutputStream; +import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; +import java.io.OutputStream; import java.io.PrintWriter; +import java.util.zip.GZIPOutputStream; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.camel.Message; +import org.apache.camel.component.http.helper.GZIPHelper; import org.apache.camel.spi.HeaderFilterStrategy; /** @@ -59,13 +64,22 @@ doWriteExceptionResponse(exchange.getException(), response); } } else { - Message out = exchange.getOut(); + // just copy the protocol relates header + copyProtocolHeaders(exchange.getIn(), exchange.getOut()); + Message out = exchange.getOut(); if (out != null) { doWriteResponse(out, response); } } } + private void copyProtocolHeaders(Message request, Message response) { + if (request.getHeader(GZIPHelper.CONTENT_ENCODING) != null) { + String contentEncoding = request.getHeader(GZIPHelper.CONTENT_ENCODING, String.class); + response.setHeader(GZIPHelper.CONTENT_ENCODING, contentEncoding); + } + } + public void doWriteExceptionResponse(Throwable exception, HttpServletResponse response) throws IOException { response.setStatus(500); // 500 for internal server error response.setContentType("text/plain"); @@ -88,8 +102,8 @@ response.setStatus(code); } // set the content type in the response. - if (message.getHeader("Content-Type") != null) { - String contentType = message.getHeader("Content-Type", String.class); + if (message.getHeader("Content-Type") != null) { + String contentType = message.getHeader("Content-Type", String.class); response.setContentType(contentType); } @@ -106,18 +120,22 @@ if (message.getBody() != null) { // try to stream the body since that would be the most efficient InputStream is = message.getBody(InputStream.class); - int length = 0; if (is != null) { - ServletOutputStream os = null; + ServletOutputStream os = response.getOutputStream(); try { - os = response.getOutputStream(); + ByteArrayOutputStream initialArray = new ByteArrayOutputStream(); int c; while ((c = is.read()) >= 0) { - os.write(c); - length++; + initialArray.write(c); } + byte[] processedArray = processReponseContent(message, initialArray.toByteArray(), response); + os.write(processedArray); // set content length before we flush - response.setContentLength(length); + // 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(); @@ -135,6 +153,11 @@ } } + + 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); + } public Object parseBody(HttpMessage httpMessage) throws IOException { // lets assume the body is a reader Modified: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpConverter.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpConverter.java?rev=742898&r1=742897&r2=742898&view=diff ============================================================================== --- camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpConverter.java (original) +++ camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpConverter.java Tue Feb 10 09:07:49 2009 @@ -18,11 +18,13 @@ import java.io.BufferedReader; import java.io.IOException; +import java.io.InputStream; import javax.servlet.ServletInputStream; import javax.servlet.http.HttpServletRequest; import org.apache.camel.Converter; +import org.apache.camel.component.http.helper.GZIPHelper; /** * Some converter methods making it easy to convert the body of a message to servlet types or to switch between @@ -51,6 +53,15 @@ } @Converter + public InputStream toInputStream(HttpMessage message) throws Exception { + HttpServletRequest request = toServletRequest(message); + if (request != null) { + return GZIPHelper.getInputStream(request); + } + return null; + } + + @Converter public BufferedReader toReader(HttpMessage message) throws IOException { HttpServletRequest request = toServletRequest(message); if (request != null) { Modified: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpHeaderFilterStrategy.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpHeaderFilterStrategy.java?rev=742898&r1=742897&r2=742898&view=diff ============================================================================== --- camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpHeaderFilterStrategy.java (original) +++ camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpHeaderFilterStrategy.java Tue Feb 10 09:07:49 2009 @@ -16,6 +16,7 @@ */ package org.apache.camel.component.http; +import org.apache.camel.component.http.helper.GZIPHelper; import org.apache.camel.impl.DefaultHeaderFilterStrategy; /** @@ -30,6 +31,7 @@ protected void initialize() { getOutFilter().add("content-length"); getOutFilter().add("content-type"); + getOutFilter().add(GZIPHelper.CONTENT_ENCODING); getOutFilter().add(HttpMethods.HTTP_METHOD); getOutFilter().add(HttpProducer.QUERY); getOutFilter().add(HttpProducer.HTTP_RESPONSE_CODE.toLowerCase()); Modified: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java?rev=742898&r1=742897&r2=742898&view=diff ============================================================================== --- camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java (original) +++ camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java Tue Feb 10 09:07:49 2009 @@ -24,6 +24,7 @@ import org.apache.camel.Message; import org.apache.camel.NoTypeConversionAvailableException; 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.impl.DefaultProducer; import org.apache.camel.spi.HeaderFilterStrategy; @@ -146,7 +147,7 @@ InputStream is = null; try { bos = new LoadingByteArrayOutputStream(); - is = method.getResponseBodyAsStream(); + is = GZIPHelper.getInputStream(method); // in case of no response stream if (is == null) { return null; Added: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/RequestEntityConverter.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/RequestEntityConverter.java?rev=742898&view=auto ============================================================================== --- camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/RequestEntityConverter.java (added) +++ camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/RequestEntityConverter.java Tue Feb 10 09:07:49 2009 @@ -0,0 +1,80 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.http; + +import java.io.BufferedReader; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +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.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( + (String) exchange.getIn().getHeader(GZIPHelper.CONTENT_ENCODING), + buffer.array())); + } + + @Converter + public RequestEntity toRequestEntity(byte[] array, Exchange exchange) throws Exception { + return new InputStreamRequestEntity( + GZIPHelper.toGZIPInputStreamIfRequested( + (String) exchange.getIn().getHeader(GZIPHelper.CONTENT_ENCODING), + array)); + } + + @Converter + public RequestEntity toRequestEntity(InputStream inStream, Exchange exchange) throws Exception { + return new InputStreamRequestEntity( + GZIPHelper.getGZIPWrappedInputStream( + (String) exchange.getIn().getHeader(GZIPHelper.CONTENT_ENCODING), + inStream)); + } + + + @Converter + public RequestEntity toRequestEntity(String str, Exchange exchange) throws Exception { + return new InputStreamRequestEntity( + GZIPHelper.toGZIPInputStreamIfRequested( + (String) exchange.getIn().getHeader(GZIPHelper.CONTENT_ENCODING), + str.getBytes())); + } + + +} + Propchange: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/RequestEntityConverter.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/RequestEntityConverter.java ------------------------------------------------------------------------------ svn:keywords = Rev Date Added: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/helper/GZIPHelper.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/helper/GZIPHelper.java?rev=742898&view=auto ============================================================================== --- camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/helper/GZIPHelper.java (added) +++ camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/helper/GZIPHelper.java Tue Feb 10 09:07:49 2009 @@ -0,0 +1,131 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +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; + +/** + * + * Helper/Utility class to help wrapping + * content into GZIP Input/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() { } + + public static void setGZIPMessageHeader(Message message) { + message.setHeader(CONTENT_ENCODING, GZIP); + } + + 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 Exception { + 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)); + } else { + return inStream; + } + } + + 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()); + } else { + return new ByteArrayInputStream(array); + } + } + + // -------------- 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[] compressArrayIfGZIPRequested(String gzipEncoding, + byte[] array, HttpServletResponse response) throws IOException { + if (containsGzip(gzipEncoding)) { + return getGZIPWrappedOutputStream(array).toByteArray(); + } else { + return array; + } + } + + public static ByteArrayOutputStream getGZIPWrappedOutputStream(byte[] array) throws IOException { + ByteArrayOutputStream compressed = new ByteArrayOutputStream(); + GZIPOutputStream gzout = new GZIPOutputStream(compressed); + gzout.write(array); + gzout.close(); + return compressed; + } + + private static boolean containsGzip(String str) { + return str != null && str.toLowerCase().indexOf(GZIP) >= 0; + } + +} Propchange: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/helper/GZIPHelper.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/helper/GZIPHelper.java ------------------------------------------------------------------------------ svn:keywords = Rev Date Added: camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/GZIPHelperTest.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/GZIPHelperTest.java?rev=742898&view=auto ============================================================================== --- camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/GZIPHelperTest.java (added) +++ camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/GZIPHelperTest.java Tue Feb 10 09:07:49 2009 @@ -0,0 +1,98 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.http; + +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 junit.framework.TestCase; + +import org.apache.camel.component.http.helper.GZIPHelper; + +public class GZIPHelperTest extends TestCase { + + public void testGetGZIPWrappedInputStreamTrue() throws Exception { + ByteArrayOutputStream compressed = new ByteArrayOutputStream(); + GZIPOutputStream gzout = new GZIPOutputStream(compressed); + gzout.write(new byte[]{0, 1}); + gzout.close(); + ByteArrayInputStream bai = new ByteArrayInputStream(compressed.toByteArray()); + InputStream inStream = GZIPHelper.getGZIPWrappedInputStream(GZIPHelper.GZIP, bai); + assertNotNull(inStream); + assertTrue("Returned InputStream is not of type GZIPInputStream", inStream instanceof GZIPInputStream); + } + + public void testGetGZIPWrappedInputStreamFalse() throws Exception { + ByteArrayInputStream bai = new ByteArrayInputStream(new byte[]{0, 1}); + InputStream inStream = GZIPHelper.getGZIPWrappedInputStream("other-encoding", bai); + assertNotNull(inStream); + assertFalse("Unexpected Return InputStream type", inStream instanceof GZIPInputStream); + } + + public void testGetInputStreamStringByteArrayTrue() throws Exception { + InputStream inStream = GZIPHelper.toGZIPInputStreamIfRequested(GZIPHelper.GZIP, new byte[]{0, 1}); + assertNotNull(inStream); + try { + new GZIPInputStream(inStream); + } catch (Exception e) { + fail("Returned InpuStream is not GZipped correctly"); + } + } + + public void testGetInputStreamStringByteArrayFalse() throws Exception { + InputStream inStream = GZIPHelper.toGZIPInputStreamIfRequested("other-encoding", new byte[]{0, 1}); + assertNotNull(inStream); + try { + new GZIPInputStream(inStream); + fail("Returned InputStream should not be GZipped!"); + } catch (IOException e) { + // Expected error. + } + } + + public void testCompressArrayIfGZIPRequestedStringByteArrayTrue() throws Exception { + byte[] initialArray = new byte[]{0, 1}; + + ByteArrayOutputStream compressed = new ByteArrayOutputStream(); + GZIPOutputStream gzout = new GZIPOutputStream(compressed); + gzout.write(initialArray); + gzout.close(); + byte[] expectedArray = compressed.toByteArray(); + assertNotNull("Returned expectedArray is null", expectedArray); + + byte[] retArray = GZIPHelper.compressArrayIfGZIPRequested(GZIPHelper.GZIP, initialArray); + assertNotNull("Returned array is null", retArray); + + + assertTrue("Length of returned array is different than expected array.", expectedArray.length == retArray.length); + + for (int i = 0; i < retArray.length; i++) { + assertEquals("Contents of returned array is different thatn expected array", expectedArray[i], retArray[i]); + } + + } + + public void testGetGZIPWrappedOutputStream() throws Exception { + ByteArrayOutputStream arrayOutputStream = GZIPHelper.getGZIPWrappedOutputStream(new byte[]{0, 1}); + assertNotNull(arrayOutputStream); + } + +} Propchange: camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/GZIPHelperTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/GZIPHelperTest.java ------------------------------------------------------------------------------ svn:keywords = Rev Date Modified: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/ConvertPayloadToInputStreamTest.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/ConvertPayloadToInputStreamTest.java?rev=742898&r1=742897&r2=742898&view=diff ============================================================================== --- camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/ConvertPayloadToInputStreamTest.java (original) +++ camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/ConvertPayloadToInputStreamTest.java Tue Feb 10 09:07:49 2009 @@ -40,7 +40,7 @@ MockEndpoint mockEndpoint = getMockEndpoint("mock:result"); mockEndpoint.expectedMessageCount(1); - template.sendBodyAndHeader("http://localhost:8080/test", expectedBody, "Content-Type", "application/xml"); + template.sendBodyAndHeader("http://localhost:9080/test", expectedBody, "Content-Type", "application/xml"); mockEndpoint.assertIsSatisfied(); List<Exchange> list = mockEndpoint.getReceivedExchanges(); @@ -59,7 +59,7 @@ protected RouteBuilder createRouteBuilder() throws Exception { return new RouteBuilder() { public void configure() { - from("jetty:http://localhost:8080/test"). + from("jetty:http://localhost:9080/test"). convertBodyTo(InputStream.class). to("mock:result"); } Modified: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/ExplicitHttpsRouteTest.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/ExplicitHttpsRouteTest.java?rev=742898&r1=742897&r2=742898&view=diff ============================================================================== --- camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/ExplicitHttpsRouteTest.java (original) +++ camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/ExplicitHttpsRouteTest.java Tue Feb 10 09:07:49 2009 @@ -39,14 +39,14 @@ JettyHttpComponent componentJetty = (JettyHttpComponent) context.getComponent("jetty"); componentJetty.setSslSocketConnector(sslSocketConnector); - from("jetty:https://localhost:8080/test").to("mock:a"); + from("jetty:https://localhost:9080/test").to("mock:a"); Processor proc = new Processor() { public void process(Exchange exchange) throws Exception { exchange.getOut(true).setBody("<b>Hello World</b>"); } }; - from("jetty:https://localhost:8080/hello").process(proc); + from("jetty:https://localhost:9080/hello").process(proc); } }; } Modified: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpRouteTest.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpRouteTest.java?rev=742898&r1=742897&r2=742898&view=diff ============================================================================== --- camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpRouteTest.java (original) +++ camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpRouteTest.java Tue Feb 10 09:07:49 2009 @@ -63,7 +63,7 @@ public void testHelloEndpoint() throws Exception { ByteArrayOutputStream os = new ByteArrayOutputStream(); - InputStream is = new URL("http://localhost:8080/hello").openStream(); + InputStream is = new URL("http://localhost:9080/hello").openStream(); int c; while ((c = is.read()) >= 0) { os.write(c); @@ -75,14 +75,14 @@ } protected void invokeHttpEndpoint() throws IOException { - template.sendBodyAndHeader("http://localhost:8080/test", expectedBody, "Content-Type", "application/xml"); + template.sendBodyAndHeader("http://localhost:9080/test", expectedBody, "Content-Type", "application/xml"); } @Override protected RouteBuilder createRouteBuilder() throws Exception { return new RouteBuilder() { public void configure() { - from("jetty:http://localhost:8080/test").to("mock:a"); + from("jetty:http://localhost:9080/test").to("mock:a"); Processor proc = new Processor() { public void process(Exchange exchange) throws Exception { @@ -96,7 +96,7 @@ exchange.getOut(true).setBody("<b>Hello World</b>"); } }; - from("jetty:http://localhost:8080/hello?sessionSupport=true").process(proc); + from("jetty:http://localhost:9080/hello?sessionSupport=true").process(proc); } }; } Modified: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpRouteUsingUrlPostTest.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpRouteUsingUrlPostTest.java?rev=742898&r1=742897&r2=742898&view=diff ============================================================================== --- camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpRouteUsingUrlPostTest.java (original) +++ camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpRouteUsingUrlPostTest.java Tue Feb 10 09:07:49 2009 @@ -31,7 +31,7 @@ public class HttpRouteUsingUrlPostTest extends HttpRouteTest { protected void invokeHttpEndpoint() throws IOException { - URL url = new URL("http://localhost:8080/test"); + URL url = new URL("http://localhost:9080/test"); URLConnection urlConnection = url.openConnection(); urlConnection.setDoInput(true); urlConnection.setDoOutput(true); Modified: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpsRouteTest.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpsRouteTest.java?rev=742898&r1=742897&r2=742898&view=diff ============================================================================== --- camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpsRouteTest.java (original) +++ camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpsRouteTest.java Tue Feb 10 09:07:49 2009 @@ -96,7 +96,7 @@ public void testEndpointWithoutHttps() { MockEndpoint mockEndpoint = resolveMandatoryEndpoint("mock:a", MockEndpoint.class); try { - template.sendBodyAndHeader("jetty:http://localhost:8080/test", expectedBody, "Content-Type", "application/xml"); + template.sendBodyAndHeader("jetty:http://localhost:9080/test", expectedBody, "Content-Type", "application/xml"); fail("expect exception on access to https endpoint via http"); } catch (RuntimeCamelException expected) { } @@ -106,7 +106,7 @@ public void testHelloEndpoint() throws Exception { ByteArrayOutputStream os = new ByteArrayOutputStream(); - InputStream is = new URL("https://localhost:8080/hello").openStream(); + InputStream is = new URL("https://localhost:9080/hello").openStream(); int c; while ((c = is.read()) >= 0) { os.write(c); @@ -119,7 +119,7 @@ public void testHelloEndpointWithoutHttps() throws Exception { try { - new URL("http://localhost:8080/hello").openStream(); + new URL("http://localhost:9080/hello").openStream(); fail("expected SocketException on use ot http"); } catch (SocketException expected) { } @@ -128,7 +128,7 @@ } protected void invokeHttpEndpoint() throws IOException { - template.sendBodyAndHeader("jetty:https://localhost:8080/test", expectedBody, "Content-Type", "application/xml"); + template.sendBodyAndHeader("jetty:https://localhost:9080/test", expectedBody, "Content-Type", "application/xml"); } @Override @@ -142,14 +142,14 @@ URL keyStoreUrl = this.getClass().getClassLoader().getResource("jsse/localhost.ks"); componentJetty.setKeystore(keyStoreUrl.getPath()); - from("jetty:https://localhost:8080/test").to("mock:a"); + from("jetty:https://localhost:9080/test").to("mock:a"); Processor proc = new Processor() { public void process(Exchange exchange) throws Exception { exchange.getOut(true).setBody("<b>Hello World</b>"); } }; - from("jetty:https://localhost:8080/hello").process(proc); + from("jetty:https://localhost:9080/hello").process(proc); } }; } Modified: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyContentTypeTest.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyContentTypeTest.java?rev=742898&r1=742897&r2=742898&view=diff ============================================================================== --- camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyContentTypeTest.java (original) +++ camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyContentTypeTest.java Tue Feb 10 09:07:49 2009 @@ -21,6 +21,7 @@ import org.apache.camel.Exchange; import org.apache.camel.Processor; import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.http.helper.GZIPHelper; /** * Unit test for content-type @@ -28,7 +29,7 @@ public class JettyContentTypeTest extends ContextTestSupport { public void testSameContentType() throws Exception { - Endpoint endpoint = context.getEndpoint("http://localhost:8080/myapp/myservice"); + Endpoint endpoint = context.getEndpoint("http://localhost:9080/myapp/myservice"); Exchange exchange = endpoint.createExchange(); exchange.getIn().setBody("<order>123</order>"); exchange.getIn().setHeader("user", "Claus"); @@ -39,9 +40,24 @@ assertEquals("<order>OK</order>", body); assertOutMessageHeader(exchange, "content-type", "text/xml"); } + + public void testContentTypeWithGZip() throws Exception { + Endpoint endpoint = context.getEndpoint("http://localhost:9080/myapp/myservice"); + Exchange exchange = endpoint.createExchange(); + exchange.getIn().setBody("<order>123</order>"); + exchange.getIn().setHeader("user", "Claus"); + exchange.getIn().setHeader("content-type", "text/xml"); + GZIPHelper.setGZIPMessageHeader(exchange.getIn()); + template.send(endpoint, exchange); + + String body = exchange.getOut().getBody(String.class); + assertEquals("<order>OK</order>", body); + assertOutMessageHeader(exchange, "content-type", "text/xml"); + assertOutMessageHeader(exchange, GZIPHelper.CONTENT_ENCODING, GZIPHelper.GZIP); + } public void testMixedContentType() throws Exception { - Endpoint endpoint = context.getEndpoint("http://localhost:8080/myapp/myservice"); + Endpoint endpoint = context.getEndpoint("http://localhost:9080/myapp/myservice"); Exchange exchange = endpoint.createExchange(); exchange.getIn().setBody("<order>123</order>"); exchange.getIn().setHeader("Content-Type", "text/xml"); @@ -56,7 +72,7 @@ protected RouteBuilder createRouteBuilder() throws Exception { return new RouteBuilder() { public void configure() throws Exception { - from("jetty:http://localhost:8080/myapp/myservice").process(new MyBookService()); + from("jetty:http://localhost:9080/myapp/myservice").process(new MyBookService()); } }; } @@ -64,7 +80,7 @@ public class MyBookService implements Processor { public void process(Exchange exchange) throws Exception { if (exchange.getIn().getHeader("user") != null) { - exchange.getOut().setBody("<order>OK</order>"); + exchange.getOut().setBody("<order>OK</order>"); } else { exchange.getOut().setBody("FAIL"); exchange.getOut().setHeader("Content-Type", "text/plain"); Modified: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyHttpBindingRefTest.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyHttpBindingRefTest.java?rev=742898&r1=742897&r2=742898&view=diff ============================================================================== --- camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyHttpBindingRefTest.java (original) +++ camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyHttpBindingRefTest.java Tue Feb 10 09:07:49 2009 @@ -32,12 +32,12 @@ public class JettyHttpBindingRefTest extends ContextTestSupport { public void testDefaultHttpBinding() throws Exception { - Object out = template.requestBody("http://localhost:8080/myapp/myservice", "Hello World"); + Object out = template.requestBody("http://localhost:9080/myapp/myservice", "Hello World"); assertEquals("Bye World", context.getTypeConverter().convertTo(String.class, out)); } public void testCustomHttpBinding() throws Exception { - Object out = template.requestBody("http://localhost:8081/myapp/myotherservice", "Hello World"); + Object out = template.requestBody("http://localhost:9081/myapp/myotherservice", "Hello World"); assertEquals("Something went wrong but we dont care", context.getTypeConverter().convertTo(String.class, out)); } @@ -56,9 +56,9 @@ public void configure() throws Exception { errorHandler(noErrorHandler()); - from("jetty:http://localhost:8080/myapp/myservice?httpBindingRef=default").transform().constant("Bye World"); + from("jetty:http://localhost:9080/myapp/myservice?httpBindingRef=default").transform().constant("Bye World"); - from("jetty:http://localhost:8081/myapp/myotherservice?httpBindingRef=myownbinder").process(new Processor() { + from("jetty:http://localhost:9081/myapp/myotherservice?httpBindingRef=myownbinder").process(new Processor() { public void process(Exchange exchange) throws Exception { throw new IllegalStateException("Not implemented"); } Modified: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyHttpClientOptionsTest.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyHttpClientOptionsTest.java?rev=742898&r1=742897&r2=742898&view=diff ============================================================================== --- camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyHttpClientOptionsTest.java (original) +++ camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyHttpClientOptionsTest.java Tue Feb 10 09:07:49 2009 @@ -34,7 +34,7 @@ assertEquals("Get the wrong http client parameter", 5555, producer.getHttpClient().getParams().getSoTimeout()); // send and receive - Object out = template.requestBody("http://localhost:8080/myapp/myservice", "Hello World"); + Object out = template.requestBody("http://localhost:9080/myapp/myservice", "Hello World"); assertEquals("Bye World", context.getTypeConverter().convertTo(String.class, out)); } @@ -43,7 +43,7 @@ return new RouteBuilder() { @Override public void configure() throws Exception { - from("jetty:http://localhost:8080/myapp/myservice?httpClient.soTimeout=5555").transform().constant("Bye World"); + from("jetty:http://localhost:9080/myapp/myservice?httpClient.soTimeout=5555").transform().constant("Bye World"); } }; } Modified: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyImageFileTest.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyImageFileTest.java?rev=742898&r1=742897&r2=742898&view=diff ============================================================================== --- camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyImageFileTest.java (original) +++ camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyImageFileTest.java Tue Feb 10 09:07:49 2009 @@ -23,6 +23,7 @@ import org.apache.camel.Exchange; import org.apache.camel.Processor; import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.http.helper.GZIPHelper; /** * Unit test for exposing a http server that returns images @@ -30,19 +31,29 @@ public class JettyImageFileTest extends ContextTestSupport { public void testImageContentType() throws Exception { - Endpoint endpoint = context.getEndpoint("http://localhost:8080/myapp/myservice"); + Endpoint endpoint = context.getEndpoint("http://localhost:9080/myapp/myservice"); Exchange exchange = endpoint.createExchange(); template.send(endpoint, exchange); assertNotNull(exchange.getOut().getBody()); assertOutMessageHeader(exchange, "Content-Type", "image/jpeg"); } + + public void testImageWithGZip() throws Exception { + Endpoint endpoint = context.getEndpoint("http://localhost:9080/myapp/myservice"); + Exchange exchange = endpoint.createExchange(); + GZIPHelper.setGZIPMessageHeader(exchange.getIn()); + template.send(endpoint, exchange); + + assertNotNull(exchange.getOut().getBody()); + assertOutMessageHeader(exchange, "Content-Type", "image/jpeg"); + } @Override protected RouteBuilder createRouteBuilder() throws Exception { return new RouteBuilder() { public void configure() throws Exception { - from("jetty:http://localhost:8080/myapp/myservice").process(new MyImageService()); + from("jetty:http://localhost:9080/myapp/myservice").process(new MyImageService()); } }; } Modified: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyResponseBodyWhenErrorTest.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyResponseBodyWhenErrorTest.java?rev=742898&r1=742897&r2=742898&view=diff ============================================================================== --- camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyResponseBodyWhenErrorTest.java (original) +++ camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyResponseBodyWhenErrorTest.java Tue Feb 10 09:07:49 2009 @@ -30,7 +30,7 @@ public void testResponseBodyWhenError() throws Exception { try { - template.sendBody("http://localhost:8080/myapp/myservice", "bookid=123"); + template.sendBody("http://localhost:9080/myapp/myservice", "bookid=123"); fail("Should have thrown an exception"); } catch (RuntimeCamelException e) { HttpOperationFailedException cause = (HttpOperationFailedException) e.getCause(); @@ -48,7 +48,7 @@ return new RouteBuilder() { public void configure() throws Exception { errorHandler(noErrorHandler()); - from("jetty:http://localhost:8080/myapp/myservice").process(new MyBookService()); + from("jetty:http://localhost:9080/myapp/myservice").process(new MyBookService()); } }; } Modified: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyRouteTest.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyRouteTest.java?rev=742898&r1=742897&r2=742898&view=diff ============================================================================== --- camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyRouteTest.java (original) +++ camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyRouteTest.java Tue Feb 10 09:07:49 2009 @@ -29,7 +29,7 @@ public class JettyRouteTest extends ContextTestSupport { public void testSendToJetty() throws Exception { - Object response = template.requestBody("http://localhost:8080/myapp/myservice", "bookid=123"); + Object response = template.requestBody("http://localhost:9080/myapp/myservice", "bookid=123"); // convert the response to a String String body = context.getTypeConverter().convertTo(String.class, response); assertEquals("<html><body>Book 123 is Camel in Action</body></html>", body); @@ -40,7 +40,7 @@ return new RouteBuilder() { public void configure() throws Exception { // START SNIPPET: e1 - from("jetty:http://localhost:8080/myapp/myservice").process(new MyBookService()); + from("jetty:http://localhost:9080/myapp/myservice").process(new MyBookService()); // END SNIPPET: e1 } };