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:40 UTC

[1/2] camel git commit: CAMEL-10175: It was the other binding. This closes #1313

Repository: camel
Updated Branches:
  refs/heads/master bf11db863 -> 72a09b002


CAMEL-10175: It was the other binding. This closes #1313


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

Branch: refs/heads/master
Commit: 72a09b002ea3feea198aff3997f60c5b7be4ab44
Parents: 90e79e7
Author: Claus Ibsen <da...@apache.org>
Authored: Sat Nov 26 10:28:28 2016 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Nov 26 10:39:32 2016 +0100

----------------------------------------------------------------------
 .../camel/http/common/DefaultHttpBinding.java   | 30 ++++++++++++--------
 .../jetty/CamelContinuationServlet.java         |  2 --
 .../jetty/DefaultJettyHttpBinding.java          | 26 ++++++-----------
 .../component/jetty9/JettyHttpComponent9.java   |  6 ++--
 .../JettyAsyncContinuationTimeoutTest.java      |  2 +-
 ...ettyAsyncDefaultContinuationTimeoutTest.java |  2 +-
 6 files changed, 31 insertions(+), 37 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/72a09b00/components/camel-http-common/src/main/java/org/apache/camel/http/common/DefaultHttpBinding.java
----------------------------------------------------------------------
diff --git a/components/camel-http-common/src/main/java/org/apache/camel/http/common/DefaultHttpBinding.java b/components/camel-http-common/src/main/java/org/apache/camel/http/common/DefaultHttpBinding.java
index 96ed6b9..b64d1e7 100644
--- a/components/camel-http-common/src/main/java/org/apache/camel/http/common/DefaultHttpBinding.java
+++ b/components/camel-http-common/src/main/java/org/apache/camel/http/common/DefaultHttpBinding.java
@@ -32,6 +32,7 @@ import java.util.Iterator;
 import java.util.Locale;
 import java.util.Map;
 import java.util.TimeZone;
+import java.util.concurrent.TimeoutException;
 import javax.activation.DataHandler;
 import javax.servlet.ServletOutputStream;
 import javax.servlet.http.HttpServletRequest;
