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 2021/11/18 10:03:02 UTC

[camel] branch main updated (4ccbcde -> d8999df)

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a change to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git.


    from 4ccbcde  CAMEL-16656: camel-core - ResourceReloader SPI - Allow to reload on changes
     new 4596aa0  CAMEL-17205: camel-core - Error handler with custom prepare processor should have access to failure route id
     new d8999df  CAMEL-16656: camel-core - ResourceReloader SPI - Allow to reload on changes

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../errorhandler/RedeliveryErrorHandler.java       | 29 ++++++++++++++--------
 .../DefaultErrorHandlerOnPrepareTest.java          |  6 ++++-
 .../support/FileWatcherResourceReloadStrategy.java |  6 ++---
 .../support/ResourceReloadStrategySupport.java     | 14 ++++++++---
 .../camel/support/RouteWatcherReloadStrategy.java  |  2 +-
 5 files changed, 39 insertions(+), 18 deletions(-)

[camel] 01/02: CAMEL-17205: camel-core - Error handler with custom prepare processor should have access to failure route id

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 4596aa0a04067c06e0045360bd3698c5f478130a
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu Nov 18 10:52:30 2021 +0100

    CAMEL-17205: camel-core - Error handler with custom prepare processor should have access to failure route id
---
 .../errorhandler/RedeliveryErrorHandler.java       | 29 ++++++++++++++--------
 .../DefaultErrorHandlerOnPrepareTest.java          |  6 ++++-
 2 files changed, 24 insertions(+), 11 deletions(-)

diff --git a/core/camel-core-processor/src/main/java/org/apache/camel/processor/errorhandler/RedeliveryErrorHandler.java b/core/camel-core-processor/src/main/java/org/apache/camel/processor/errorhandler/RedeliveryErrorHandler.java
index 385fac4..d418a6a 100644
--- a/core/camel-core-processor/src/main/java/org/apache/camel/processor/errorhandler/RedeliveryErrorHandler.java
+++ b/core/camel-core-processor/src/main/java/org/apache/camel/processor/errorhandler/RedeliveryErrorHandler.java
@@ -558,7 +558,7 @@ public abstract class RedeliveryErrorHandler extends ErrorHandlerSupport
             ee.setException(exchange.getProperty(ExchangePropertyKey.EXCEPTION_CAUGHT, Exception.class));
             // and put failure endpoint back as well
             ee.setProperty(ExchangePropertyKey.FAILURE_ENDPOINT, ee.getProperty(ExchangePropertyKey.TO_ENDPOINT));
