Class AdviceWithRouteBuilder

All Implemented Interfaces:
org.apache.camel.CamelContextAware, org.apache.camel.Ordered, org.apache.camel.RoutesBuilder, org.apache.camel.spi.HasCamelContext, 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 Details

    • AdviceWithRouteBuilder

      public AdviceWithRouteBuilder()
    • AdviceWithRouteBuilder

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

    • 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