camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r790811 - in /camel/trunk: camel-core/src/main/java/org/apache/camel/ camel-core/src/main/java/org/apache/camel/util/ components/camel-http/src/main/java/org/apache/camel/component/http/ components/camel-http/src/main/java/org/apache/camel/...
Date Fri, 03 Jul 2009 07:02:34 GMT
Author: davsclaus
Date: Fri Jul  3 07:02:33 2009
New Revision: 790811

URL: http://svn.apache.org/viewvc?rev=790811&view=rev
Log:
CAMEL-1740: Content-Type and Content-Encoding is now first class keys in Camel used by http
related components. Fixed jetty unit test with gzip encoding as it was wrong.

Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/Exchange.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/util/ExchangeHelper.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/util/MessageHelper.java
    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/HttpMessage.java
    camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java
    camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/RequestEntityConverter.java
    camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/helper/GZIPHelper.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/JettyImageFileTest.java
    camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyWithXPathChoiceTest.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/Exchange.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/Exchange.java?rev=790811&r1=790810&r2=790811&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/Exchange.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/Exchange.java Fri Jul  3 07:02:33
2009
@@ -46,15 +46,18 @@
     String BEAN_HOLDER                = "CamelBeanHolder";
     String BEAN_MULTI_PARAMETER_ARRAY = "CamelBeanMultiParameterArray";
 
-    String CHARSET_NAME = "CamelCharsetName";
-    String CONTENT_TYPE = "CamelContentType";
-    String CORRELATION_ID = "CamelCorrelationId";
+    String BINDING = "CamelBinding";
+
+    String CHARSET_NAME     = "CamelCharsetName";
+    String CONTENT_ENCODING = "Content-Encoding";
+    String CONTENT_TYPE     = "Content-Type";
+    String CORRELATION_ID   = "CamelCorrelationId";
 
     String DATASET_INDEX = "CamelDataSetIndex";
 
-    String EXCEPTION_CAUGHT  = "CamelExceptionCaught";
+    String EXCEPTION_CAUGHT     = "CamelExceptionCaught";
     String ERRORHANDLER_HANDLED = "CamelErrorHandlerHandled";
-    String FAILURE_HANDLED   = "CamelFailureHandled";
+    String FAILURE_HANDLED      = "CamelFailureHandled";
 
     String FILE_LOCAL_WORK_PATH = "CamelFileLocalWorkPath";
     String FILE_NAME            = "CamelFileName";
@@ -98,8 +101,6 @@
     String TRANSACTED    = "CamelTransacted";
     String ROLLBACK_ONLY = "CamelRollbackOnly";
 
-    String BINDING = "CamelBinding";
-    
     /**
      * Returns the {@link ExchangePattern} (MEP) of this exchange.
      *

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/util/ExchangeHelper.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ExchangeHelper.java?rev=790811&r1=790810&r2=790811&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/util/ExchangeHelper.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/util/ExchangeHelper.java Fri Jul
 3 07:02:33 2009
@@ -350,6 +350,13 @@
     }
 
     /**
+     * Returns the MIME content encoding on the input message or null if one is not defined
+     */
+    public static String getContentEncoding(Exchange exchange) {
+        return MessageHelper.getContentEncoding(exchange.getIn());
+    }
+
+    /**
      * Performs a lookup in the registry of the mandatory bean name and throws an exception
if it could not be found
      */
     public static Object lookupMandatoryBean(Exchange exchange, String name) {

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/util/MessageHelper.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/util/MessageHelper.java?rev=790811&r1=790810&r2=790811&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/util/MessageHelper.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/util/MessageHelper.java Fri Jul
 3 07:02:33 2009
@@ -100,15 +100,17 @@
     }
     
     /**
-     * Returns the MIME content type on the message or null if one is not defined
+     * Returns the MIME content type on the message or <tt>null</tt> if none
defined
      */
     public static String getContentType(Message message) {        
-        String contentType = message.getHeader(Exchange.CONTENT_TYPE, String.class);
-        if (contentType == null) {
-            // fallback with the Content-Type
-            contentType = message.getHeader("Content-Type", String.class);
-        }
-        return contentType;
+        return message.getHeader(Exchange.CONTENT_TYPE, String.class);
+    }
+
+    /**
+     * Returns the MIME content encoding on the message or <tt>null</tt> if none
defined
+     */
+    public static String getContentEncoding(Message message) {
+        return message.getHeader(Exchange.CONTENT_ENCODING, String.class);
     }
 
     /**

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=790811&r1=790810&r2=790811&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
Fri Jul  3 07:02:33 2009
@@ -16,13 +16,11 @@
  */
 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 java.util.zip.GZIPOutputStream;
 import javax.servlet.ServletOutputStream;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
