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/04/22 07:00:54 UTC

[camel] branch main updated (498a757 -> c85ca13)

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 498a757  Sync deps
     new ac64622  CAMEL-16494: After VetoCamelContextStartException CamelContext instance broken forever
     new 9ed97ca  CAMEL-16535: Add option to dump routes as XML on startup
     new a3418693 CAMEL-16535: Add option to dump routes as XML on startup
     new c85ca13  CAMEL-16494: After VetoCamelContextStartException CamelContext instance broken forever

The 4 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:
 .../apache/camel/support/service/BaseService.java  |   4 +
 .../camel/impl/engine/AbstractCamelContext.java    |  49 ++++---
 .../xml/AbstractCamelContextFactoryBeanTest.java   |   3 +-
 .../engine/VetoCamelContextStartExceptionTest.java | 155 +++++++++++++++++++++
 4 files changed, 193 insertions(+), 18 deletions(-)
 create mode 100644 core/camel-core/src/test/java/org/apache/camel/impl/engine/VetoCamelContextStartExceptionTest.java

[camel] 02/04: CAMEL-16535: Add option to dump routes as XML on startup

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 9ed97cad28baa8d1ddfab937b73984ada4bef3a0
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu Apr 22 08:34:34 2021 +0200

    CAMEL-16535: Add option to dump routes as XML on startup
---
 .../main/java/org/apache/camel/impl/engine/AbstractCamelContext.java    | 1 -
 .../org/apache/camel/core/xml/AbstractCamelContextFactoryBeanTest.java  | 2 +-
 2 files changed, 1 insertion(+), 2 deletions(-)

diff --git a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
index 6f35049..285cef6 100644
--- a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
+++ b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
@@ -4848,7 +4848,6 @@ public abstract class AbstractCamelContext extends BaseService
         return "CamelContext(" + getName() + ")";
     }
 
