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
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.-
Field Summary
Fields inherited from class org.apache.camel.builder.RouteBuilder
log
Fields inherited from interface org.apache.camel.Ordered
HIGHEST, LOWEST
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic RouteDefinition
adviceWith
(org.apache.camel.CamelContext camelContext, Object routeId, boolean logXml, org.apache.camel.util.function.ThrowingConsumer<AdviceWithRouteBuilder, Exception> builder) Deprecated.static RouteDefinition
adviceWith
(org.apache.camel.CamelContext camelContext, Object routeId, org.apache.camel.util.function.ThrowingConsumer<AdviceWithRouteBuilder, Exception> builder) Deprecated.Gets a list of additional tasks to execute after theRouteBuilder.configure()
method has been executed during the advice process.Gets the original route to be adviced.boolean
Whether to log the adviced routes before/after as XML.void
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<?>Weaves by adding the nodes to the start of the route (excl onException etc).<T extends ProcessorDefinition<?>>
ProcessorDefinition<?>Weaves by adding the nodes to the end of the route (excl onException etc).<T extends ProcessorDefinition<?>>
AdviceWithBuilder<T>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
-
Constructor Details
-
AdviceWithRouteBuilder
public AdviceWithRouteBuilder() -
AdviceWithRouteBuilder
public AdviceWithRouteBuilder(org.apache.camel.CamelContext context)
-
-
Method Details
-
adviceWith
@Deprecated public static RouteDefinition adviceWith(org.apache.camel.CamelContext camelContext, Object routeId, org.apache.camel.util.function.ThrowingConsumer<AdviceWithRouteBuilder, Exception> builder) throws ExceptionDeprecated.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 ExceptionAdvices 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
Sets the original route to be adviced.- Parameters:
originalRoute
- the original route.
-
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
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
Mock all endpoints.- Throws:
Exception
- can be thrown if error occurred
-
mockEndpoints
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
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
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
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
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
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
Weaves by matching type of the nodes in the route (incl onException etc).- Parameters:
type
- the processor type- Returns:
- the builder
-
weaveAddFirst
Weaves by adding the nodes to the start of the route (excl onException etc).- Returns:
- the builder
-
weaveAddLast
Weaves by adding the nodes to the end of the route (excl onException etc).- Returns:
- the builder
-
AdviceWith.adviceWith(CamelContext, Object, boolean, ThrowingConsumer)