@@ -116,9 +114,9 @@
     }
 
     private void copyProtocolHeaders(Message request, Message response) {
-        if (request.getHeader(HttpMessage.CONTENT_ENCODING) != null) {
-            String contentEncoding = request.getHeader(HttpMessage.CONTENT_ENCODING, String.class);
-            response.setHeader(HttpMessage.CONTENT_ENCODING, contentEncoding);
+        if (request.getHeader(Exchange.CONTENT_ENCODING) != null) {
+            String contentEncoding = request.getHeader(Exchange.CONTENT_ENCODING, String.class);
+            response.setHeader(Exchange.CONTENT_ENCODING, contentEncoding);
         }        
     }
 

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=790811&r1=790810&r2=790811&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
Fri Jul  3 07:02:33 2009
@@ -23,6 +23,7 @@
 import javax.servlet.http.HttpServletRequest;
 
 import org.apache.camel.Converter;
+import org.apache.camel.Exchange;
 import org.apache.camel.component.http.helper.GZIPHelper;
 
 /**
@@ -73,7 +74,7 @@
         if (request == null) {
             return null;
         }
-        String contentEncoding = request.getHeader(HttpMessage.CONTENT_ENCODING);
+        String contentEncoding = request.getHeader(Exchange.CONTENT_ENCODING);
         return GZIPHelper.toGZIPInputStream(contentEncoding, request.getInputStream());
     }
 

Modified: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpMessage.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpMessage.java?rev=790811&r1=790810&r2=790811&view=diff
==============================================================================
--- camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpMessage.java
(original)
+++ camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpMessage.java
Fri Jul  3 07:02:33 2009
@@ -28,8 +28,7 @@
  * @version $Revision$
  */
 public class HttpMessage extends DefaultMessage {
-    public static final String CONTENT_ENCODING = "Content-Encoding";
-    
+
     private HttpServletRequest request;
 
     public HttpMessage(Exchange exchange, HttpServletRequest request) {

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=790811&r1=790810&r2=790811&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
Fri Jul  3 07:02:33 2009
@@ -19,7 +19,6 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.UnsupportedEncodingException;
-import java.util.zip.GZIPInputStream;
 
 import org.apache.camel.Exchange;
 import org.apache.camel.Message;
@@ -161,7 +160,7 @@
             return null;
         }
 
-        Header header = method.getRequestHeader(HttpMessage.CONTENT_ENCODING);
+        Header header = method.getRequestHeader(Exchange.CONTENT_ENCODING);
         String contentEncoding = header != null ? header.getValue() : null;
 
         is = GZIPHelper.toGZIPInputStream(contentEncoding, is);

Modified: 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=790811&r1=790810&r2=790811&view=diff
==============================================================================
--- camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/RequestEntityConverter.java
(original)
+++ camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/RequestEntityConverter.java
Fri Jul  3 07:02:33 2009
@@ -62,14 +62,14 @@
     private RequestEntity asRequestEntity(InputStream in, Exchange exchange) throws IOException
{
         return new InputStreamRequestEntity(
                 GZIPHelper.toGZIPInputStream(
-                        exchange.getIn().getHeader(HttpMessage.CONTENT_ENCODING, String.class),
+                        exchange.getIn().getHeader(Exchange.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(HttpMessage.CONTENT_ENCODING, String.class),
+                    exchange.getIn().getHeader(Exchange.CONTENT_ENCODING, String.class),
                     data), ExchangeHelper.getContentType(exchange));
     }
 }

Modified: 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=790811&r1=790810&r2=790811&view=diff
==============================================================================
--- camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/helper/GZIPHelper.java
(original)
+++ camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/helper/GZIPHelper.java
Fri Jul  3 07:02:33 2009
@@ -23,8 +23,8 @@
 import java.util.zip.GZIPInputStream;
 import java.util.zip.GZIPOutputStream;
 
+import org.apache.camel.Exchange;
 import org.apache.camel.Message;
-import org.apache.camel.component.http.HttpMessage;
 import org.apache.camel.util.ObjectHelper;
 
 /**
@@ -76,7 +76,7 @@
     }
 
     public static boolean isGzip(Message message) {
-        return isGzip(message.getHeader(HttpMessage.CONTENT_ENCODING, String.class));
+        return isGzip(message.getHeader(Exchange.CONTENT_ENCODING, String.class));
     }
 
     public static boolean isGzip(String header) {

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=790811&r1=790810&r2=790811&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
Fri Jul  3 07:02:33 2009
@@ -20,7 +20,6 @@
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
 import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.http.HttpMessage;
 import org.apache.camel.test.junit4.CamelTestSupport;
 import org.apache.camel.util.ExchangeHelper;
 import org.apache.camel.util.MessageHelper;
@@ -38,7 +37,7 @@
         exchange.getIn().setHeader("user", "Claus");
         exchange.getIn().setHeader("Content-Type", "text/xml");
         if (usingGZip) {
-            exchange.getIn().setHeader(HttpMessage.CONTENT_ENCODING, "gzip");
+            exchange.getIn().setHeader("Content-Encoding", "gzip");
         }
         template.send(endpoint, exchange);
 
@@ -54,7 +53,7 @@
     }
     
     @Test
-    public void testContentTypeWithGZip() throws Exception {
+    public void testContentTypeWithGZipEncoding() throws Exception {
         sendMessageWithContentType(true);
     }
 

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=790811&r1=790810&r2=790811&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
Fri Jul  3 07:02:33 2009
@@ -22,7 +22,6 @@
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
 import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.http.HttpMessage;
 import org.apache.camel.test.junit4.CamelTestSupport;
 import org.apache.camel.util.MessageHelper;
 import org.junit.Test;
@@ -36,7 +35,7 @@
         Endpoint endpoint = context.getEndpoint("http://localhost:9080/myapp/myservice");
         Exchange exchange = endpoint.createExchange();        
         if (usingGZip) {
-            exchange.getIn().setHeader(HttpMessage.CONTENT_ENCODING, "gzip");
+            exchange.getIn().setHeader(Exchange.CONTENT_ENCODING, "gzip");
         }
         template.send(endpoint, exchange);
 

Modified: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyWithXPathChoiceTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyWithXPathChoiceTest.java?rev=790811&r1=790810&r2=790811&view=diff
==============================================================================
--- camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyWithXPathChoiceTest.java
(original)
+++ camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyWithXPathChoiceTest.java
Fri Jul  3 07:02:33 2009
@@ -18,10 +18,10 @@
 
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
+import static org.apache.camel.component.mock.MockEndpoint.expectsMessageCount;
 import org.apache.camel.test.junit4.CamelTestSupport;
 import org.junit.Before;
 import org.junit.Test;
-import static org.apache.camel.component.mock.MockEndpoint.expectsMessageCount;
 
 public class JettyWithXPathChoiceTest extends CamelTestSupport {
     protected MockEndpoint x;
@@ -39,14 +39,14 @@
 
         x.reset();
         y.reset();
-        z.reset();        
-        
+        z.reset();
+
         body = "<two/>";
         expectsMessageCount(0, x, z);
-        
+
         sendBody(body);
 
-        assertMockEndpointsSatisfied();    
+        assertMockEndpointsSatisfied();
     }
 
     private void sendBody(String body) {
@@ -66,14 +66,15 @@
     protected RouteBuilder createRouteBuilder() {
         return new RouteBuilder() {
             public void configure() {
-                errorHandler(deadLetterChannel("mock:error").redeliverDelay(0));
+                from("jetty:http://localhost:9080/myworld")
+                    // use stream caching
+                    .streamCaching()
+                    .choice()
+                        .when().xpath("/one").to("mock:x")
+                        .when().xpath("/two").to("mock:y")
+                        .otherwise().to("mock:z")
+                    .end();
 
-                // Need a convertBodyTo processor here or we may get an error
-                // that we are at the end of the stream
-                from("jetty:http://localhost:9080/myworld").choice()
-                  .when().xpath("/one").to("mock:x")
-                  .when().xpath("/two").to("mock:y")
-                  .otherwise().to("mock:z");
             }
         };
     }



Mime
View raw message