CAMEL-8774 Fixed the issue of copying the protocol headers in camel-jetty

Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/497b1779
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/497b1779
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/497b1779

Branch: refs/heads/master
Commit: 497b17797d8a8f0d6cd01feeb8e280094d95a09d
Parents: 2eaa44e
Author: Willem Jiang <willem.ji...@gmail.com>
Authored: Wed May 27 16:28:40 2015 +0800
Committer: Willem Jiang <willem.ji...@gmail.com>
Committed: Wed May 27 16:31:29 2015 +0800

----------------------------------------------------------------------
 .../org/apache/camel/util/MessageHelper.java    |  2 +-
 .../apache/camel/util/MessageHelperTest.java    |  2 +-
 .../http/HttpProtocolHeaderFilterStrategy.java  | 88 ++++++++++++++++++++
 .../jetty/DefaultJettyHttpBinding.java          |  6 +-
 4 files changed, 94 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/497b1779/camel-core/src/main/java/org/apache/camel/util/MessageHelper.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/MessageHelper.java 
b/camel-core/src/main/java/org/apache/camel/util/MessageHelper.java
index 49d2170..77fa472 100644
--- a/camel-core/src/main/java/org/apache/camel/util/MessageHelper.java
+++ b/camel-core/src/main/java/org/apache/camel/util/MessageHelper.java
@@ -493,7 +493,7 @@ public final class MessageHelper {
             if (target.getHeader(key) == null || override) {
                 if (strategy == null) {
                     target.setHeader(key, value);
-                } else if (!strategy.applyFilterToCamelHeaders(key, value, 
target.getExchange())) {
+                } else if (!strategy.applyFilterToExternalHeaders(key, value, 
target.getExchange())) {
                     // Just make sure we don't copy the protocol headers to 
target
                     target.setHeader(key, value);
                 }

http://git-wip-us.apache.org/repos/asf/camel/blob/497b1779/camel-core/src/test/java/org/apache/camel/util/MessageHelperTest.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/test/java/org/apache/camel/util/MessageHelperTest.java 
b/camel-core/src/test/java/org/apache/camel/util/MessageHelperTest.java
index 1e9ef0a..7cd305f 100644
--- a/camel-core/src/test/java/org/apache/camel/util/MessageHelperTest.java
+++ b/camel-core/src/test/java/org/apache/camel/util/MessageHelperTest.java
@@ -131,7 +131,7 @@ public class MessageHelperTest extends TestCase {
         Message target = message.getExchange().getOut();
         
         DefaultHeaderFilterStrategy headerFilterStrategy = new 
DefaultHeaderFilterStrategy();
-        headerFilterStrategy.setOutFilterPattern("foo");
+        headerFilterStrategy.setInFilterPattern("foo");
         
         source.setHeader("foo", 123);
         source.setHeader("bar", 456);

http://git-wip-us.apache.org/repos/asf/camel/blob/497b1779/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProtocolHeaderFilterStrategy.java
----------------------------------------------------------------------
diff --git 
a/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProtocolHeaderFilterStrategy.java
 
b/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProtocolHeaderFilterStrategy.java
new file mode 100644
index 0000000..d8398ae
--- /dev/null
+++ 
b/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProtocolHeaderFilterStrategy.java
@@ -0,0 +1,88 @@
+/**
+ * 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 org.apache.camel.impl.DefaultHeaderFilterStrategy;
+
+
+public class HttpProtocolHeaderFilterStrategy extends 
DefaultHeaderFilterStrategy {
+    
+    public HttpProtocolHeaderFilterStrategy() {
+        initialize();  
+    }
+
+    // Just add the http headers here 
+    protected void initialize() {
+        getInFilter().add("host");
+        
+        getInFilter().add("content-encoding");
+        getInFilter().add("content-language");
+        getInFilter().add("content-location");
+        getInFilter().add("content-md5");
+        getInFilter().add("content-length");
+        getInFilter().add("content-type");
+        getInFilter().add("content-range");
+        
+        getInFilter().add("dav");
+        getInFilter().add("depth");
+        getInFilter().add("destination");
+        getInFilter().add("etag");
+        getInFilter().add("expect");
+        getInFilter().add("expires");
+        getInFilter().add("from");
+        getInFilter().add("if");
+        getInFilter().add("if-match");
+        getInFilter().add("if-modified-since");
+        getInFilter().add("if-none-match");
+        getInFilter().add("if-range");
+        getInFilter().add("if-unmodified-since");
+        getInFilter().add("last-modified");
+        getInFilter().add("location");
+        getInFilter().add("lock-token");
+        getInFilter().add("max-forwards");
+        getInFilter().add("overwrite");
+        getInFilter().add("pragma");
+        getInFilter().add("proxy-authenticate");
+        getInFilter().add("proxy-authorization");
+        getInFilter().add("range");
+        getInFilter().add("referer");
+        getInFilter().add("retry-after");
+        getInFilter().add("server");
+        getInFilter().add("status-uri");
+        getInFilter().add("te");
+        getInFilter().add("timeout");
+      
+        getInFilter().add("user-agent");
+        getInFilter().add("vary");
+  
+        getInFilter().add("www-authenticate");
+        
+        // Add the filter for the Generic Message header
+        // http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.5
+        getInFilter().add("cache-control");
+        getInFilter().add("connection");
+        getInFilter().add("date");
+        getInFilter().add("pragma");
+        getInFilter().add("trailer");
+        getInFilter().add("transfer-encoding");
+        getInFilter().add("upgrade");
+        getInFilter().add("via");
+        getInFilter().add("warning");
+               
+        setLowerCase(true);
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/497b1779/components/camel-jetty-common/src/main/java/org/apache/camel/component/jetty/DefaultJettyHttpBinding.java
----------------------------------------------------------------------
diff --git 
a/components/camel-jetty-common/src/main/java/org/apache/camel/component/jetty/DefaultJettyHttpBinding.java
 
b/components/camel-jetty-common/src/main/java/org/apache/camel/component/jetty/DefaultJettyHttpBinding.java
index 63c52ea..ce3cc26 100644
--- 
a/components/camel-jetty-common/src/main/java/org/apache/camel/component/jetty/DefaultJettyHttpBinding.java
+++ 
b/components/camel-jetty-common/src/main/java/org/apache/camel/component/jetty/DefaultJettyHttpBinding.java
@@ -28,6 +28,7 @@ import org.apache.camel.RuntimeCamelException;
 import org.apache.camel.component.http.HttpConstants;
 import org.apache.camel.component.http.HttpHeaderFilterStrategy;
 import org.apache.camel.component.http.HttpOperationFailedException;
+import org.apache.camel.component.http.HttpProtocolHeaderFilterStrategy;
 import org.apache.camel.component.http.helper.HttpHelper;
 import org.apache.camel.spi.HeaderFilterStrategy;
 import org.apache.camel.util.IOHelper;
@@ -42,6 +43,7 @@ public class DefaultJettyHttpBinding implements 
JettyHttpBinding {
 
     private static final Logger LOG = 
LoggerFactory.getLogger(DefaultJettyHttpBinding.class);
     private HeaderFilterStrategy headerFilterStrategy = new 
HttpHeaderFilterStrategy();
+    private HeaderFilterStrategy httpProtocolHeaderFilterStrategy = new 
HttpProtocolHeaderFilterStrategy();
     private boolean throwExceptionOnFailure;
     private boolean transferException;
 
@@ -122,8 +124,8 @@ public class DefaultJettyHttpBinding implements 
JettyHttpBinding {
         
         // preserve headers from in by copying any non existing headers
         // to avoid overriding existing headers with old values
-        // We also need to apply the HeaderFilterStrategy here
-        MessageHelper.copyHeaders(exchange.getIn(), answer, strategy, false);
+        // We also need to apply the httpProtocolHeaderFilterStrategy to 
filter the http protocol header
+        MessageHelper.copyHeaders(exchange.getIn(), answer, 
httpProtocolHeaderFilterStrategy, false);
 
         // extract body after headers has been set as we want to ensure 
content-type from Jetty HttpExchange
         // has been populated first

Reply via email to