camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject camel git commit: CAMEL-9586: Add getRequestHeaders to JettyContentExchange. Thanks to James Lindstorff for the patch.
Date Fri, 11 Sep 2015 08:21:48 GMT
Repository: camel
Updated Branches:
  refs/heads/master 546f347bb -> 7ac77fe38


CAMEL-9586: Add getRequestHeaders to JettyContentExchange. Thanks to James Lindstorff for
the patch.


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

Branch: refs/heads/master
Commit: 7ac77fe38e80cc42390529ac3f94985c720de9be
Parents: 546f347
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Fri Sep 11 10:22:48 2015 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Fri Sep 11 10:22:48 2015 +0200

----------------------------------------------------------------------
 .../component/jetty/JettyContentExchange.java   |  1 +
 .../component/jetty8/JettyContentExchange8.java | 48 ++++++++++++--------
 .../component/jetty9/JettyContentExchange9.java | 39 +++++++++-------
 3 files changed, 51 insertions(+), 37 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/7ac77fe3/components/camel-jetty-common/src/main/java/org/apache/camel/component/jetty/JettyContentExchange.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty-common/src/main/java/org/apache/camel/component/jetty/JettyContentExchange.java
b/components/camel-jetty-common/src/main/java/org/apache/camel/component/jetty/JettyContentExchange.java
index aef8935..af63606 100644
--- a/components/camel-jetty-common/src/main/java/org/apache/camel/component/jetty/JettyContentExchange.java
+++ b/components/camel-jetty-common/src/main/java/org/apache/camel/component/jetty/JettyContentExchange.java
@@ -66,4 +66,5 @@ public interface JettyContentExchange {
 
     Map<String, Collection<String>> getResponseHeaders();
 
+    Map<String, Collection<String>> getRequestHeaders();
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/7ac77fe3/components/camel-jetty8/src/main/java/org/apache/camel/component/jetty8/JettyContentExchange8.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty8/src/main/java/org/apache/camel/component/jetty8/JettyContentExchange8.java
b/components/camel-jetty8/src/main/java/org/apache/camel/component/jetty8/JettyContentExchange8.java
index 857877c..2e5d3ca 100644
--- a/components/camel-jetty8/src/main/java/org/apache/camel/component/jetty8/JettyContentExchange8.java
+++ b/components/camel-jetty8/src/main/java/org/apache/camel/component/jetty8/JettyContentExchange8.java
@@ -44,8 +44,6 @@ import org.slf4j.LoggerFactory;
 
 /**
  * Jetty specific exchange which keeps track of the the request and response.
- *
- * @version 
  */
 public class JettyContentExchange8 implements JettyContentExchange {
 
@@ -57,12 +55,12 @@ public class JettyContentExchange8 implements JettyContentExchange {
     private volatile HttpClient client;
     private final CountDownLatch done = new CountDownLatch(1);
     private final ContentExchange ce;
-    
+
     public JettyContentExchange8() {
         this.ce = new ContentExchange(true);
     }
 
-    public void init(Exchange exchange, JettyHttpBinding jettyBinding, 
+    public void init(Exchange exchange, JettyHttpBinding jettyBinding,
                      final HttpClient client, AsyncCallback callback) {
         this.exchange = exchange;
         this.jettyBinding = jettyBinding;
@@ -107,13 +105,13 @@ public class JettyContentExchange8 implements JettyContentExchange {
                     JettyContentExchange8.this.onExpire();
                 }
             }
-            
+
         });
     }
 
     protected void onRequestComplete() throws IOException {
         LOG.trace("onRequestComplete");
-        
+
         closeRequestContentSource();
     }
 
@@ -153,11 +151,11 @@ public class JettyContentExchange8 implements JettyContentExchange {
 
     public String getUrl() {
         String params = ce.getRequestFields().getStringField(HttpHeaders.CONTENT_ENCODING);
-        return ce.getScheme() + "://" 
-            + ce.getAddress().toString() 
-            + ce.getRequestURI() + (params != null ? "?" + params : "");
+        return ce.getScheme() + "://"
+                + ce.getAddress().toString()
+                + ce.getRequestURI() + (params != null ? "?" + params : "");
     }
-    
+
     protected void closeRequestContentSource() {
         // close the input stream when its not needed anymore
         InputStream is = ce.getRequestContentSource();
@@ -230,14 +228,15 @@ public class JettyContentExchange8 implements JettyContentExchange {
     public void setMethod(String method) {
         ce.setMethod(method);
     }
-    
+
     public void setURL(String url) {
         ce.setURL(url);
     }
 
     public void setRequestContent(byte[] byteArray) {
-        ce.setRequestContent(new org.eclipse.jetty.io.ByteArrayBuffer(byteArray));      
 
+        ce.setRequestContent(new org.eclipse.jetty.io.ByteArrayBuffer(byteArray));
     }
+
     public void setRequestContent(String data, String charset) throws UnsupportedEncodingException
{
         if (charset == null) {
             ce.setRequestContent(new org.eclipse.jetty.io.ByteArrayBuffer(data));
@@ -245,8 +244,9 @@ public class JettyContentExchange8 implements JettyContentExchange {
             ce.setRequestContent(new org.eclipse.jetty.io.ByteArrayBuffer(data, charset));
         }
     }
+
     public void setRequestContent(InputStream ins) {
-        ce.setRequestContentSource(ins);        
+        ce.setRequestContentSource(ins);
     }
 
     public void addRequestHeader(String key, String s) {
@@ -260,14 +260,22 @@ public class JettyContentExchange8 implements JettyContentExchange {
     public byte[] getResponseContentBytes() {
         return ce.getResponseContentBytes();
     }
-    
-    public Map<String, Collection<String>> getResponseHeaders() {
-        final HttpFields f = ce.getResponseFields();
-        Map<String, Collection<String>> ret = new TreeMap<String, Collection<String>>(String.CASE_INSENSITIVE_ORDER);
-        for (String n : f.getFieldNamesCollection()) {
-            ret.put(n,  f.getValuesCollection(n));
+
+    private Map<String, Collection<String>> getFieldsAsMap(HttpFields fields)
{
+        final Map<String, Collection<String>> result = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
+        for (String name : fields.getFieldNamesCollection()) {
+            result.put(name, fields.getValuesCollection(name));
         }
-        return ret;
+        return result;
+    }
+
+    public Map<String, Collection<String>> getRequestHeaders() {
+        return getFieldsAsMap(ce.getRequestFields());
+    }
+
+
+    public Map<String, Collection<String>> getResponseHeaders() {
+        return getFieldsAsMap(ce.getResponseFields());
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/camel/blob/7ac77fe3/components/camel-jetty9/src/main/java/org/apache/camel/component/jetty9/JettyContentExchange9.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty9/src/main/java/org/apache/camel/component/jetty9/JettyContentExchange9.java
b/components/camel-jetty9/src/main/java/org/apache/camel/component/jetty9/JettyContentExchange9.java
index d9f7e14..f9966cc 100644
--- a/components/camel-jetty9/src/main/java/org/apache/camel/component/jetty9/JettyContentExchange9.java
+++ b/components/camel-jetty9/src/main/java/org/apache/camel/component/jetty9/JettyContentExchange9.java
@@ -48,8 +48,6 @@ import org.slf4j.LoggerFactory;
 
 /**
  * Jetty specific exchange which keeps track of the the request and response.
- *
- * @version 
  */
 public class JettyContentExchange9 implements JettyContentExchange {
 
@@ -68,14 +66,14 @@ public class JettyContentExchange9 implements JettyContentExchange {
 
     private boolean supportRedirect;
 
-    public void init(Exchange exchange, JettyHttpBinding jettyBinding, 
+    public void init(Exchange exchange, JettyHttpBinding jettyBinding,
                      final HttpClient client, AsyncCallback callback) {
         this.exchange = exchange;
         this.jettyBinding = jettyBinding;
         this.client = client;
         this.callback = callback;
     }
-    
+
     protected void onRequestComplete() {
         LOG.trace("onRequestComplete");
         closeRequestContentSource();
@@ -135,15 +133,15 @@ public class JettyContentExchange9 implements JettyContentExchange {
             throw new IllegalStateException(e.getMessage(), e);
         }
     }
-    
+
     protected void closeRequestContentSource() {
         tryClose(this.request.getContent());
     }
-    
+
     private void tryClose(Object obj) {
         if (obj instanceof Closeable) {
             try {
-                ((Closeable)obj).close();
+                ((Closeable) obj).close();
             } catch (IOException e) {
                 // Ignore
             }
@@ -175,11 +173,11 @@ public class JettyContentExchange9 implements JettyContentExchange {
     public void setMethod(String method) {
         this.request.method(method);
     }
-    
+
     public void setTimeout(long timeout) {
         this.request.timeout(timeout, TimeUnit.MILLISECONDS);
     }
-    
+
     public void setURL(String url) {
         this.request = client.newRequest(url);
     }
@@ -194,7 +192,7 @@ public class JettyContentExchange9 implements JettyContentExchange {
     }
 
     public void setRequestContent(InputStream ins) {
-        this.request.content(new InputStreamContentProvider(ins), this.requestContentType);
       
+        this.request.content(new InputStreamContentProvider(ins), this.requestContentType);
     }
 
     public void addRequestHeader(String key, String s) {
@@ -236,14 +234,21 @@ public class JettyContentExchange9 implements JettyContentExchange {
     public byte[] getResponseContentBytes() {
         return responseContent;
     }
-    
-    public Map<String, Collection<String>> getResponseHeaders() {
-        final HttpFields f = response.getHeaders();
-        Map<String, Collection<String>> ret = new TreeMap<String, Collection<String>>(String.CASE_INSENSITIVE_ORDER);
-        for (String n : f.getFieldNamesCollection()) {
-            ret.put(n,  f.getValuesList(n));
+
+    private Map<String, Collection<String>> getFieldsAsMap(HttpFields fields)
{
+        final Map<String, Collection<String>> result = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
+        for (String name : fields.getFieldNamesCollection()) {
+            result.put(name, fields.getValuesList(name));
         }
-        return ret;
+        return result;
+    }
+
+    public Map<String, Collection<String>> getRequestHeaders() {
+        return getFieldsAsMap(request.getHeaders());
+    }
+
+    public Map<String, Collection<String>> getResponseHeaders() {
+        return getFieldsAsMap(response.getHeaders());
     }
 
     @Override


Mime
View raw message