camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject [4/5] camel git commit: CAMEL-8774 merged the patch into camel-http4
Date Wed, 27 May 2015 08:31:44 GMT
CAMEL-8774 merged the patch into camel-http4


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

Branch: refs/heads/master
Commit: ce9a32256df3728ba24f8fcae4a4c297b27ed54c
Parents: 75c622c
Author: Willem Jiang <willem.jiang@gmail.com>
Authored: Wed May 27 16:30:31 2015 +0800
Committer: Willem Jiang <willem.jiang@gmail.com>
Committed: Wed May 27 16:31:29 2015 +0800

----------------------------------------------------------------------
 .../camel/component/http4/HttpProducer.java     |  6 +-
 .../http4/HttpProtocolHeaderFilterStrategy.java | 88 ++++++++++++++++++++
 .../component/http4/HttpCompressionTest.java    |  4 +-
 3 files changed, 95 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/ce9a3225/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpProducer.java
b/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpProducer.java
index 53f9221..a301f54 100644
--- a/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpProducer.java
+++ b/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpProducer.java
@@ -37,6 +37,7 @@ import org.apache.camel.Exchange;
 import org.apache.camel.Message;
 import org.apache.camel.component.file.GenericFile;
 import org.apache.camel.component.http4.helper.HttpHelper;
+
 import org.apache.camel.converter.stream.CachedOutputStream;
 import org.apache.camel.impl.DefaultProducer;
 import org.apache.camel.spi.HeaderFilterStrategy;
@@ -74,6 +75,7 @@ public class HttpProducer extends DefaultProducer {
     private HttpContext httpContext;
     private boolean throwException;
     private boolean transferException;
+    private HeaderFilterStrategy httpProtocolHeaderFilterStrategy = new HttpProtocolHeaderFilterStrategy();
 
     public HttpProducer(HttpEndpoint endpoint) {
         super(endpoint);
@@ -192,6 +194,7 @@ public class HttpProducer extends DefaultProducer {
         // propagate HTTP response headers
         Header[] headers = httpResponse.getAllHeaders();
         for (Header header : headers) {
+            System.out.println("headers name " + header.getName());
             String name = header.getName();
             String value = header.getValue();
             if (name.toLowerCase().equals("content-type")) {
@@ -207,7 +210,8 @@ public class HttpProducer extends DefaultProducer {
 
         // preserve headers from in by copying any non existing headers
         // to avoid overriding existing headers with old values
-        MessageHelper.copyHeaders(exchange.getIn(), answer, false);
+        // Just filter the http protocol headers 
+        MessageHelper.copyHeaders(exchange.getIn(), answer, httpProtocolHeaderFilterStrategy,
false);
     }
 
     protected Exception populateHttpOperationFailedException(Exchange exchange, HttpRequestBase
httpRequest, HttpResponse httpResponse, int responseCode) throws IOException, ClassNotFoundException
{

http://git-wip-us.apache.org/repos/asf/camel/blob/ce9a3225/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpProtocolHeaderFilterStrategy.java
----------------------------------------------------------------------
diff --git a/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpProtocolHeaderFilterStrategy.java
b/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpProtocolHeaderFilterStrategy.java
new file mode 100644
index 0000000..e7ae36d
--- /dev/null
+++ b/components/camel-http4/src/main/java/org/apache/camel/component/http4/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.http4;
+
+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/ce9a3225/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpCompressionTest.java
----------------------------------------------------------------------
diff --git a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpCompressionTest.java
b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpCompressionTest.java
index 2feab44..e6d3d9e 100644
--- a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpCompressionTest.java
+++ b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpCompressionTest.java
@@ -71,9 +71,9 @@ public class HttpCompressionTest extends BaseHttpTest {
         assertNotNull(out);
 
         Map<String, Object> headers = out.getHeaders();
+        System.out.println(headers);
         assertEquals(HttpStatus.SC_OK, headers.get(Exchange.HTTP_RESPONSE_CODE));
-        assertEquals("gzip", headers.get("Content-Encoding"));
-
+        
         assertBody(out.getBody(String.class));
     }
 


Mime
View raw message