camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r999444 - in /camel/trunk/components: camel-http/src/main/java/org/apache/camel/component/http/ camel-jetty/src/main/java/org/apache/camel/component/jetty/ camel-jetty/src/test/java/org/apache/camel/component/jetty/
Date Tue, 21 Sep 2010 14:47:04 GMT
Author: davsclaus
Date: Tue Sep 21 14:47:03 2010
New Revision: 999444

URL: http://svn.apache.org/viewvc?rev=999444&view=rev
Log:
CAMEL-2743: Fixed jetty returning back http headers using keys in lowercase.

Added:
    camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpHeaderCaseTest.java
      - copied, changed from r999286, camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpHeaderTest.java
Modified:
    camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java
    camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/DefaultJettyHttpBinding.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=999444&r1=999443&r2=999444&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 Sep 21 14:47:03 2010
@@ -216,11 +216,13 @@ public class DefaultHttpBinding implemen
         }
 
         // append headers
-        for (String key : message.getHeaders().keySet()) {
-            String value = message.getHeader(key, String.class);
-            if (headerFilterStrategy != null
+        // must use entrySet to ensure case of keys is preserved
+        for (Map.Entry<String, Object> entry : message.getHeaders().entrySet()) {
+            String key = entry.getKey();
+            Object value = entry.getValue();
+            if (value != null && headerFilterStrategy != null
                     && !headerFilterStrategy.applyFilterToCamelHeaders(key, value,
exchange)) {
-                response.setHeader(key, value);
+                response.setHeader(key, value.toString());
             }
         }
 

Modified: camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/DefaultJettyHttpBinding.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/DefaultJettyHttpBinding.java?rev=999444&r1=999443&r2=999444&view=diff
==============================================================================
--- camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/DefaultJettyHttpBinding.java
(original)
+++ camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/DefaultJettyHttpBinding.java
Tue Sep 21 14:47:03 2010
@@ -83,6 +83,7 @@ public class DefaultJettyHttpBinding imp
         answer.setBody(extractResponseBody(exchange, httpExchange));
 
         // propagate HTTP response headers
+        // must use entrySet to ensure case of keys is preserved
         for (Map.Entry<String, String> entry : httpExchange.getHeaders().entrySet())
{
             String name = entry.getKey();
             String value = entry.getValue();

Copied: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpHeaderCaseTest.java
(from r999286, camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpHeaderTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpHeaderCaseTest.java?p2=camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpHeaderCaseTest.java&p1=camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpHeaderTest.java&r1=999286&r2=999444&rev=999444&view=diff
==============================================================================
--- camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpHeaderTest.java
(original)
+++ camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpHeaderCaseTest.java
Tue Sep 21 14:47:03 2010
@@ -16,56 +16,56 @@
  */
 package org.apache.camel.component.jetty;
 
+import java.util.LinkedHashMap;
 import java.util.Map;
-import java.util.Map.Entry;
 
-import javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
-
-import org.apache.camel.Endpoint;
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
 import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.jetty.JettyContentTypeTest.MyBookService;
 import org.apache.camel.test.junit4.CamelTestSupport;
-import org.apache.camel.util.ExchangeHelper;
-import org.apache.camel.util.MessageHelper;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpMethod;
+import org.apache.commons.httpclient.methods.PostMethod;
 import org.junit.Test;
 
-public class HttpHeaderTest extends CamelTestSupport {
+public class HttpHeaderCaseTest extends CamelTestSupport {
 
     @Test
-    public void testHttpHeaders() throws Exception {
-        String result = template.requestBody("direct:start", "hello", String.class);
-        assertEquals("Should send a right http header to the server.", "Find the key!", result);
-       
+    public void testHttpHeaderCase() throws Exception {
+        HttpClient client = new HttpClient();
+        HttpMethod method = new PostMethod("http://localhost:9080/myapp/mytest");
+
+        method.setRequestHeader("clientHeader", "fooBAR");
+        method.setRequestHeader("OTHER", "123");
+        method.setRequestHeader("beer", "Carlsberg");
+
+        client.executeMethod(method);
+
+        assertEquals("Bye World", method.getResponseBodyAsString());
+        assertEquals("aBc123", method.getResponseHeader("MyCaseHeader").getValue());
+        assertEquals("456DEf", method.getResponseHeader("otherCaseHeader").getValue());
     }
 
     @Override
     protected RouteBuilder createRouteBuilder() throws Exception {
         return new RouteBuilder() {
             public void configure() throws Exception {
-                from("direct:start").setHeader("SOAPAction", constant("http://xxx.com/interfaces/ticket"))
-                    .setHeader("Content-Type", constant("text/xml; charset=utf-8"))
-                    .setHeader(Exchange.HTTP_PROTOCOL_VERSION, constant("HTTP/1.0"))
-                    .to("http://localhost:9080/myapp/mytest");
-
                 from("jetty:http://localhost:9080/myapp/mytest").process(new Processor()
{
-
                     public void process(Exchange exchange) throws Exception {
-                        Map<String, Object> headers = exchange.getIn().getHeaders();
-                        ServletRequest request = exchange.getIn().getHeader(Exchange.HTTP_SERVLET_REQUEST,
ServletRequest.class);
-                        assertNotNull(request);
-                        assertEquals("Get a wong http protocol version", request.getProtocol(),
"HTTP/1.0");
-                        for (Entry<String, Object> entry : headers.entrySet()) {
-                            if ("SOAPAction".equals(entry.getKey()) && "http://xxx.com/interfaces/ticket".equals(entry.getValue()))
{
-                                exchange.getOut().setBody("Find the key!");
-                                return;
-                            }
-                        }
-                        exchange.getOut().setBody("Cannot find the key!");
-                    }
 
+                        // headers received should be in case as well
+                        Map<String, Object> map = new LinkedHashMap<String, Object>();
+                        map.putAll(exchange.getIn().getHeaders());
+
+                        assertEquals("123", map.get("OTHER"));
+                        assertEquals(null, map.get("other"));
+                        assertEquals("Carlsberg", map.get("beer"));
+                        assertEquals(null, map.get("Beer"));
+
+                        exchange.getOut().setBody("Bye World");
+                        exchange.getOut().setHeader("MyCaseHeader", "aBc123");
+                        exchange.getOut().setHeader("otherCaseHeader", "456DEf");
+                    }
                 });
 
             }



Mime
View raw message