You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2016/11/26 09:39:41 UTC

[2/2] camel git commit: CAMEL-10175

CAMEL-10175

- Added functionality to handle continuation timeouts out of the box in camel-jetty-common component


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

Branch: refs/heads/master
Commit: 90e79e7e90d6cccc7143e7ff6abeb8ef28067cd9
Parents: bf11db8
Author: Nikhil Vibhav <ni...@gmail.com>
Authored: Sat Nov 26 01:15:39 2016 +0530
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Nov 26 10:39:32 2016 +0100

----------------------------------------------------------------------
 .../jetty/CamelContinuationServlet.java         |  5 ++++-
 .../jetty/DefaultJettyHttpBinding.java          | 22 ++++++++++++++------
 2 files changed, 20 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/90e79e7e/components/camel-jetty-common/src/main/java/org/apache/camel/component/jetty/CamelContinuationServlet.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty-common/src/main/java/org/apache/camel/component/jetty/CamelContinuationServlet.java b/components/camel-jetty-common/src/main/java/org/apache/camel/component/jetty/CamelContinuationServlet.java
index f1299f4..b16bd16 100644
--- a/components/camel-jetty-common/src/main/java/org/apache/camel/component/jetty/CamelContinuationServlet.java
+++ b/components/camel-jetty-common/src/main/java/org/apache/camel/component/jetty/CamelContinuationServlet.java
@@ -20,6 +20,7 @@ import java.io.IOException;
 import java.util.Iterator;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.TimeoutException;
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
@@ -141,7 +142,9 @@ public class CamelContinuationServlet extends CamelServlet {
                 // remember this id as expired
                 expiredExchanges.put(id, id);
                 log.warn("Continuation expired of exchangeId: {}", id);
-                response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
+
+                consumer.getBinding().doWriteExceptionResponse(new TimeoutException(), response);
+
                 return;
             }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/90e79e7e/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 42704ee..f634a1b 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
@@ -21,25 +21,24 @@ import java.io.InputStream;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.concurrent.TimeoutException;
 
 import org.apache.camel.Exchange;
 import org.apache.camel.Message;
 import org.apache.camel.RuntimeCamelException;
-import org.apache.camel.http.common.HttpConstants;
-import org.apache.camel.http.common.HttpHeaderFilterStrategy;
-import org.apache.camel.http.common.HttpHelper;
-import org.apache.camel.http.common.HttpOperationFailedException;
-import org.apache.camel.http.common.HttpProtocolHeaderFilterStrategy;
+import org.apache.camel.http.common.*;
 import org.apache.camel.spi.HeaderFilterStrategy;
 import org.apache.camel.util.IOHelper;
 import org.apache.camel.util.MessageHelper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import javax.servlet.http.HttpServletResponse;
+
 /**
  * @version 
  */
-public class DefaultJettyHttpBinding implements JettyHttpBinding {
+public class DefaultJettyHttpBinding extends DefaultHttpBinding implements JettyHttpBinding {
 
     private static final Logger LOG = LoggerFactory.getLogger(DefaultJettyHttpBinding.class);
     private HeaderFilterStrategy headerFilterStrategy = new HttpHeaderFilterStrategy();
@@ -78,6 +77,17 @@ public class DefaultJettyHttpBinding implements JettyHttpBinding {
         }
     }
 
+    @Override
+    public void doWriteExceptionResponse(Throwable exception, HttpServletResponse response) throws IOException {
+        // Handle continuation timeout
+        if (exception instanceof TimeoutException) {
+            response.setStatus(HttpServletResponse.SC_GATEWAY_TIMEOUT);
+            response.getWriter().write("Continuation timed out...");
+        } else {
+            super.doWriteExceptionResponse(exception, response);
+        }
+    }
+
     public HeaderFilterStrategy getHeaderFilterStrategy() {
         return headerFilterStrategy;
     }