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
The following commit(s) were added to refs/heads/main by this push: new 6fbdcacde4d CAMEL-22145: camel-core: Include source location when throwing failed to create or start route exception so end user can better known which file has the problem. 6fbdcacde4d is described below commit 6fbdcacde4df467bb27e77a621aceafdecb55775 Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Fri Jun 13 13:28:38 2025 +0200 CAMEL-22145: camel-core: Include source location when throwing failed to create or start route exception so end user can better known which file has the problem. --- .../apache/camel/FailedToCreateRouteException.java | 28 +++++++++++++++------- .../apache/camel/FailedToStartRouteException.java | 19 +++++++++++++-- .../impl/engine/InternalRouteStartupManager.java | 8 ++++--- .../org/apache/camel/impl/engine/RouteService.java | 17 +++++++------ .../org/apache/camel/impl/DefaultCamelContext.java | 2 +- .../java/org/apache/camel/impl/DefaultModel.java | 2 +- .../camel/model/ProcessorDefinitionHelper.java | 3 +++ .../org/apache/camel/reifier/RouteReifier.java | 21 ++++++++++++---- .../direct/DirectEndpointRouteInlinedTest.java | 2 +- .../seda/SedaConcurrentConsumersNPEIssueTest.java | 4 ++-- .../GracefulShutdownNoAutoStartOrderClashTest.java | 2 +- .../org/apache/camel/issues/RouteIdClashTest.java | 2 +- .../model/StartingRoutesErrorReportedTest.java | 12 ++++++---- .../org/apache/camel/main/RoutesConfigurer.java | 2 +- .../java/org/apache/camel/main/MainScan3Test.java | 2 +- .../camel/management/ManagedDuplicateIdTest.java | 2 +- .../org/apache/camel/support/LoggerHelper.java | 18 ++++++++++++++ .../camel/dsl/jbang/core/common/RuntimeType.java | 4 ++-- .../camel/dsl/jbang/it/CustomJarsITCase.java | 2 +- 19 files changed, 107 insertions(+), 45 deletions(-) diff --git a/core/camel-api/src/main/java/org/apache/camel/FailedToCreateRouteException.java b/core/camel-api/src/main/java/org/apache/camel/FailedToCreateRouteException.java index 4f217beb9e6..8c02ef9dcc0 100644 --- a/core/camel-api/src/main/java/org/apache/camel/FailedToCreateRouteException.java +++ b/core/camel-api/src/main/java/org/apache/camel/FailedToCreateRouteException.java @@ -24,33 +24,45 @@ import org.apache.camel.util.URISupport; public class FailedToCreateRouteException extends RuntimeCamelException { private final String routeId; + private final String location; public FailedToCreateRouteException(String cause) { - super("Failed to create route because of " + cause); + super("Failed to create route because: " + cause); this.routeId = null; + this.location = null; } - public FailedToCreateRouteException(String routeId, String route, String cause) { - super("Failed to create route " + routeId + ": " + getRouteMessage(route) + " because of " + cause); + public FailedToCreateRouteException(String routeId, String location, String route, String cause) { + super("Failed to create route: " + routeId + (location != null ? " (source: " + location + ")" : "") + ": " + + getRouteMessage(route) + " because: " + cause); this.routeId = routeId; + this.location = location; } - public FailedToCreateRouteException(String routeId, String route, Throwable cause) { - super("Failed to create route " + routeId + ": " + getRouteMessage(route) + " because of " + getExceptionMessage(cause), + public FailedToCreateRouteException(String routeId, String location, String route, Throwable cause) { + super("Failed to create route: " + routeId + (location != null ? " (source: " + location + ")" : "") + ": " + + getRouteMessage(route) + " because: " + getExceptionMessage(cause), cause); this.routeId = routeId; + this.location = location; } - public FailedToCreateRouteException(String routeId, String route, String at, Throwable cause) { - super("Failed to create route " + routeId + " at: >>> " + at + " <<< in route: " + getRouteMessage(route) - + " because of " + getExceptionMessage(cause), cause); + public FailedToCreateRouteException(String routeId, String location, String route, String at, Throwable cause) { + super("Failed to create route: " + routeId + (location != null ? " (source: " + location + ")" : "") + " at: >>> " + at + + " <<< in route: " + getRouteMessage(route) + + " because: " + getExceptionMessage(cause), cause); this.routeId = routeId; + this.location = location; } public String getRouteId() { return routeId; } + public String getLocation() { + return location; + } + protected static String getExceptionMessage(Throwable cause) { return cause.getMessage() != null ? cause.getMessage() : cause.getClass().getSimpleName(); } diff --git a/core/camel-api/src/main/java/org/apache/camel/FailedToStartRouteException.java b/core/camel-api/src/main/java/org/apache/camel/FailedToStartRouteException.java index 850161ca687..cf6a1976ded 100644 --- a/core/camel-api/src/main/java/org/apache/camel/FailedToStartRouteException.java +++ b/core/camel-api/src/main/java/org/apache/camel/FailedToStartRouteException.java @@ -22,18 +22,33 @@ package org.apache.camel; public class FailedToStartRouteException extends RuntimeCamelException { private final String routeId; + private final String location; public FailedToStartRouteException(String routeId, String message) { - super("Failed to start route " + routeId + " because of " + message); + super("Failed to start route: " + routeId + " because: " + message); this.routeId = routeId; + this.location = null; } public FailedToStartRouteException(String routeId, String message, Throwable cause) { - super("Failed to start route " + routeId + " because of " + message, cause); + super("Failed to start route: " + routeId + " because: " + message, cause); this.routeId = routeId; + this.location = null; + } + + public FailedToStartRouteException(String routeId, String location, String message, Throwable cause) { + super("Failed to start route: " + routeId + (location != null ? " (source: " + location + ")" : "") + " because: " + + message, + cause); + this.routeId = routeId; + this.location = location; } public String getRouteId() { return routeId; } + + public String getLocation() { + return location; + } } diff --git a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/InternalRouteStartupManager.java b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/InternalRouteStartupManager.java index 2c3e8de613c..c3535283c0e 100644 --- a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/InternalRouteStartupManager.java +++ b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/InternalRouteStartupManager.java @@ -283,8 +283,10 @@ final class InternalRouteStartupManager { if (other != null && answer != other) { String otherId = other.getRoute().getId(); throw new FailedToStartRouteException( - answer.getRoute().getId(), "startupOrder clash. Route " + otherId + " already has startupOrder " + answer - .getStartupOrder() + " configured which this route have as well. Please correct startupOrder to be unique among all your routes."); + answer.getRoute().getId(), "Route startup order clash. Route " + otherId + " already has startupOrder " + + answer + .getStartupOrder() + + " configured which this route have as well. Please correct startupOrder to be unique among all your routes."); } // check in existing already started as well for (RouteStartupOrder order : camelContext.getCamelContextExtension().getRouteStartupOrder()) { @@ -294,7 +296,7 @@ final class InternalRouteStartupManager { if (!answer.getRoute().getId().equals(otherId) && answer.getStartupOrder() == order.getStartupOrder()) { throw new FailedToStartRouteException( - answer.getRoute().getId(), "startupOrder clash. Route " + otherId + " already has startupOrder " + answer.getRoute().getId(), "Route startup order clash. Route " + otherId + " already has startupOrder " + answer.getStartupOrder() + " configured which this route have as well. Please correct startupOrder to be unique among all your routes."); } diff --git a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/RouteService.java b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/RouteService.java index db4429af08d..8b5abd3eb48 100644 --- a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/RouteService.java +++ b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/RouteService.java @@ -36,7 +36,6 @@ import org.apache.camel.FailedToStartRouteException; import org.apache.camel.Processor; import org.apache.camel.Route; import org.apache.camel.RouteAware; -import org.apache.camel.RuntimeCamelException; import org.apache.camel.Service; import org.apache.camel.StartupStep; import org.apache.camel.spi.IdAware; @@ -79,6 +78,10 @@ public class RouteService extends ChildServiceSupport { return route.getId(); } + public String getLocation() { + return route.getSourceLocationShort(); + } + public CamelContext getCamelContext() { return camelContext; } @@ -123,7 +126,7 @@ public class RouteService extends ChildServiceSupport { try { doWarmUp(); } catch (Exception e) { - throw new FailedToStartRouteException(getId(), e.getLocalizedMessage(), e); + throw new FailedToStartRouteException(getId(), getLocation(), e.getLocalizedMessage(), e); } } @@ -132,7 +135,7 @@ public class RouteService extends ChildServiceSupport { try { doSetup(); } catch (Exception e) { - throw new FailedToStartRouteException(getId(), e.getLocalizedMessage(), e); + throw new FailedToStartRouteException(getId(), getLocation(), e.getLocalizedMessage(), e); } } } @@ -240,12 +243,8 @@ public class RouteService extends ChildServiceSupport { EventHelper.notifyRouteStarting(camelContext, route); } - try { - // ensure we are warmed up - warmUp(); - } catch (FailedToStartRouteException e) { - throw RuntimeCamelException.wrapRuntimeException(e); - } + // ensure we are warmed up + warmUp(); try (MDCHelper mdcHelper = new MDCHelper(route.getId())) { // start the route itself diff --git a/core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultCamelContext.java b/core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultCamelContext.java index 3549773d6cb..d83560182af 100644 --- a/core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultCamelContext.java +++ b/core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultCamelContext.java @@ -641,7 +641,7 @@ public class DefaultCamelContext extends SimpleCamelContext implements ModelCame if (duplicate != null) { throw new FailedToStartRouteException( routeDefinition.getId(), - "duplicate id detected: " + duplicate + "Duplicate id detected: " + duplicate + ". Please correct ids to be unique among all your routes."); } diff --git a/core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultModel.java b/core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultModel.java index f767c9ea08e..ec4e85e8f5c 100644 --- a/core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultModel.java +++ b/core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultModel.java @@ -576,7 +576,7 @@ public class DefaultModel implements Model { if (duplicate != null) { throw new FailedToCreateRouteFromTemplateException( routeId, routeTemplateId, - "duplicate id detected: " + duplicate + ". Please correct ids to be unique among all your routes."); + "Duplicate id detected: " + duplicate + ". Please correct ids to be unique among all your routes."); } // must use route collection to prepare the created route to diff --git a/core/camel-core-model/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java b/core/camel-core-model/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java index 5172592716d..1dd53f99079 100644 --- a/core/camel-core-model/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java +++ b/core/camel-core-model/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java @@ -403,6 +403,9 @@ public final class ProcessorDefinitionHelper { StackTraceElement e = st[i]; if (!e.getClassName().startsWith("org.apache.camel.model") && !e.getClassName().startsWith("org.apache.camel.builder.RouteBuilder") && + !e.getClassName().startsWith("org.apache.camel.reifier.RouteReifier") && + !e.getClassName().startsWith("org.apache.camel.impl") && + !e.getClassName().startsWith("org.apache.camel.support") && !e.getClassName().startsWith("org.apache.camel.dsl")) { // when we are no longer in model/RouteBuilder, we have found the location:line-number node.setLineNumber(e.getLineNumber()); diff --git a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/RouteReifier.java b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/RouteReifier.java index cd71e075ec1..eced54acf90 100644 --- a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/RouteReifier.java +++ b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/RouteReifier.java @@ -41,6 +41,7 @@ import org.apache.camel.ShutdownRunningTask; import org.apache.camel.StartupStep; import org.apache.camel.model.ModelCamelContext; import org.apache.camel.model.ProcessorDefinition; +import org.apache.camel.model.ProcessorDefinitionHelper; import org.apache.camel.model.PropertyDefinition; import org.apache.camel.model.RouteDefinition; import org.apache.camel.processor.ContractAdvice; @@ -57,6 +58,7 @@ import org.apache.camel.spi.NodeIdFactory; import org.apache.camel.spi.RoutePolicy; import org.apache.camel.spi.RoutePolicyFactory; import org.apache.camel.support.ExchangeHelper; +import org.apache.camel.support.LoggerHelper; import org.apache.camel.support.PluginHelper; import org.apache.camel.support.service.ServiceSupport; import org.apache.camel.util.IOHelper; @@ -87,9 +89,10 @@ public class RouteReifier extends ProcessorReifier<RouteDefinition> { } catch (FailedToCreateRouteException e) { throw e; } catch (Exception e) { - // wrap in exception which provide more details about which route - // was failing - throw new FailedToCreateRouteException(definition.getId(), definition.toString(), e); + // location on route is stored on input + ProcessorDefinitionHelper.prepareSourceLocation(definition.getResource(), definition.getInput()); + String source = LoggerHelper.getSourceLocationOnly(definition.getInput()); + throw new FailedToCreateRouteException(definition.getRouteId(), source, definition.toString(), e); } } @@ -213,7 +216,11 @@ public class RouteReifier extends ProcessorReifier<RouteDefinition> { Exception cause = new IllegalArgumentException( "Route " + definition.getId() + " has no output processors." + " You need to add outputs to the route such as to(\"log:foo\")."); - throw new FailedToCreateRouteException(definition.getId(), definition.toString(), at, cause); + // location on route is stored on input + ProcessorDefinitionHelper.prepareSourceLocation(definition.getResource(), definition.getInput()); + String source = LoggerHelper.getSourceLocationOnly(definition.getInput()); + throw new FailedToCreateRouteException( + definition.getRouteId(), source, definition.toString(), at, cause); } List<ProcessorDefinition<?>> list = new ArrayList<>(definition.getOutputs()); @@ -232,7 +239,11 @@ public class RouteReifier extends ProcessorReifier<RouteDefinition> { camelContext.getCamelContextExtension().getStartupStepRecorder().endStep(step); } catch (Exception e) { - throw new FailedToCreateRouteException(definition.getId(), definition.toString(), output.toString(), e); + // location on route is stored on input + String source = LoggerHelper + .getLineNumberLoggerName(definition.getInput() != null ? definition.getInput().getLocation() : null); + throw new FailedToCreateRouteException( + definition.getRouteId(), source, definition.toString(), output.toString(), e); } } diff --git a/core/camel-core/src/test/java/org/apache/camel/component/direct/DirectEndpointRouteInlinedTest.java b/core/camel-core/src/test/java/org/apache/camel/component/direct/DirectEndpointRouteInlinedTest.java index e85f7bd9518..69ed88dd62c 100644 --- a/core/camel-core/src/test/java/org/apache/camel/component/direct/DirectEndpointRouteInlinedTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/component/direct/DirectEndpointRouteInlinedTest.java @@ -62,7 +62,7 @@ public class DirectEndpointRouteInlinedTest extends ContextTestSupport { }, "Should have thrown exception"); assertTrue(e.getMessage().matches( - "Failed to start route route[0-9]+ because of Multiple consumers for the same endpoint is not allowed: direct://start")); + "Failed to start route: route[0-9]+ because: Multiple consumers for the same endpoint is not allowed: direct://start")); } } diff --git a/core/camel-core/src/test/java/org/apache/camel/component/seda/SedaConcurrentConsumersNPEIssueTest.java b/core/camel-core/src/test/java/org/apache/camel/component/seda/SedaConcurrentConsumersNPEIssueTest.java index 68938880167..ee0a9ca3baa 100644 --- a/core/camel-core/src/test/java/org/apache/camel/component/seda/SedaConcurrentConsumersNPEIssueTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/component/seda/SedaConcurrentConsumersNPEIssueTest.java @@ -40,7 +40,7 @@ public class SedaConcurrentConsumersNPEIssueTest extends ContextTestSupport { = assertThrows(FailedToStartRouteException.class, () -> context.getRouteController().startRoute("first"), "Should have thrown exception"); - assertEquals("Failed to start route first because of Multiple consumers for the same endpoint is not allowed:" + assertEquals("Failed to start route: first because: Multiple consumers for the same endpoint is not allowed:" + " seda://foo?concurrentConsumers=5", e.getMessage()); } @@ -61,7 +61,7 @@ public class SedaConcurrentConsumersNPEIssueTest extends ContextTestSupport { = assertThrows(FailedToStartRouteException.class, () -> context.getRouteController().startRoute("first"), "Should have thrown exception"); - assertEquals("Failed to start route first because of Multiple consumers for the same endpoint is not allowed:" + assertEquals("Failed to start route: first because: Multiple consumers for the same endpoint is not allowed:" + " seda://foo?concurrentConsumers=5", e.getMessage()); } diff --git a/core/camel-core/src/test/java/org/apache/camel/impl/GracefulShutdownNoAutoStartOrderClashTest.java b/core/camel-core/src/test/java/org/apache/camel/impl/GracefulShutdownNoAutoStartOrderClashTest.java index 8b9f9665d02..8907801112d 100644 --- a/core/camel-core/src/test/java/org/apache/camel/impl/GracefulShutdownNoAutoStartOrderClashTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/impl/GracefulShutdownNoAutoStartOrderClashTest.java @@ -43,7 +43,7 @@ public class GracefulShutdownNoAutoStartOrderClashTest extends ContextTestSuppor Exception e = assertThrows(Exception.class, () -> context.start(), "Should have thrown an exception"); assertEquals( - "Failed to start route bar because of startupOrder clash. Route foo already has startupOrder 5 configured" + "Failed to start route: bar because: Route startup order clash. Route foo already has startupOrder 5 configured" + " which this route have as well. Please correct startupOrder to be unique among all your routes.", e.getMessage()); } diff --git a/core/camel-core/src/test/java/org/apache/camel/issues/RouteIdClashTest.java b/core/camel-core/src/test/java/org/apache/camel/issues/RouteIdClashTest.java index 5f1d9445c46..6382c8d0a86 100644 --- a/core/camel-core/src/test/java/org/apache/camel/issues/RouteIdClashTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/issues/RouteIdClashTest.java @@ -47,7 +47,7 @@ public class RouteIdClashTest extends ContextTestSupport { } catch (FailedToStartRouteException e) { Assertions.assertEquals("myroute", e.getRouteId()); Assertions.assertEquals( - "Failed to start route myroute because of duplicate id detected: myroute. Please correct ids to be unique among all your routes.", + "Failed to start route: myroute because: Duplicate id detected: myroute. Please correct ids to be unique among all your routes.", e.getMessage()); } } diff --git a/core/camel-core/src/test/java/org/apache/camel/model/StartingRoutesErrorReportedTest.java b/core/camel-core/src/test/java/org/apache/camel/model/StartingRoutesErrorReportedTest.java index a08563b33b8..f68a24d01fb 100644 --- a/core/camel-core/src/test/java/org/apache/camel/model/StartingRoutesErrorReportedTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/model/StartingRoutesErrorReportedTest.java @@ -17,9 +17,11 @@ package org.apache.camel.model; import org.apache.camel.ContextTestSupport; +import org.apache.camel.FailedToCreateRouteException; import org.apache.camel.builder.RouteBuilder; import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -37,8 +39,8 @@ public class StartingRoutesErrorReportedTest extends ContextTestSupport { context.start(); }); - assertTrue(e.getMessage().startsWith( - "Failed to create route route1: Route(route1)[From[direct:start?foo=bar] -> [To[mock:result]... because of")); + FailedToCreateRouteException fe = assertIsInstanceOf(FailedToCreateRouteException.class, e); + assertEquals("route1", fe.getRouteId()); } @Test @@ -54,7 +56,7 @@ public class StartingRoutesErrorReportedTest extends ContextTestSupport { }); assertTrue( - e.getMessage().startsWith("Failed to create route route2 at: >>> To[direct:result?foo=bar] <<< in route:")); + e.getMessage().startsWith("Failed to create route: route2 at: >>> To[direct:result?foo=bar] <<< in route:")); } @Test @@ -70,7 +72,7 @@ public class StartingRoutesErrorReportedTest extends ContextTestSupport { }); assertTrue( - e.getMessage().startsWith("Failed to create route route2 at: >>> To[direct:result?foo=bar] <<< in route:")); + e.getMessage().startsWith("Failed to create route: route2 at: >>> To[direct:result?foo=bar] <<< in route:")); } @Test @@ -85,7 +87,7 @@ public class StartingRoutesErrorReportedTest extends ContextTestSupport { context.start(); }, "Should have thrown exception"); - assertTrue(e.getMessage().startsWith("Failed to create route route3 at: >>> Bean[ref:] <<< in route:")); + assertTrue(e.getMessage().startsWith("Failed to create route: route3 at: >>> Bean[ref:] <<< in route:")); } @Test diff --git a/core/camel-main/src/main/java/org/apache/camel/main/RoutesConfigurer.java b/core/camel-main/src/main/java/org/apache/camel/main/RoutesConfigurer.java index 71119f09802..1931ddbce0b 100644 --- a/core/camel-main/src/main/java/org/apache/camel/main/RoutesConfigurer.java +++ b/core/camel-main/src/main/java/org/apache/camel/main/RoutesConfigurer.java @@ -383,7 +383,7 @@ public class RoutesConfigurer extends ServiceSupport implements NonManagedServic if (!dups.isEmpty()) { String id = String.join(",", dups); throw new FailedToCreateRouteException( - "duplicate route ids detected: " + id + ". Please correct ids to be unique among all your routes."); + "Duplicate route ids detected: " + id + ". Please correct ids to be unique among all your routes."); } } diff --git a/core/camel-main/src/test/java/org/apache/camel/main/MainScan3Test.java b/core/camel-main/src/test/java/org/apache/camel/main/MainScan3Test.java index 36bf3da9adb..527da89a614 100644 --- a/core/camel-main/src/test/java/org/apache/camel/main/MainScan3Test.java +++ b/core/camel-main/src/test/java/org/apache/camel/main/MainScan3Test.java @@ -33,7 +33,7 @@ public class MainScan3Test { fail(); } catch (FailedToCreateRouteException e) { assertEquals( - "Failed to create route because of duplicate route ids detected: foo2. Please correct ids to be unique among all your routes.", + "Failed to create route because: Duplicate route ids detected: foo2. Please correct ids to be unique among all your routes.", e.getMessage()); } diff --git a/core/camel-management/src/test/java/org/apache/camel/management/ManagedDuplicateIdTest.java b/core/camel-management/src/test/java/org/apache/camel/management/ManagedDuplicateIdTest.java index 73526f4ba03..22dc06931eb 100644 --- a/core/camel-management/src/test/java/org/apache/camel/management/ManagedDuplicateIdTest.java +++ b/core/camel-management/src/test/java/org/apache/camel/management/ManagedDuplicateIdTest.java @@ -52,7 +52,7 @@ public class ManagedDuplicateIdTest extends ManagementTestSupport { fail("Should fail"); } catch (Exception e) { assertEquals( - "Failed to start route foo because of duplicate id detected: clash. Please correct ids to be unique among all your routes.", + "Failed to start route: foo because: Duplicate id detected: clash. Please correct ids to be unique among all your routes.", e.getMessage()); } } diff --git a/core/camel-support/src/main/java/org/apache/camel/support/LoggerHelper.java b/core/camel-support/src/main/java/org/apache/camel/support/LoggerHelper.java index 35c419c3e54..a2258b4b884 100644 --- a/core/camel-support/src/main/java/org/apache/camel/support/LoggerHelper.java +++ b/core/camel-support/src/main/java/org/apache/camel/support/LoggerHelper.java @@ -93,6 +93,24 @@ public final class LoggerHelper { return name; } + public static String getSourceLocationOnly(Object node) { + String name = null; + if (node instanceof LineNumberAware) { + if (node instanceof NamedRoute namedRoute) { + // we want the input from a route as it has the source location / line number + node = namedRoute.getInput(); + } + + final LineNumberAware lineNumberAware = (LineNumberAware) node; + String loc = lineNumberAware.getLocation(); + if (loc != null) { + // is it a class or file? + name = loc; + } + } + return name; + } + public static String stripSourceLocationLineNumber(String location) { int cnt = StringHelper.countChar(location, ':'); if (cnt > 1) { diff --git a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/common/RuntimeType.java b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/common/RuntimeType.java index 6f336cdbd5b..50eb5d33e00 100644 --- a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/common/RuntimeType.java +++ b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/common/RuntimeType.java @@ -32,9 +32,9 @@ public enum RuntimeType { public static RuntimeType fromValue(String value) { value = value.toLowerCase(Locale.ROOT); return switch (value) { - case "spring-boot", "camel-spring-boot" -> RuntimeType.springBoot; + case "spring", "spring-boot", "camel-spring-boot" -> RuntimeType.springBoot; case "quarkus", "camel-quarkus" -> RuntimeType.quarkus; - case "main", "camel-main" -> RuntimeType.main; + case "main", "camel-main", "camel" -> RuntimeType.main; default -> throw new IllegalArgumentException("Unsupported runtime " + value); }; } diff --git a/dsl/camel-jbang/camel-jbang-it/src/test/java/org/apache/camel/dsl/jbang/it/CustomJarsITCase.java b/dsl/camel-jbang/camel-jbang-it/src/test/java/org/apache/camel/dsl/jbang/it/CustomJarsITCase.java index 7840f4ecc8a..b78ccb0c4d4 100644 --- a/dsl/camel-jbang/camel-jbang-it/src/test/java/org/apache/camel/dsl/jbang/it/CustomJarsITCase.java +++ b/dsl/camel-jbang/camel-jbang-it/src/test/java/org/apache/camel/dsl/jbang/it/CustomJarsITCase.java @@ -30,7 +30,7 @@ public class CustomJarsITCase extends JBangTestSupport { Assertions .assertThatCode(() -> execute(String.format("run %s/CircuitBreakerRoute.java --dep=camel-timer", mountPoint()))) .as("the application without dependency will cause error") - .hasStackTraceContaining("Failed to create route circuitBreaker") + .hasStackTraceContaining("Failed to create route: circuitBreaker") .hasStackTraceContaining( "Cannot find camel-resilience4j or camel-microprofile-fault-tolerance on the classpath."); executeBackground(String.format("run %s/CircuitBreakerRoute.java --dep=camel-timer,camel-resilience4j", mountPoint()));