@@ -333,23 +334,28 @@ public class DefaultHttpBinding implements HttpBinding {
     }
 
     public void doWriteExceptionResponse(Throwable exception, HttpServletResponse response) throws IOException {
-        // 500 for internal server error
-        response.setStatus(500);
-
-        if (isTransferException()) {
-            // transfer the exception as a serialized java object
-            HttpHelper.writeObjectToServletResponse(response, exception);
-        } else {
-            // write stacktrace as plain text
+        if (exception instanceof TimeoutException) {
+            response.setStatus(HttpServletResponse.SC_GATEWAY_TIMEOUT);
             response.setContentType("text/plain");
-            PrintWriter pw = response.getWriter();
-            exception.printStackTrace(pw);
-            pw.flush();
+            response.getWriter().write("Timeout error");
+        } else {
+            response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+
+            if (isTransferException()) {
+                // transfer the exception as a serialized java object
+                HttpHelper.writeObjectToServletResponse(response, exception);
+            } else {
+                // write stacktrace as plain text
+                response.setContentType("text/plain");
+                PrintWriter pw = response.getWriter();
+                exception.printStackTrace(pw);
+                pw.flush();
+            }
         }
     }
 
     public void doWriteFaultResponse(Message message, HttpServletResponse response, Exchange exchange) throws IOException {
-        message.setHeader(Exchange.HTTP_RESPONSE_CODE, 500);
+        message.setHeader(Exchange.HTTP_RESPONSE_CODE, HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
         doWriteResponse(message, response, exchange);
     }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/72a09b00/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 b16bd16..c785689 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
@@ -142,9 +142,7 @@ public class CamelContinuationServlet extends CamelServlet {
                 // remember this id as expired
                 expiredExchanges.put(id, id);
                 log.warn("Continuation expired of exchangeId: {}", id);
-
                 consumer.getBinding().doWriteExceptionResponse(new TimeoutException(), response);
-
                 return;
             }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/72a09b00/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 f634a1b..e073fd5 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,24 +21,25 @@ 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.*;
+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.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 
+ * @version
  */
-public class DefaultJettyHttpBinding extends DefaultHttpBinding implements JettyHttpBinding {
+public class DefaultJettyHttpBinding implements JettyHttpBinding {
 
     private static final Logger LOG = LoggerFactory.getLogger(DefaultJettyHttpBinding.class);
     private HeaderFilterStrategy headerFilterStrategy = new HttpHeaderFilterStrategy();
@@ -50,7 +51,7 @@ public class DefaultJettyHttpBinding extends DefaultHttpBinding implements Jetty
 
     public DefaultJettyHttpBinding() {
     }
-    
+
     public void populateResponse(Exchange exchange, JettyContentExchange httpExchange) throws Exception {
         int responseCode = httpExchange.getResponseStatus();
 
@@ -77,17 +78,6 @@ public class DefaultJettyHttpBinding extends DefaultHttpBinding implements Jetty
         }
     }
 
-    @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;
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/72a09b00/components/camel-jetty9/src/main/java/org/apache/camel/component/jetty9/JettyHttpComponent9.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty9/src/main/java/org/apache/camel/component/jetty9/JettyHttpComponent9.java b/components/camel-jetty9/src/main/java/org/apache/camel/component/jetty9/JettyHttpComponent9.java
index 48f8e80..159da1f 100644
--- a/components/camel-jetty9/src/main/java/org/apache/camel/component/jetty9/JettyHttpComponent9.java
+++ b/components/camel-jetty9/src/main/java/org/apache/camel/component/jetty9/JettyHttpComponent9.java
@@ -73,7 +73,7 @@ public class JettyHttpComponent9 extends JettyHttpComponent {
                                                       JettyHttpEndpoint endpoint,
                                                       SslContextFactory sslcf) {
         try {
-            String hosto = endpoint.getHttpUri().getHost();
+            String host = endpoint.getHttpUri().getHost();
             int porto = endpoint.getPort();
             org.eclipse.jetty.server.HttpConfiguration httpConfig = new org.eclipse.jetty.server.HttpConfiguration();
             httpConfig.setSendServerVersion(endpoint.isSendServerVersion());
@@ -110,8 +110,8 @@ public class JettyHttpComponent9 extends JettyHttpComponent {
             connectionFactories.add(httpFactory);
             result.setConnectionFactories(connectionFactories);
             result.setPort(porto);
-            if (hosto != null) {
-                result.setHost(hosto);
+            if (host != null) {
+                result.setHost(host);
             }
             /*
             if (getSocketConnectorProperties() != null && !"https".equals(endpoint.getProtocol())) {

http://git-wip-us.apache.org/repos/asf/camel/blob/72a09b00/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/async/JettyAsyncContinuationTimeoutTest.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/async/JettyAsyncContinuationTimeoutTest.java b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/async/JettyAsyncContinuationTimeoutTest.java
index 3ae3aff..7d968f6 100644
--- a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/async/JettyAsyncContinuationTimeoutTest.java
+++ b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/async/JettyAsyncContinuationTimeoutTest.java
@@ -42,7 +42,7 @@ public class JettyAsyncContinuationTimeoutTest extends BaseJettyTest {
             long taken = watch.stop();
 
             HttpOperationFailedException cause = assertIsInstanceOf(HttpOperationFailedException.class, e.getCause());
-            assertEquals(503, cause.getStatusCode());
+            assertEquals(504, cause.getStatusCode());
 
             // should be approx 3-4 sec.
             assertTrue("Timeout should occur faster than " + taken, taken < 4500);

http://git-wip-us.apache.org/repos/asf/camel/blob/72a09b00/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/async/JettyAsyncDefaultContinuationTimeoutTest.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/async/JettyAsyncDefaultContinuationTimeoutTest.java b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/async/JettyAsyncDefaultContinuationTimeoutTest.java
index d608ce5..d5d57eb 100644
--- a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/async/JettyAsyncDefaultContinuationTimeoutTest.java
+++ b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/async/JettyAsyncDefaultContinuationTimeoutTest.java
@@ -46,7 +46,7 @@ public class JettyAsyncDefaultContinuationTimeoutTest extends BaseJettyTest {
             long taken = watch.stop();
 
             HttpOperationFailedException cause = assertIsInstanceOf(HttpOperationFailedException.class, e.getCause());
-            assertEquals(503, cause.getStatusCode());
+            assertEquals(504, cause.getStatusCode());
 
             // should be approx 30-34 sec.
             assertTrue("Timeout should occur faster than " + taken, taken < 34000);


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

Posted by da...@apache.org.
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;
     }