You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2014/12/24 12:35:47 UTC
[1/2] camel git commit: CAMEL-8179 Support to set the ErrorHandler
from the JettyHttpComponent
Repository: camel
Updated Branches:
refs/heads/master 28b49e84e -> d0fd80340
CAMEL-8179 Support to set the ErrorHandler from the JettyHttpComponent
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/d0fd8034
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/d0fd8034
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/d0fd8034
Branch: refs/heads/master
Commit: d0fd80340f20e9aa7fe55b241060394fed74cef1
Parents: 49f937d
Author: Willem Jiang <wi...@gmail.com>
Authored: Wed Dec 24 18:59:14 2014 +0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Wed Dec 24 19:35:14 2014 +0800
----------------------------------------------------------------------
.../camel/component/jetty/JettyHttpComponent.java | 15 +++++++++++++--
.../camel/component/jetty/JettyHandle404Test.java | 12 ++++++++++++
2 files changed, 25 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/d0fd8034/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java b/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
index 5c032a8..42eb16f 100644
--- a/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
+++ b/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
@@ -124,6 +124,7 @@ public class JettyHttpComponent extends HttpComponent implements RestConsumerFac
protected Integer responseBufferSize;
protected Integer responseHeaderSize;
protected String proxyHost;
+ protected ErrorHandler errorHandler;
private Integer proxyPort;
public JettyHttpComponent() {
@@ -498,6 +499,14 @@ public class JettyHttpComponent extends HttpComponent implements RestConsumerFac
}
+ public ErrorHandler getErrorHandler() {
+ return errorHandler;
+ }
+
+ public void setErrorHandler(ErrorHandler errorHandler) {
+ this.errorHandler = errorHandler;
+ }
+
protected Connector getConnector(Server server, JettyHttpEndpoint endpoint) {
Connector connector;
if ("https".equals(endpoint.getProtocol())) {
@@ -1213,8 +1222,10 @@ public class JettyHttpComponent extends HttpComponent implements RestConsumerFac
}
ContextHandlerCollection collection = new ContextHandlerCollection();
s.setHandler(collection);
-
- if (!Server.getVersion().startsWith("8")) {
+ // setup the error handler if it set to Jetty component
+ if (getErrorHandler() != null) {
+ s.addBean(getErrorHandler());
+ } else if (!Server.getVersion().startsWith("8")) {
//need an error handler that won't leak information about the exception
//back to the client.
ErrorHandler eh = new ErrorHandler() {
http://git-wip-us.apache.org/repos/asf/camel/blob/d0fd8034/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyHandle404Test.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyHandle404Test.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyHandle404Test.java
index c017b39..12282de 100644
--- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyHandle404Test.java
+++ b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyHandle404Test.java
@@ -16,6 +16,7 @@
*/
package org.apache.camel.component.jetty;
+import org.apache.camel.Component;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;
@@ -45,12 +46,23 @@ public class JettyHandle404Test extends BaseJettyTest {
assertMockEndpointsSatisfied();
}
+
+ @Test
+ public void testCustomerErrorHandler() throws Exception {
+ String response = template.requestBody("http://localhost:{{port}}/myserver1?throwExceptionOnFailure=false", null, String.class);
+ // look for the error message which is sent by MyErrorHandler
+ assertTrue("Get a wrong error message", response.indexOf("MyErrorHandler") > 0);
+ }
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
+ // setup the jetty component with the customx error handler
+ JettyHttpComponent jettyComponent = (JettyHttpComponent)context.getComponent("jetty");
+ jettyComponent.setErrorHandler(new MyErrorHandler());
+
// disable error handling
errorHandler(noErrorHandler());
[2/2] camel git commit: CAMEL-8173 Polished the code of
TimeoutInflightRepository
Posted by ni...@apache.org.
CAMEL-8173 Polished the code of TimeoutInflightRepository
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/49f937d7
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/49f937d7
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/49f937d7
Branch: refs/heads/master
Commit: 49f937d79cb507d23a33a3d41c6f8809695bde31
Parents: 28b49e8
Author: Willem Jiang <wi...@gmail.com>
Authored: Wed Dec 24 18:54:53 2014 +0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Wed Dec 24 19:35:14 2014 +0800
----------------------------------------------------------------------
.../java/org/apache/camel/impl/TimeoutInflightRepository.java | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/49f937d7/camel-core/src/main/java/org/apache/camel/impl/TimeoutInflightRepository.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/TimeoutInflightRepository.java b/camel-core/src/main/java/org/apache/camel/impl/TimeoutInflightRepository.java
index b3ad72e..64a58c4 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/TimeoutInflightRepository.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/TimeoutInflightRepository.java
@@ -37,6 +37,7 @@ import org.slf4j.LoggerFactory;
public class TimeoutInflightRepository extends ServiceSupport implements InflightRepository {
private static final Logger LOG = LoggerFactory.getLogger(TimeoutInflightRepository.class);
private static final String INFLIGHT_TIME_STAMP = "CamelInflightTimeStamp";
+ private static final String TIMEOUT_EXCHANGE_PROCESSED = "CamelTimeoutExchangeProcessed";
private ExchangeFormatter exchangeFormatter;
private final Map<String, Exchange> inflightExchanges = new ConcurrentHashMap<String, Exchange>();
private long waitTime = 60 * 1000;
@@ -85,7 +86,7 @@ public class TimeoutInflightRepository extends ServiceSupport implements Infligh
@Override
public void remove(Exchange exchange) {
- exchange.removeProperties(INFLIGHT_TIME_STAMP);
+ exchange.removeProperty(INFLIGHT_TIME_STAMP);
inflightExchanges.remove(exchange.getExchangeId());
}
@@ -185,9 +186,11 @@ public class TimeoutInflightRepository extends ServiceSupport implements Infligh
for (Exchange exchange : inflightExchanges.values()) {
// check if the exchange is timeout
long timeStamp = exchange.getProperty(INFLIGHT_TIME_STAMP, Long.class);
+ Boolean processed = exchange.getProperty(TIMEOUT_EXCHANGE_PROCESSED, Boolean.FALSE, Boolean.class);
long processingTime = System.currentTimeMillis() - timeStamp;
- if (processingTime > timeout) {
+ if (!processed && processingTime > timeout) {
processTimeoutExchange(exchange, processingTime);
+ exchange.setProperty(TIMEOUT_EXCHANGE_PROCESSED, Boolean.TRUE);
}
}
try {