camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acosent...@apache.org
Subject [1/2] camel git commit: CAMEL-10577 replace BufferingResponseListener with InputStreamResponseListener to avoid hardcoded 2MB limit
Date Thu, 12 Jan 2017 07:14:53 GMT
Repository: camel
Updated Branches:
  refs/heads/master bb1e8e75e -> 6eb5b8f4e


CAMEL-10577 replace BufferingResponseListener with InputStreamResponseListener to avoid hardcoded
2MB limit


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

Branch: refs/heads/master
Commit: 0c4c7ea1a464f0d61f039615fabdb7edde5fd031
Parents: bb1e8e7
Author: Kevin Earls <kevin@kevinearls.com>
Authored: Tue Jan 10 09:56:40 2017 +0100
Committer: Andrea Cosentino <ancosen@gmail.com>
Committed: Thu Jan 12 07:50:56 2017 +0100

----------------------------------------------------------------------
 .../component/jetty9/JettyContentExchange9.java | 26 +++++++++++++++++---
 1 file changed, 23 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/0c4c7ea1/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 f7cba4a..0730053 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
@@ -16,12 +16,14 @@
  */
 package org.apache.camel.component.jetty9;
 
+import java.io.ByteArrayOutputStream;
 import java.io.Closeable;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.UnsupportedEncodingException;
 import java.lang.reflect.Method;
 import java.net.MalformedURLException;
+import java.nio.ByteBuffer;
 import java.util.Collection;
 import java.util.Map;
 import java.util.TreeMap;
@@ -29,6 +31,8 @@ import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeoutException;
 
+import static javax.servlet.http.HttpServletResponse.SC_OK;
+
 import org.apache.camel.AsyncCallback;
 import org.apache.camel.CamelExchangeException;
 import org.apache.camel.Exchange;
@@ -39,14 +43,16 @@ import org.eclipse.jetty.client.HttpClient;
 import org.eclipse.jetty.client.api.Request;
 import org.eclipse.jetty.client.api.Response;
 import org.eclipse.jetty.client.api.Result;
-import org.eclipse.jetty.client.util.BufferingResponseListener;
 import org.eclipse.jetty.client.util.BytesContentProvider;
 import org.eclipse.jetty.client.util.InputStreamContentProvider;
+import org.eclipse.jetty.client.util.InputStreamResponseListener;
 import org.eclipse.jetty.client.util.StringContentProvider;
 import org.eclipse.jetty.http.HttpFields;
+import org.eclipse.jetty.util.Callback;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+
 /**
  * Jetty specific exchange which keeps track of the the request and response.
  */
@@ -214,14 +220,28 @@ public class JettyContentExchange9 implements JettyContentExchange {
             }
 
         };
-        BufferingResponseListener responseListener = new BufferingResponseListener() {
+
+        InputStreamResponseListener responseListener = new InputStreamResponseListener()
{
+            ByteArrayOutputStream baos = new ByteArrayOutputStream();
+
+            @Override
+            public void onContent(Response response, ByteBuffer content, Callback callback)
{
+                if (response.getStatus() != SC_OK) {
+                    LOG.warn("Response received {}: {}", response.getStatus(), response.getReason());
+                }
+                byte[] buffer = new byte[content.limit()];
+                content.get(buffer);
+                baos.write(buffer, 0, buffer.length);
+
+                callback.succeeded();
+            }
 
             @Override
             public void onComplete(Result result) {
                 if (result.isFailed()) {
                     doTaskCompleted(result.getFailure());
                 } else {
-                    onResponseComplete(result, getContent(), getMediaType());
+                    onResponseComplete(result, baos.toByteArray(), null);
                 }
             }
         };


Mime
View raw message