-            // and store the route id so we know in which route we failed
+            // and store the route id, so we know in which route we failed
             Route rc = ExchangeHelper.getRoute(ee);
             if (rc != null) {
                 ee.setProperty(ExchangePropertyKey.FAILURE_ROUTE_ID, rc.getRouteId());
@@ -1145,6 +1145,15 @@ public abstract class RedeliveryErrorHandler extends ErrorHandlerSupport
                 // reset cached streams so they can be read again
                 MessageHelper.resetStreamCache(exchange.getIn());
 
+                // store the last to endpoint as the failure endpoint
+                exchange.setProperty(ExchangePropertyKey.FAILURE_ENDPOINT,
+                        exchange.getProperty(ExchangePropertyKey.TO_ENDPOINT));
+                // and store the route id, so we know in which route we failed
+                Route rc = ExchangeHelper.getRoute(exchange);
+                if (rc != null) {
+                    exchange.setProperty(ExchangePropertyKey.FAILURE_ROUTE_ID, rc.getRouteId());
+                }
+
                 // invoke custom on prepare
                 if (onPrepareProcessor != null) {
                     try {
@@ -1158,15 +1167,6 @@ public abstract class RedeliveryErrorHandler extends ErrorHandlerSupport
 
                 LOG.trace("Failure processor {} is processing Exchange: {}", processor, exchange);
 
-                // store the last to endpoint as the failure endpoint
-                exchange.setProperty(ExchangePropertyKey.FAILURE_ENDPOINT,
-                        exchange.getProperty(ExchangePropertyKey.TO_ENDPOINT));
-                // and store the route id so we know in which route we failed
-                Route rc = ExchangeHelper.getRoute(exchange);
-                if (rc != null) {
-                    exchange.setProperty(ExchangePropertyKey.FAILURE_ROUTE_ID, rc.getRouteId());
-                }
-
                 // fire event as we had a failure processor to handle it, which there is a event for
                 final boolean deadLetterChannel = processor == deadLetter;
 
@@ -1210,6 +1210,15 @@ public abstract class RedeliveryErrorHandler extends ErrorHandlerSupport
                 });
             } else {
                 try {
+                    // store the last to endpoint as the failure endpoint
+                    exchange.setProperty(ExchangePropertyKey.FAILURE_ENDPOINT,
+                            exchange.getProperty(ExchangePropertyKey.TO_ENDPOINT));
+                    // and store the route id, so we know in which route we failed
+                    Route rc = ExchangeHelper.getRoute(exchange);
+                    if (rc != null) {
+                        exchange.setProperty(ExchangePropertyKey.FAILURE_ROUTE_ID, rc.getRouteId());
+                    }
+
                     // invoke custom on prepare
                     if (onPrepareProcessor != null) {
                         try {
diff --git a/core/camel-core/src/test/java/org/apache/camel/processor/DefaultErrorHandlerOnPrepareTest.java b/core/camel-core/src/test/java/org/apache/camel/processor/DefaultErrorHandlerOnPrepareTest.java
index 3bff5fe..82ce338 100644
--- a/core/camel-core/src/test/java/org/apache/camel/processor/DefaultErrorHandlerOnPrepareTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/processor/DefaultErrorHandlerOnPrepareTest.java
@@ -38,6 +38,7 @@ public class DefaultErrorHandlerOnPrepareTest extends ContextTestSupport {
         assertTrue(out.isFailed(), "Should be failed");
         assertIsInstanceOf(IllegalArgumentException.class, out.getException());
         assertEquals("Forced", out.getIn().getHeader("FailedBecause"));
+        assertEquals("foo", out.getIn().getHeader("FailedAtRoute"));
     }
 
     @Override
@@ -47,7 +48,9 @@ public class DefaultErrorHandlerOnPrepareTest extends ContextTestSupport {
             public void configure() throws Exception {
                 errorHandler(defaultErrorHandler().onPrepareFailure(new MyPrepareProcessor()));
 
-                from("direct:start").log("Incoming ${body}").throwException(new IllegalArgumentException("Forced"));
+                from("direct:start")
+                        .routeId("foo")
+                        .log("Incoming ${body}").throwException(new IllegalArgumentException("Forced"));
             }
         };
     }
@@ -58,6 +61,7 @@ public class DefaultErrorHandlerOnPrepareTest extends ContextTestSupport {
         public void process(Exchange exchange) throws Exception {
             Exception cause = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Exception.class);
             exchange.getIn().setHeader("FailedBecause", cause.getMessage());
+            exchange.getIn().setHeader("FailedAtRoute", exchange.getProperty(Exchange.FAILURE_ROUTE_ID, String.class));
         }
     }
 }

[camel] 02/02: CAMEL-16656: camel-core - ResourceReloader SPI - Allow to reload on changes

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git

commit d8999df46f5b0c4500b4a33c743a1527cd1d5cd0
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu Nov 18 10:55:28 2021 +0100

    CAMEL-16656: camel-core - ResourceReloader SPI - Allow to reload on changes
---
 .../camel/support/FileWatcherResourceReloadStrategy.java   |  6 +++---
 .../camel/support/ResourceReloadStrategySupport.java       | 14 +++++++++++---
 .../apache/camel/support/RouteWatcherReloadStrategy.java   |  2 +-
 3 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/core/camel-support/src/main/java/org/apache/camel/support/FileWatcherResourceReloadStrategy.java b/core/camel-support/src/main/java/org/apache/camel/support/FileWatcherResourceReloadStrategy.java
index 26f092d..427cf57 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/FileWatcherResourceReloadStrategy.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/FileWatcherResourceReloadStrategy.java
@@ -1,4 +1,4 @@
-/**
+/*
  * Licensed to the Apache Software Foundation (ASF) under one or more
  * contributor license agreements.  See the NOTICE file distributed with
  * this work for additional information regarding copyright ownership.
@@ -274,9 +274,9 @@ public class FileWatcherResourceReloadStrategy extends ResourceReloadStrategySup
                                 // must use file resource loader as we cannot load from classpath
                                 Resource resource = ecc.getResourceLoader().resolveResource("file:" + name);
                                 getResourceReload().onReload(name, resource);
-                                succeeded++;
+                                incSucceededCounter();
                             } catch (Exception e) {
-                                failed++;
+                                incFailedCounter();
                                 LOG.warn("Error reloading routes from file: " + name + " due " + e.getMessage()
                                          + ". This exception is ignored.",
                                         e);
diff --git a/core/camel-support/src/main/java/org/apache/camel/support/ResourceReloadStrategySupport.java b/core/camel-support/src/main/java/org/apache/camel/support/ResourceReloadStrategySupport.java
index 7cf27b7..a7db337 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/ResourceReloadStrategySupport.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/ResourceReloadStrategySupport.java
@@ -1,4 +1,4 @@
-/**
+/*
  * Licensed to the Apache Software Foundation (ASF) under one or more
  * contributor license agreements.  See the NOTICE file distributed with
  * this work for additional information regarding copyright ownership.
@@ -30,8 +30,8 @@ public abstract class ResourceReloadStrategySupport extends ServiceSupport imple
 
     private ResourceReload resourceReload;
     private CamelContext camelContext;
-    protected int succeeded;
-    protected int failed;
+    private int succeeded;
+    private int failed;
 
     @Override
     public CamelContext getCamelContext() {
@@ -77,6 +77,14 @@ public abstract class ResourceReloadStrategySupport extends ServiceSupport imple
         failed = 0;
     }
 
+    protected void incSucceededCounter() {
+        succeeded++;
+    }
+
+    protected void incFailedCounter() {
+        failed++;
+    }
+
     @Override
     protected void doStart() throws Exception {
         // noop
diff --git a/core/camel-support/src/main/java/org/apache/camel/support/RouteWatcherReloadStrategy.java b/core/camel-support/src/main/java/org/apache/camel/support/RouteWatcherReloadStrategy.java
index baf633c..8251de0 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/RouteWatcherReloadStrategy.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/RouteWatcherReloadStrategy.java
@@ -1,4 +1,4 @@
-/**
+/*
  * Licensed to the Apache Software Foundation (ASF) under one or more
  * contributor license agreements.  See the NOTICE file distributed with
  * this work for additional information regarding copyright ownership.