-
     protected void failOnStartup(Exception e) {
         if (e instanceof VetoCamelContextStartException) {
             VetoCamelContextStartException vetoException = (VetoCamelContextStartException) e;
diff --git a/core/camel-core-xml/src/test/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBeanTest.java b/core/camel-core-xml/src/test/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBeanTest.java
index 4abb372..8d162b6 100644
--- a/core/camel-core-xml/src/test/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBeanTest.java
+++ b/core/camel-core-xml/src/test/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBeanTest.java
@@ -89,7 +89,7 @@ public class AbstractCamelContextFactoryBeanTest {
             asList("{{getStreamCache}}", "{{getDebug}}", "{{getTrace}}", "{{getBacklogTrace}}",
                     "{{getMessageHistory}}", "{{getLogMask}}", "{{getLogExhaustedMessageBody}}", "{{getHandleFault}}",
                     "{{getCaseInsensitiveHeaders}}",
-                    "{{getAutoStartup}}", "{{getUseMDCLogging}}", "{{getUseDataType}}", "{{getUseBreadcrumb}}",
+                    "{{getAutoStartup}}", "{{getDumpRoutes}}", "{{getUseMDCLogging}}", "{{getUseDataType}}", "{{getUseBreadcrumb}}",
                     "{{getBeanPostProcessorEnabled}}", "{{getAllowUseOriginalMessage}}",
                     "{{getLoadTypeConverters}}", "{{getTypeConverterStatisticsEnabled}}",
                     "{{getInflightRepositoryBrowseEnabled}}"));

[camel] 04/04: CAMEL-16494: After VetoCamelContextStartException CamelContext instance broken forever

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 c85ca132cda7fff921642c30a95d1ccd82acbe02
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu Apr 22 08:43:55 2021 +0200

    CAMEL-16494: After VetoCamelContextStartException CamelContext instance broken forever
---
 .../impl/engine/VetoCamelContextStartExceptionTest.java  | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/core/camel-core/src/test/java/org/apache/camel/impl/engine/VetoCamelContextStartExceptionTest.java b/core/camel-core/src/test/java/org/apache/camel/impl/engine/VetoCamelContextStartExceptionTest.java
index 9b27033..0dcd006 100644
--- a/core/camel-core/src/test/java/org/apache/camel/impl/engine/VetoCamelContextStartExceptionTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/impl/engine/VetoCamelContextStartExceptionTest.java
@@ -1,3 +1,19 @@
+/*
+ * 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.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 package org.apache.camel.impl.engine;
 
 import org.apache.camel.CamelContext;

[camel] 03/04: CAMEL-16535: Add option to dump routes as XML on startup

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 a3418693869bbcba311d043179ccdb960c6572e9
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu Apr 22 08:36:48 2021 +0200

    CAMEL-16535: Add option to dump routes as XML on startup
---
 .../org/apache/camel/core/xml/AbstractCamelContextFactoryBeanTest.java | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/core/camel-core-xml/src/test/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBeanTest.java b/core/camel-core-xml/src/test/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBeanTest.java
index 8d162b6..e6b131d 100644
--- a/core/camel-core-xml/src/test/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBeanTest.java
+++ b/core/camel-core-xml/src/test/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBeanTest.java
@@ -89,7 +89,8 @@ public class AbstractCamelContextFactoryBeanTest {
             asList("{{getStreamCache}}", "{{getDebug}}", "{{getTrace}}", "{{getBacklogTrace}}",
                     "{{getMessageHistory}}", "{{getLogMask}}", "{{getLogExhaustedMessageBody}}", "{{getHandleFault}}",
                     "{{getCaseInsensitiveHeaders}}",
-                    "{{getAutoStartup}}", "{{getDumpRoutes}}", "{{getUseMDCLogging}}", "{{getUseDataType}}", "{{getUseBreadcrumb}}",
+                    "{{getAutoStartup}}", "{{getDumpRoutes}}", "{{getUseMDCLogging}}", "{{getUseDataType}}",
+                    "{{getUseBreadcrumb}}",
                     "{{getBeanPostProcessorEnabled}}", "{{getAllowUseOriginalMessage}}",
                     "{{getLoadTypeConverters}}", "{{getTypeConverterStatisticsEnabled}}",
                     "{{getInflightRepositoryBrowseEnabled}}"));

[camel] 01/04: CAMEL-16494: After VetoCamelContextStartException CamelContext instance broken forever

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 ac64622f8d934648379543e6c773cebcafd76b6a
Author: Акинцев Валерий Андреевич <ak...@gazprom-neft.ru>
AuthorDate: Wed Apr 21 22:28:03 2021 +0300

    CAMEL-16494: After VetoCamelContextStartException CamelContext instance broken forever
---
 .../apache/camel/support/service/BaseService.java  |   4 +
 .../camel/impl/engine/AbstractCamelContext.java    |  50 +++++---
 .../engine/VetoCamelContextStartExceptionTest.java | 139 +++++++++++++++++++++
 3 files changed, 176 insertions(+), 17 deletions(-)

diff --git a/core/camel-api/src/main/java/org/apache/camel/support/service/BaseService.java b/core/camel-api/src/main/java/org/apache/camel/support/service/BaseService.java
index 8cfc17d..6ee434c 100644
--- a/core/camel-api/src/main/java/org/apache/camel/support/service/BaseService.java
+++ b/core/camel-api/src/main/java/org/apache/camel/support/service/BaseService.java
@@ -109,6 +109,10 @@ public abstract class BaseService {
                 return;
             }
             init();
+            if (status == FAILED) {
+                LOG.trace("Init failed");
+                return;
+            }
             try (AutoCloseable ignored = doLifecycleChange()) {
                 status = STARTING;
                 LOG.trace("Starting service: {}", this);
diff --git a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
index b73bb94..6f35049 100644
--- a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
+++ b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
@@ -2476,18 +2476,21 @@ public abstract class AbstractCamelContext extends BaseService
 
     @Override
     public void init() {
-        super.init();
+        try {
+            super.init();
+        } catch (RuntimeCamelException e) {
+            if (e.getCause() != null && e.getCause() instanceof VetoCamelContextStartException) {
+                vetoed = (VetoCamelContextStartException) e.getCause();
+            } else {
+                throw e;
+            }
+        }
 
         // was the initialization vetoed?
         if (vetoed != null) {
-            if (vetoed.isRethrowException()) {
-                throw RuntimeCamelException.wrapRuntimeException(vetoed);
-            } else {
-                LOG.info("CamelContext ({}) vetoed to not initialize due to {}", getName(), vetoed.getMessage());
-                // swallow exception and change state of this camel context to stopped
-                fail(vetoed);
-                return;
-            }
+            LOG.info("CamelContext ({}) vetoed to not initialize due to {}", getName(), vetoed.getMessage());
+            failOnStartup(vetoed);
+            return;
         }
     }
 
@@ -2502,14 +2505,10 @@ public abstract class AbstractCamelContext extends BaseService
 
         // did the start veto?
         if (vetoed != null) {
-            if (vetoed.isRethrowException()) {
-                throw RuntimeCamelException.wrapRuntimeException(vetoed);
-            } else {
-                LOG.info("CamelContext ({}) vetoed to not start due to {}", getName(), vetoed.getMessage());
-                // swallow exception and change state of this camel context to stopped
-                stop();
-                return;
-            }
+            LOG.info("CamelContext ({}) vetoed to not start due to {}", getName(), vetoed.getMessage());
+            failOnStartup(vetoed);
+            stop();
+            return;
         }
 
         for (LifecycleStrategy strategy : lifecycleStrategies) {
@@ -2624,6 +2623,8 @@ public abstract class AbstractCamelContext extends BaseService
     public void doInit() throws Exception {
         StopWatch watch = new StopWatch();
 
+        vetoed = null;
+
         StartupStep step = startupStepRecorder.beginStep(CamelContext.class, null, "Init CamelContext");
 
         // init the route controller
@@ -4847,6 +4848,21 @@ public abstract class AbstractCamelContext extends BaseService
         return "CamelContext(" + getName() + ")";
     }
 
+
+    protected void failOnStartup(Exception e) {
+        if (e instanceof VetoCamelContextStartException) {
+            VetoCamelContextStartException vetoException = (VetoCamelContextStartException) e;
+            if (vetoException.isRethrowException()) {
+                fail(e);
+            } else {
+                // swallow exception and change state of this camel context to stopped
+                status = FAILED;
+            }
+        } else {
+            fail(e);
+        }
+    }
+
     protected abstract ExchangeFactory createExchangeFactory();
 
     protected abstract ExchangeFactoryManager createExchangeFactoryManager();
diff --git a/core/camel-core/src/test/java/org/apache/camel/impl/engine/VetoCamelContextStartExceptionTest.java b/core/camel-core/src/test/java/org/apache/camel/impl/engine/VetoCamelContextStartExceptionTest.java
new file mode 100644
index 0000000..9b27033
--- /dev/null
+++ b/core/camel-core/src/test/java/org/apache/camel/impl/engine/VetoCamelContextStartExceptionTest.java
@@ -0,0 +1,139 @@
+package org.apache.camel.impl.engine;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.ServiceStatus;
+import org.apache.camel.VetoCamelContextStartException;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.support.LifecycleStrategySupport;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class VetoCamelContextStartExceptionTest {
+
+    @Test
+    public void testVetoOnStarting() {
+        CamelContext context = new DefaultCamelContext();
+        context.addLifecycleStrategy(
+                new LifecycleStrategySupport() {
+                    @Override
+                    public void onContextStarting(CamelContext context) throws VetoCamelContextStartException {
+                        throw new VetoCamelContextStartException("Veto on starting", context, true);
+                    }
+                });
+
+        Throwable throwable = assertThrows(Throwable.class, context::start);
+
+        assertTrue(context.isVetoStarted());
+        assertEquals(ServiceStatus.Stopped, context.getStatus());
+        assertEquals("org.apache.camel.VetoCamelContextStartException: Veto on starting", throwable.getMessage());
+    }
+
+    @Test
+    public void testVetoOnStartingWithoutRethrow() {
+        CamelContext context = new DefaultCamelContext();
+        context.addLifecycleStrategy(
+                new LifecycleStrategySupport() {
+                    @Override
+                    public void onContextStarting(CamelContext context) throws VetoCamelContextStartException {
+                        throw new VetoCamelContextStartException("Veto on starting", context, false);
+                    }
+                });
+        context.start();
+        assertTrue(context.isVetoStarted());
+        assertEquals(ServiceStatus.Stopped, context.getStatus());
+    }
+
+    @Test
+    public void testVetoOnInitializing() {
+        CamelContext context = new DefaultCamelContext();
+        context.addLifecycleStrategy(
+                new LifecycleStrategySupport() {
+                    @Override
+                    public void onContextInitializing(CamelContext context) throws VetoCamelContextStartException {
+                        throw new VetoCamelContextStartException("Veto on initializing", context, true);
+                    }
+                });
+
+        Throwable throwable = assertThrows(Throwable.class, context::start);
+        assertTrue(context.isVetoStarted());
+        assertEquals(ServiceStatus.Stopped, context.getStatus());
+        assertEquals("org.apache.camel.VetoCamelContextStartException: Veto on initializing", throwable.getMessage());
+    }
+
+    @Test
+    public void testVetoOnInitializingWithoutRethrow() {
+        CamelContext context = new DefaultCamelContext();
+        context.addLifecycleStrategy(
+                new LifecycleStrategySupport() {
+                    @Override
+                    public void onContextInitializing(CamelContext context) throws VetoCamelContextStartException {
+                        throw new VetoCamelContextStartException("Veto on initializing", context, false);
+                    }
+                });
+        context.start();
+        assertTrue(context.isVetoStarted());
+        assertEquals(ServiceStatus.Stopped, context.getStatus());
+    }
+
+    @Test
+    public void testVetoOnInitialized() {
+        CamelContext context = new DefaultCamelContext();
+        context.addLifecycleStrategy(
+                new LifecycleStrategySupport() {
+                    @Override
+                    public void onContextInitialized(CamelContext context) throws VetoCamelContextStartException {
+                        throw new VetoCamelContextStartException("Veto on initialized", context, true);
+                    }
+                });
+
+        Throwable throwable = assertThrows(Throwable.class, context::start);
+        assertTrue(context.isVetoStarted());
+        assertEquals(ServiceStatus.Stopped, context.getStatus());
+        assertEquals("org.apache.camel.VetoCamelContextStartException: Veto on initialized", throwable.getMessage());
+    }
+
+    @Test
+    public void testVetoOnInitializedWithoutRethrow() {
+        CamelContext context = new DefaultCamelContext();
+        context.addLifecycleStrategy(
+                new LifecycleStrategySupport() {
+                    @Override
+                    public void onContextInitialized(CamelContext context) throws VetoCamelContextStartException {
+                        throw new VetoCamelContextStartException("Veto on initialized", context, false);
+                    }
+                });
+        context.start();
+        assertTrue(context.isVetoStarted());
+        assertEquals(ServiceStatus.Stopped, context.getStatus());
+    }
+
+    @Test
+    public void testVetoReset() throws Exception {
+        try (CamelContext context = new DefaultCamelContext()) {
+            boolean[] needThrowVeto = new boolean[] { true };
+            context.addLifecycleStrategy(
+                    new LifecycleStrategySupport() {
+                        @Override
+                        public void onContextInitialized(CamelContext context) throws VetoCamelContextStartException {
+                            if (needThrowVeto[0]) {
+                                needThrowVeto[0] = false;
+                                throw new VetoCamelContextStartException("Veto on initialized", context, false);
+                            }
+                        }
+                    });
+
+            context.start();
+            assertTrue(context.isVetoStarted());
+            assertEquals(ServiceStatus.Stopped, context.getStatus());
+
+            context.start();
+            assertFalse(context.isVetoStarted());
+            assertEquals(ServiceStatus.Started, context.getStatus());
+        }
+
+    }
+}