camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cschnei...@apache.org
Subject camel git commit: Remove second path of getting response headers
Date Fri, 12 Dec 2014 10:23:51 GMT
Repository: camel
Updated Branches:
  refs/heads/master 646e7106e -> 0cd81204d


Remove second path of getting response headers


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

Branch: refs/heads/master
Commit: 0cd81204d9bbe1f9adac5524355133093148c3a5
Parents: 646e710
Author: Christian Schneider <chris@die-schneider.net>
Authored: Fri Dec 12 11:23:21 2014 +0100
Committer: Christian Schneider <chris@die-schneider.net>
Committed: Fri Dec 12 11:23:35 2014 +0100

----------------------------------------------------------------------
 .../jetty/DefaultJettyHttpBinding.java          | 15 ++++++-
 .../component/jetty/JettyContentExchange.java   | 47 --------------------
 .../JettyHttpProducerSuspendTest.java           |  2 +-
 3 files changed, 14 insertions(+), 50 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/0cd81204/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/DefaultJettyHttpBinding.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/DefaultJettyHttpBinding.java
b/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/DefaultJettyHttpBinding.java
index 15e05af..5137d15 100644
--- a/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/DefaultJettyHttpBinding.java
+++ b/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/DefaultJettyHttpBinding.java
@@ -19,6 +19,7 @@ package org.apache.camel.component.jetty;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.Collection;
+import java.util.HashMap;
 import java.util.Map;
 
 import org.apache.camel.Exchange;
@@ -133,7 +134,7 @@ public class DefaultJettyHttpBinding implements JettyHttpBinding {
                                                                                 int responseCode)
