This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push: new 08e4baa CAMEL-15732: Untangle reifier from builder. 08e4baa is described below commit 08e4baa6779b41a9d7531f09fcbe1f725ed25572 Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Fri Oct 23 09:37:18 2020 +0200 CAMEL-15732: Untangle reifier from builder. --- .../org/apache/camel/reifier/RouteReifier.java | 158 --------------------- 1 file changed, 158 deletions(-) diff --git a/core/camel-core-engine/src/main/java/org/apache/camel/reifier/RouteReifier.java b/core/camel-core-engine/src/main/java/org/apache/camel/reifier/RouteReifier.java index 17fded9..95a4071 100644 --- a/core/camel-core-engine/src/main/java/org/apache/camel/reifier/RouteReifier.java +++ b/core/camel-core-engine/src/main/java/org/apache/camel/reifier/RouteReifier.java @@ -32,15 +32,9 @@ import org.apache.camel.Route; import org.apache.camel.RuntimeCamelException; import org.apache.camel.ShutdownRoute; import org.apache.camel.ShutdownRunningTask; -import org.apache.camel.builder.AdviceWith; -import org.apache.camel.builder.AdviceWithRouteBuilder; -import org.apache.camel.builder.AdviceWithTask; -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.model.Model; import org.apache.camel.model.ProcessorDefinition; import org.apache.camel.model.PropertyDefinition; import org.apache.camel.model.RouteDefinition; -import org.apache.camel.model.RoutesDefinition; import org.apache.camel.processor.CamelInternalProcessor; import org.apache.camel.processor.ContractAdvice; import org.apache.camel.processor.Pipeline; @@ -50,7 +44,6 @@ import org.apache.camel.spi.LifecycleStrategy; import org.apache.camel.spi.ManagementInterceptStrategy; import org.apache.camel.spi.RoutePolicy; import org.apache.camel.spi.RoutePolicyFactory; -import org.apache.camel.util.ObjectHelper; public class RouteReifier extends ProcessorReifier<RouteDefinition> { @@ -63,39 +56,6 @@ public class RouteReifier extends ProcessorReifier<RouteDefinition> { super(camelContext, (RouteDefinition) definition); } - /** - * Advices this route with the route builder. - * <p/> - * <b>Important:</b> It is recommended to only advice a given route once (you can of course advice multiple routes). - * If you do it multiple times, then it may not work as expected, especially when any kind of error handling is - * involved. The Camel team plan for Camel 3.0 to support this as internal refactorings in the routing engine is - * needed to support this properly. - * <p/> - * You can use a regular {@link RouteBuilder} but the specialized {@link AdviceWithRouteBuilder} has additional - * features when using the <a href="http://camel.apache.org/advicewith.html">advice with</a> feature. We therefore - * suggest you to use the {@link AdviceWithRouteBuilder}. - * <p/> - * The advice process will add the interceptors, on exceptions, on completions etc. configured from the route - * builder to this route. - * <p/> - * This is mostly used for testing purpose to add interceptors and the likes to an existing route. - * <p/> - * Will stop and remove the old route from camel context and add and start this new advised route. - * - * @param definition the model definition - * @param camelContext the camel context - * @param builder the route builder - * @return a new route which is this route merged with the route builder - * @throws Exception can be thrown from the route builder - * @see AdviceWithRouteBuilder - * @deprecated use {@link AdviceWith#adviceWith(RouteDefinition, CamelContext, RouteBuilder)} - */ - @Deprecated - public static RouteDefinition adviceWith(RouteDefinition definition, CamelContext camelContext, RouteBuilder builder) - throws Exception { - return AdviceWith.adviceWith(definition, camelContext, builder); - } - @Override public Processor createProcessor() throws Exception { throw new UnsupportedOperationException("Not implemented for RouteDefinition"); @@ -113,124 +73,6 @@ public class RouteReifier extends ProcessorReifier<RouteDefinition> { } } - /** - * Advices this route with the route builder. - * <p/> - * <b>Important:</b> It is recommended to only advice a given route once (you can of course advice multiple routes). - * If you do it multiple times, then it may not work as expected, especially when any kind of error handling is - * involved. The Camel team plan for Camel 3.0 to support this as internal refactorings in the routing engine is - * needed to support this properly. - * <p/> - * You can use a regular {@link RouteBuilder} but the specialized - * {@link org.apache.camel.builder.AdviceWithRouteBuilder} has additional features when using the - * <a href="http://camel.apache.org/advicewith.html">advice with</a> feature. We therefore suggest you to use the - * {@link org.apache.camel.builder.AdviceWithRouteBuilder}. - * <p/> - * The advice process will add the interceptors, on exceptions, on completions etc. configured from the route - * builder to this route. - * <p/> - * This is mostly used for testing purpose to add interceptors and the likes to an existing route. - * <p/> - * Will stop and remove the old route from camel context and add and start this new advised route. - * - * @param builder the route builder - * @return a new route which is this route merged with the route builder - * @throws Exception can be thrown from the route builder - * @see AdviceWithRouteBuilder - */ - @SuppressWarnings("deprecation") - public RouteDefinition adviceWith(RouteBuilder builder) throws Exception { - ObjectHelper.notNull(builder, "RouteBuilder"); - - log.debug("AdviceWith route before: {}", this); - ExtendedCamelContext ecc = camelContext.adapt(ExtendedCamelContext.class); - Model model = camelContext.getExtension(Model.class); - - // inject this route into the advice route builder so it can access this route - // and offer features to manipulate the route directly - if (builder instanceof AdviceWithRouteBuilder) { - AdviceWithRouteBuilder arb = (AdviceWithRouteBuilder) builder; - arb.setOriginalRoute(definition); - } - - // configure and prepare the routes from the builder - RoutesDefinition routes = builder.configureRoutes(camelContext); - - // was logging enabled or disabled - boolean logRoutesAsXml = true; - if (builder instanceof AdviceWithRouteBuilder) { - AdviceWithRouteBuilder arb = (AdviceWithRouteBuilder) builder; - logRoutesAsXml = arb.isLogRouteAsXml(); - } - - log.debug("AdviceWith routes: {}", routes); - - // we can only advice with a route builder without any routes - if (!builder.getRouteCollection().getRoutes().isEmpty()) { - throw new IllegalArgumentException( - "You can only advice from a RouteBuilder which has no existing routes. Remove all routes from the route builder."); - } - // we can not advice with error handlers (if you added a new error - // handler in the route builder) - // we must check the error handler on builder is not the same as on - // camel context, as that would be the default - // context scoped error handler, in case no error handlers was - // configured - if (builder.getRouteCollection().getErrorHandlerFactory() != null - && ecc.getErrorHandlerFactory() != builder.getRouteCollection().getErrorHandlerFactory()) { - throw new IllegalArgumentException( - "You can not advice with error handlers. Remove the error handlers from the route builder."); - } - - String beforeAsXml = null; - if (logRoutesAsXml && log.isInfoEnabled()) { - try { - beforeAsXml = ecc.getModelToXMLDumper().dumpModelAsXml(camelContext, definition); - } catch (Throwable e) { - // ignore, it may be due jaxb is not on classpath etc - } - } - - // stop and remove this existing route - model.removeRouteDefinition(definition); - - // any advice with tasks we should execute first? - if (builder instanceof AdviceWithRouteBuilder) { - List<AdviceWithTask> tasks = ((AdviceWithRouteBuilder) builder).getAdviceWithTasks(); - for (AdviceWithTask task : tasks) { - task.task(); - } - } - - // now merge which also ensures that interceptors and the likes get - // mixed in correctly as well - RouteDefinition merged = routes.route(definition); - - // add the new merged route - model.getRouteDefinitions().add(0, merged); - - // log the merged route at info level to make it easier to end users to - // spot any mistakes they may have made - if (log.isInfoEnabled()) { - log.info("AdviceWith route after: {}", merged); - } - - if (beforeAsXml != null && logRoutesAsXml && log.isInfoEnabled()) { - try { - String afterAsXml = ecc.getModelToXMLDumper().dumpModelAsXml(camelContext, merged); - log.info("Adviced route before/after as XML:\n{}\n{}", beforeAsXml, afterAsXml); - } catch (Throwable e) { - // ignore, it may be due jaxb is not on classpath etc - } - } - - // If the camel context is started then we start the route - if (camelContext.isStarted()) { - model.addRouteDefinition(merged); - } - return merged; - } - // Implementation methods // ------------------------------------------------------------------------- protected Route doCreateRoute() throws Exception {