Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,15 @@ public interface CamelContext extends CamelContextLifecycle, RuntimeConfiguratio
*/
void addRoutes(RoutesBuilder builder) throws Exception;

/**
* Adds the templated routes from the routes builder.
* For example in Java DSL you can use {@link org.apache.camel.builder.TemplatedRouteBuilder}.
*
* @param builder the builder which has templated routes
* @throws Exception if the routes could not be created for whatever reason
*/
void addTemplatedRoutes(RoutesBuilder builder) throws Exception;

/**
* Adds the routes configurations (global configuration for all routes) from the routes builder.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ public interface RoutesBuilder {
*/
void addRoutesToCamelContext(CamelContext context) throws Exception;

/**
* Adds the templated routes from this Route Builder to the CamelContext.
*
* @param context the Camel context
* @throws Exception is thrown if initialization of routes failed
*/
void addTemplatedRoutesToCamelContext(CamelContext context) throws Exception;

/**
* Adds or updates the routes from this Route Builder to the CamelContext.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1202,6 +1202,14 @@ public void addRoutes(RoutesBuilder builder) throws Exception {
}
}

@Override
public void addTemplatedRoutes(RoutesBuilder builder) throws Exception {
try (LifecycleHelper helper = new LifecycleHelper()) {
build();
LOG.debug("Adding templated routes from builder: {}", builder);
builder.addTemplatedRoutesToCamelContext(AbstractCamelContext.this);
}
}
@Override
public void addRoutesConfigurations(RouteConfigurationsBuilder builder) throws Exception {
try (LifecycleHelper helper = new LifecycleHelper()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,11 @@ public void addRoutes(RoutesBuilder builder) throws Exception {
delegate.addRoutes(builder);
}

@Override
public void addTemplatedRoutes(RoutesBuilder builder) throws Exception {
delegate.addTemplatedRoutes(builder);
}

@Override
public void addRoutesConfigurations(RouteConfigurationsBuilder builder) throws Exception {
delegate.addRoutesConfigurations(builder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2043,6 +2043,11 @@ public void addRoutes(RoutesBuilder builder) throws Exception {
throw new UnsupportedOperationException();
}

@Override
public void addTemplatedRoutes(RoutesBuilder builder) throws Exception {
throw new UnsupportedOperationException();
}

@Override
public void addRoutesConfigurations(RouteConfigurationsBuilder builder) throws Exception {
throw new UnsupportedOperationException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,6 @@ public void addRoutesToCamelContext(CamelContext context) throws Exception {
populateTransformers();
populateValidators();
populateRouteTemplates();
populateTemplatedRoutes();

// ensure routes are prepared before being populated
for (RouteDefinition route : routeCollection.getRoutes()) {
Expand All @@ -618,6 +617,11 @@ public void addRoutesToCamelContext(CamelContext context) throws Exception {
}
}

@Override
public void addTemplatedRoutesToCamelContext(CamelContext context) throws Exception {
populateTemplatedRoutes();
}

@Override
public Set<String> updateRoutesToCamelContext(CamelContext context) throws Exception {
Set<String> answer = new LinkedHashSet<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,11 @@ private void addDiscoveredRoutes(CamelContext camelContext, List<RoutesBuilder>
LOG.debug("Adding routes into CamelContext from RoutesBuilder: {}", builder);
camelContext.addRoutes(builder);
}
// then add templated routes last
for (RoutesBuilder builder : routes) {
LOG.debug("Adding templated routes into CamelContext from RoutesBuilder: {}", builder);
camelContext.addTemplatedRoutes(builder);
}
}

/**
Expand Down