Package org.apache.camel.builder
Class AdviceWithRouteBuilder
- java.lang.Object
-
- org.apache.camel.builder.BuilderSupport
-
- org.apache.camel.builder.RouteBuilder
-
- org.apache.camel.builder.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
ARouteBuilder
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.
-
-
Field Summary
-
Fields inherited from class org.apache.camel.builder.RouteBuilder
log
-
-
Constructor Summary
Constructors Constructor Description AdviceWithRouteBuilder()
AdviceWithRouteBuilder(org.apache.camel.CamelContext context)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static RouteDefinition
adviceWith(org.apache.camel.CamelContext camelContext, Object routeId, boolean logXml, org.apache.camel.util.function.ThrowingConsumer<AdviceWithRouteBuilder,Exception> builder)
static RouteDefinition
adviceWith(org.apache.camel.CamelContext camelContext, Object routeId, org.apache.camel.util.function.ThrowingConsumer<AdviceWithRouteBuilder,Exception> builder)
Deprecated.List<AdviceWithTask>
getAdviceWithTasks()
Gets a list of additional tasks to execute after theRouteBuilder.configure()
method has been executed during the advice process.RouteDefinition
getOriginalRoute()
Gets the original route to be adviced.boolean
isLogRouteAsXml()
Whether to log the adviced routes before/after as XML.void
mockEndpoints()
Mock all endpoints.void
mockEndpoints(String... pattern)
Mock all endpoints matching the given pattern.void
mockEndpointsAndSkip(String... pattern)
Mock all endpoints matching the given pattern, and skips sending to the original endpoint (detour messages).void
replaceFromWith(String uri)
Replaces the route from endpoint with a new urivoid
replaceFromWith(org.apache.camel.Endpoint endpoint)
Replaces the route from endpoint with a new endpointvoid
setLogRouteAsXml(boolean logRouteAsXml)
Sets whether to log the adviced routes before/after as XML.void
setOriginalRoute(RouteDefinition originalRoute)
Sets the original route to be adviced.<T extends ProcessorDefinition<?>>
ProcessorDefinition<?>weaveAddFirst()
Weaves by adding the nodes to the start of the route (excl onException etc).<T extends ProcessorDefinition<?>>
ProcessorDefinition<?>weaveAddLast()
Weaves by adding the nodes to the end of the route (excl onException etc).<T extends ProcessorDefinition<?>>
AdviceWithBuilder<T>weaveById(String pattern)
Weaves by matching id of the nodes in the route (incl onException etc).<T extends ProcessorDefinition<?>>
AdviceWithBuilder<T>weaveByToString(String pattern)
Weaves by matching the to string representation of the nodes in the route (incl onException etc).<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).<T extends ProcessorDefinition<?>>
AdviceWithBuilder<T>weaveByType(Class<T> type)
Weaves by matching type of the nodes in the route (incl onException etc).-
Methods inherited from class org.apache.camel.builder.RouteBuilder
addLifecycleInterceptor, addRoutes, addRoutesToCamelContext, addTemplatedRoutesToCamelContext, bindToRegistry, bindToRegistry, checkInitialized, configuration, configure, configureRest, configureRests, configureRoute, configureRouteConfiguration, configureRoutes, configureRouteTemplate, configureTemplatedRoute, dataFormat, errorHandler, errorHandler, expression, from, from, from, fromF, getOrder, getResource, getRestCollection, getRestConfiguration, getRouteCollection, getRouteTemplateCollection, getTemplatedRouteCollection, intercept, interceptFrom, interceptFrom, interceptSendToEndpoint, loadRoutesBuilder, loadRoutesBuilder, onCompletion, onException, onException, populateOrUpdateRoutes, populateRests, populateRoutes, populateRouteTemplates, populateTemplatedRoutes, populateTransformers, populateValidators, property, propertyInject, removeLifecycleInterceptor, rest, rest, restConfiguration, routeTemplate, setErrorHandlerFactory, setResource, setRestCollection, setRouteCollection, setRouteTemplateCollection, setTemplatedRouteCollection, templatedRoute, toString, transformer, updateRoutesToCamelContext, validator
-
Methods inherited from class org.apache.camel.builder.BuilderSupport
body, bodyAs, constant, constant, constant, createErrorHandlerBuilder, csimple, csimple, datasonnet, datasonnet, datasonnet, deadLetterChannel, deadLetterChannel, defaultErrorHandler, endpoint, endpoint, endpoints, endpoints, exceptionMessage, exchangeProperty, expression, getCamelContext, getContext, getErrorHandlerFactory, hasErrorHandlerFactory, header, joor, joor, jsonpath, jsonpath, jtaTransactionErrorHandler, jtaTransactionErrorHandler, jtaTransactionErrorHandler, method, method, method, method, noErrorHandler, regexReplaceAll, regexReplaceAll, setCamelContext, simple, simple, simpleF, simpleF, springTransactionErrorHandler, springTransactionErrorHandler, springTransactionErrorHandler, systemProperty, systemProperty, xpath, xpath, xpath, xpath
-
-
-
-
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
Deprecated.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 contextrouteId
- 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 contextrouteId
- 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 theRouteBuilder.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 thePatternHelper.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 thePatternHelper.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 thePatternHelper.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
-
-