Class AdviceWithRouteBuilder

  • All Implemented Interfaces:
    org.apache.camel.CamelContextAware, org.apache.camel.Ordered, org.apache.camel.RoutesBuilder, org.apache.camel.spi.ResourceAware

    public abstract class AdviceWithRouteBuilder
    extends RouteBuilder
    A RouteBuilder which has extended capabilities when using the advice with feature.

    Important: 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.

    • Constructor Detail

      • AdviceWithRouteBuilder

        public AdviceWithRouteBuilder()
      • AdviceWithRouteBuilder

        public AdviceWithRouteBuilder​(org.apache.camel.CamelContext context)
    • Method Detail

      • adviceWith

        @Deprecated
        public static RouteDefinition adviceWith​(org.apache.camel.CamelContext camelContext,
                                                 Object routeId,
                                                 org.apache.camel.util.function.ThrowingConsumer<AdviceWithRouteBuilder,​Exception> builder)
                                          throws Exception
        Advices this route with the route builder using a lambda expression. It can be used as following:
         AdviceWithRouteBuilder.adviceWith(context, "myRoute", a ->
             a.weaveAddLast().to("mock:result");
         

        Important: 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 advice process will add the interceptors, on exceptions, on completions etc. configured from the route builder to this route.

        This is mostly used for testing purpose to add interceptors and the likes to an existing route.

        Will stop and remove the old route from camel context and add and start this new advised route.

        Parameters:
        camelContext - the camel context
        routeId - either the route id as a string value, or null to chose the 1st route, or you can specify a number for the n'th route, or provide the route definition instance directly as well.
        builder - the advice with route builder
        Returns:
        a new route which is this route merged with the route builder
        Throws:
        Exception - can be thrown from the route builder
      • adviceWith

        @Deprecated
        public static RouteDefinition adviceWith​(org.apache.camel.CamelContext camelContext,
                                                 Object routeId,
                                                 boolean logXml,
                                                 org.apache.camel.util.function.ThrowingConsumer<AdviceWithRouteBuilder,​Exception> builder)
                                          throws Exception
        Advices this route with the route builder using a lambda expression. It can be used as following:
         AdviceWithRouteBuilder.adviceWith(context, "myRoute", false, a ->
             a.weaveAddLast().to("mock:result");
         

        Important: 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 advice process will add the interceptors, on exceptions, on completions etc. configured from the route builder to this route.

        This is mostly used for testing purpose to add interceptors and the likes to an existing route.

        Will stop and remove the old route from camel context and add and start this new advised route.

        Parameters:
        camelContext - the camel context
        routeId - either the route id as a string value, or null to chose the 1st route, or you can specify a number for the n'th route, or provide the route definition instance directly as well.
        logXml - whether to log the before and after advices routes as XML to the log (this can be turned off to perform faster)
        builder - the advice with route builder
        Returns:
        a new route which is this route merged with the route builder
        Throws:
        Exception - can be thrown from the route builder
      • setOriginalRoute

        public void setOriginalRoute​(RouteDefinition originalRoute)
        Sets the original route to be adviced.
        Parameters:
        originalRoute - the original route.
      • getOriginalRoute

        public RouteDefinition getOriginalRoute()
        Gets the original route to be adviced.
        Returns:
        the original route.
      • isLogRouteAsXml

        public boolean isLogRouteAsXml()
        Whether to log the adviced routes before/after as XML. This is usable to know how the route was adviced and changed. However marshalling the route model to XML costs CPU resources and you can then turn this off by not logging. This is default enabled.
      • setLogRouteAsXml

        public void setLogRouteAsXml​(boolean logRouteAsXml)
        Sets whether to log the adviced routes before/after as XML. This is usable to know how the route was adviced and changed. However marshalling the route model to XML costs CPU resources and you can then turn this off by not logging. This is default enabled.
      • getAdviceWithTasks

        public List<AdviceWithTask> getAdviceWithTasks()
        Gets a list of additional tasks to execute after the RouteBuilder.configure() method has been executed during the advice process.
        Returns:
        a list of additional AdviceWithTask tasks to be executed during the advice process.
      • mockEndpoints

        public void mockEndpoints()
                           throws Exception
        Mock all endpoints.
        Throws:
        Exception - can be thrown if error occurred
      • mockEndpoints

        public void mockEndpoints​(String... pattern)
                           throws Exception
        Mock all endpoints matching the given pattern.
        Parameters:
        pattern - the pattern(s).
        Throws:
        Exception - can be thrown if error occurred
        See Also:
        EndpointHelper.matchEndpoint(org.apache.camel.CamelContext, String, String)
      • mockEndpointsAndSkip

        public void mockEndpointsAndSkip​(String... pattern)
                                  throws Exception
        Mock all endpoints matching the given pattern, and skips sending to the original endpoint (detour messages).
        Parameters:
        pattern - the pattern(s).
        Throws:
        Exception - can be thrown if error occurred
        See Also:
        EndpointHelper.matchEndpoint(org.apache.camel.CamelContext, String, String)
      • replaceFromWith

        public void replaceFromWith​(String uri)
        Replaces the route from endpoint with a new uri
        Parameters:
        uri - uri of the new endpoint
      • replaceFromWith

        public void replaceFromWith​(org.apache.camel.Endpoint endpoint)
        Replaces the route from endpoint with a new endpoint
        Parameters:
        endpoint - the new endpoint
      • weaveById

        public <T extends ProcessorDefinition<?>> AdviceWithBuilder<T> weaveById​(String pattern)
        Weaves by matching id of the nodes in the route (incl onException etc).

        Uses the PatternHelper.matchPattern(String, String) matching algorithm.

        Parameters:
        pattern - the pattern
        Returns:
        the builder
        See Also:
        PatternHelper.matchPattern(String, String)
      • weaveByToString

        public <T extends ProcessorDefinition<?>> AdviceWithBuilder<T> weaveByToString​(String pattern)
        Weaves by matching the to string representation of the nodes in the route (incl onException etc).

        Uses the PatternHelper.matchPattern(String, String) matching algorithm.

        Parameters:
        pattern - the pattern
        Returns:
        the builder
        See Also:
        PatternHelper.matchPattern(String, String)
      • weaveByToUri

        public <T extends ProcessorDefinition<?>> AdviceWithBuilder<T> weaveByToUri​(String pattern)
        Weaves by matching sending to endpoints with the given uri of the nodes in the route (incl onException etc).

        Uses the PatternHelper.matchPattern(String, String) matching algorithm.

        Parameters:
        pattern - the pattern
        Returns:
        the builder
        See Also:
        PatternHelper.matchPattern(String, String)
      • weaveByType

        public <T extends ProcessorDefinition<?>> AdviceWithBuilder<T> weaveByType​(Class<T> type)
        Weaves by matching type of the nodes in the route (incl onException etc).
        Parameters:
        type - the processor type
        Returns:
        the builder
      • weaveAddFirst

        public <T extends ProcessorDefinition<?>> ProcessorDefinition<?> weaveAddFirst()
        Weaves by adding the nodes to the start of the route (excl onException etc).
        Returns:
        the builder
      • weaveAddLast

        public <T extends ProcessorDefinition<?>> ProcessorDefinition<?> weaveAddLast()
        Weaves by adding the nodes to the end of the route (excl onException etc).
        Returns:
        the builder