throws IOException {
         HttpOperationFailedException answer;
         String uri = httpExchange.getUrl();
-        Map<String, String> headers = httpExchange.getHeaders();
+        Map<String, String> headers = getSimpleMap(httpExchange.getResponseHeaders());
         Object responseBody = extractResponseBody(exchange, httpExchange);
 
         if (transferException && responseBody != null && responseBody instanceof
Exception) {
@@ -168,7 +169,8 @@ public class DefaultJettyHttpBinding implements JettyHttpBinding {
     }
 
     protected Object extractResponseBody(Exchange exchange, JettyContentExchange httpExchange)
throws IOException {
-        String contentType = httpExchange.getHeaders().get(Exchange.CONTENT_TYPE);
+        Map<String, String> headers = getSimpleMap(httpExchange.getResponseHeaders());
+        String contentType = headers.get(Exchange.CONTENT_TYPE);
 
         // if content type is serialized java object, then de-serialize it to a Java object
         if (contentType != null && HttpConstants.CONTENT_TYPE_JAVA_SERIALIZED_OBJECT.equals(contentType))
{
@@ -189,4 +191,13 @@ public class DefaultJettyHttpBinding implements JettyHttpBinding {
         this.supportRedirect = supportRedirect;
     }
 
+    Map<String, String> getSimpleMap(Map<String, Collection<String>> headers)
{
+        Map<String, String> result = new HashMap<String ,String>();
+        for (String key : headers.keySet()) {
+            Collection<String> valueCol = headers.get(key);
+            String value = (valueCol == null) ? null : valueCol.iterator().next();
+            result.put(key, value);
+        }
+        return result;
+    }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/0cd81204/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyContentExchange.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyContentExchange.java
b/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyContentExchange.java
index a06647e..01ae205 100644
--- a/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyContentExchange.java
+++ b/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyContentExchange.java
@@ -20,7 +20,6 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.UnsupportedEncodingException;
 import java.util.Collection;
-import java.util.LinkedHashMap;
 import java.util.Map;
 import java.util.TreeMap;
 import java.util.concurrent.CountDownLatch;
@@ -30,8 +29,6 @@ import org.apache.camel.CamelExchangeException;
 import org.apache.camel.Exchange;
 import org.apache.camel.ExchangeTimedOutException;
 import org.apache.camel.util.IOHelper;
-import org.apache.camel.util.ObjectHelper;
-import org.apache.camel.util.StringHelper;
 import org.eclipse.jetty.client.ContentExchange;
 import org.eclipse.jetty.client.HttpClient;
 import org.eclipse.jetty.client.HttpEventListener;
@@ -39,8 +36,6 @@ import org.eclipse.jetty.client.HttpEventListenerWrapper;
 import org.eclipse.jetty.client.HttpExchange;
 import org.eclipse.jetty.http.HttpFields;
 import org.eclipse.jetty.http.HttpHeaders;
-import org.eclipse.jetty.io.Buffer;
-import org.eclipse.jetty.io.ByteArrayBuffer;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -53,7 +48,6 @@ public class JettyContentExchange {
 
     private static final Logger LOG = LoggerFactory.getLogger(JettyContentExchange.class);
 
-    private final Map<String, String> headers = new LinkedHashMap<String, String>();
     private volatile Exchange exchange;
     private volatile AsyncCallback callback;
     private volatile JettyHttpBinding jettyBinding;
@@ -75,11 +69,6 @@ public class JettyContentExchange {
                 super.onRequestComplete();
             }
 
-            public void onResponseHeader(Buffer name, Buffer value) throws IOException {
-                JettyContentExchange.this.onResponseHeader(name, value);
-                super.onResponseHeader(name, value);
-            }
-
             @Override
             public void onResponseComplete() throws IOException {
                 super.onResponseComplete();
@@ -120,38 +109,6 @@ public class JettyContentExchange {
         this.callback = callback;
     }
 
-    protected void onResponseHeader(Buffer name, Buffer value) throws IOException {
-        String k = name.toString();
-        String v = value.toString();
-        LOG.trace("onResponseHeader {} -> {}", k, v);
-
-        // need to remove quotes from charset which can be returned by some http servers
-        if (Exchange.CONTENT_TYPE.equalsIgnoreCase(k)) {
-            String charset = ObjectHelper.after(v, "charset=");
-            if (charset != null) {
-                // there may be another parameter as well, we only want the charset parameter
-                String extra = "";
-                if (charset.contains(";")) {
-                    extra = ObjectHelper.after(charset, ";");
-                    charset = ObjectHelper.before(charset, ";");
-                }
-                charset = charset.trim();
-                String s = StringHelper.removeLeadingAndEndingQuotes(charset);
-                if (!charset.equals(s)) {
-                    v = ObjectHelper.before(v, "charset=") + "charset=" + s;
-                    LOG.debug("Removed quotes from charset in " + Exchange.CONTENT_TYPE +
" from {} to {}", charset, s);
-                    // add extra parameters
-                    if (extra != null) {
-                        v = v + ";" + extra;
-                    }
-                    // use a new buffer to adjust the value
-                    value = new ByteArrayBuffer.CaseInsensitive(v);
-                }
-            }
-        }
-        headers.put(k, v);
-    }
-
     protected void onRequestComplete() throws IOException {
         LOG.trace("onRequestComplete");
         
@@ -187,10 +144,6 @@ public class JettyContentExchange {
         doTaskCompleted(ex);
     }
 
-    public Map<String, String> getHeaders() {
-        return headers;
-    }
-
     public byte[] getBody() {
         // must return the content as raw bytes
         return ce.getResponseContentBytes();

http://git-wip-us.apache.org/repos/asf/camel/blob/0cd81204/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerSuspendTest.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerSuspendTest.java
b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerSuspendTest.java
index b21ec23..dc67337 100644
--- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerSuspendTest.java
+++ b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerSuspendTest.java
@@ -62,7 +62,7 @@ public class JettyHttpProducerSuspendTest extends BaseJettyTest {
         return new RouteBuilder() {
             @Override
             public void configure() throws Exception {
-                from(serverUri)
+                from(serverUri).id("route1")
                     .transform(body().prepend("Bye "));
             }
         };


Mime
View raw message