Package org.apache.camel.builder
Class RouteBuilder
- java.lang.Object
-
- org.apache.camel.builder.BuilderSupport
-
- org.apache.camel.builder.RouteBuilder
-
- All Implemented Interfaces:
org.apache.camel.CamelContextAware,org.apache.camel.Ordered,org.apache.camel.RoutesBuilder,org.apache.camel.spi.ResourceAware
- Direct Known Subclasses:
AdviceWithRouteBuilder,RouteConfigurationBuilder
public abstract class RouteBuilder extends BuilderSupport implements org.apache.camel.RoutesBuilder, org.apache.camel.Ordered, org.apache.camel.spi.ResourceAware
-
-
Field Summary
Fields Modifier and Type Field Description protected org.slf4j.Loggerlog
-
Constructor Summary
Constructors Constructor Description RouteBuilder()RouteBuilder(org.apache.camel.CamelContext context)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddLifecycleInterceptor(RouteBuilderLifecycleStrategy interceptor)Adds the givenRouteBuilderLifecycleStrategyto be used.static voidaddRoutes(org.apache.camel.CamelContext context, LambdaRouteBuilder rbc)Add routes to a context using a lambda expression.voidaddRoutesToCamelContext(org.apache.camel.CamelContext context)voidbindToRegistry(String id, Class<?> type, Object bean)Binds the bean to the repository (if possible).voidbindToRegistry(String id, Object bean)Binds the bean to the repository (if possible).protected voidcheckInitialized()voidconfiguration()Called on initialization to build routes configuration (global routes configurations) using the fluent builder syntax.abstract voidconfigure()Called on initialization to build the routes using the fluent builder syntax.protected voidconfigureRest(RestDefinition rest)RestsDefinitionconfigureRests(org.apache.camel.CamelContext context)Configures the restsprotected voidconfigureRoute(RouteDefinition route)protected voidconfigureRouteConfiguration(RouteConfigurationDefinition routesConfiguration)RoutesDefinitionconfigureRoutes(org.apache.camel.CamelContext context)Configures the routesprotected voidconfigureRouteTemplate(RouteTemplateDefinition routeTemplate)protected voidconfigureTemplatedRoute(org.apache.camel.CamelContextAware templatedRoute)voiderrorHandler(String ref)Installs the given error handler buildervoiderrorHandler(org.apache.camel.ErrorHandlerFactory errorHandlerFactory)Installs the given error handler builderRouteDefinitionfrom(String uri)Creates a new route from the given URI inputRouteDefinitionfrom(EndpointConsumerBuilder endpointDefinition)RouteDefinitionfrom(org.apache.camel.Endpoint endpoint)Creates a new route from the given endpointRouteDefinitionfromF(String uri, Object... args)Creates a new route from the given URI inputintgetOrder()Override this method to define ordering ofRouteBuilderclasses that are added to Camel from various runtimes such as camel-main, camel-spring-boot.org.apache.camel.spi.ResourcegetResource()TheResourcewhich is the source code for this route (such as XML, YAML, Groovy or Java source file)RestsDefinitiongetRestCollection()RestConfigurationDefinitiongetRestConfiguration()RoutesDefinitiongetRouteCollection()RouteTemplatesDefinitiongetRouteTemplateCollection()TemplatedRoutesDefinitiongetTemplatedRouteCollection()InterceptDefinitionintercept()Adds a route for an interceptor that intercepts every processing step.InterceptFromDefinitioninterceptFrom()Adds a route for an interceptor that intercepts incoming messages on any inputs in this routeInterceptFromDefinitioninterceptFrom(String uri)Adds a route for an interceptor that intercepts incoming messages on the given endpoint.InterceptSendToEndpointDefinitioninterceptSendToEndpoint(String uri)Applies a route for an interceptor if an exchange is send to the given endpointstatic RouteBuilderloadRoutesBuilder(org.apache.camel.spi.Resource resource, org.apache.camel.util.function.ThrowingBiConsumer<Reader,RouteBuilder,Exception> consumer)static RouteBuilderloadRoutesBuilder(org.apache.camel.util.function.ThrowingConsumer<RouteBuilder,Exception> consumer)LoadsRoutesBuilderusing the given consumer to create aRouteBuilderinstance.OnCompletionDefinitiononCompletion()On completion callback for doing custom routing when theExchangeis complete.OnExceptionDefinitiononException(Class<? extends Throwable> exception)Exception clause for catching certain exceptions and handling them.OnExceptionDefinitiononException(Class<? extends Throwable>... exceptions)Exception clause for catching certain exceptions and handling them.protected voidpopulateOrUpdateRoutes()protected voidpopulateRests()protected voidpopulateRoutes()protected voidpopulateRouteTemplates()protected voidpopulateTemplatedRoutes()protected voidpopulateTransformers()protected voidpopulateValidators()Stringproperty(String key)Refers to the property placeholder<T> TpropertyInject(String key, Class<T> type)Injects a property placeholder value with the given key converted to the given type.voidremoveLifecycleInterceptor(RouteBuilderLifecycleStrategy interceptor)Adds the givenRouteBuilderLifecycleStrategy.RestDefinitionrest()Creates a new REST serviceRestDefinitionrest(String path)Creates a new REST serviceRestConfigurationDefinitionrestConfiguration()Configures the REST servicesRouteTemplateDefinitionrouteTemplate(String id)Creates a new route templatevoidsetErrorHandlerFactory(org.apache.camel.ErrorHandlerFactory errorHandlerFactory)Sets the error handler to use with processors created by this buildervoidsetResource(org.apache.camel.spi.Resource resource)Sets theResourcewhich is the source code for this route (such as XML, YAML, Groovy or Java source file)voidsetRestCollection(RestsDefinition restCollection)voidsetRouteCollection(RoutesDefinition routeCollection)voidsetRouteTemplateCollection(RouteTemplatesDefinition routeTemplateCollection)voidsetTemplatedRouteCollection(TemplatedRoutesDefinition templatedRouteCollection)TemplatedRouteDefinitiontemplatedRoute(String routeTemplateId)Creates a new templated routeStringtoString()TransformerBuildertransformer()Create a newTransformerBuilder.Set<String>updateRoutesToCamelContext(org.apache.camel.CamelContext context)ValidatorBuildervalidator()Create a newValidatorBuilder.-
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, 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
-
getResource
public org.apache.camel.spi.Resource getResource()
TheResourcewhich is the source code for this route (such as XML, YAML, Groovy or Java source file)- Specified by:
getResourcein interfaceorg.apache.camel.spi.ResourceAware
-
setResource
public void setResource(org.apache.camel.spi.Resource resource)
Sets theResourcewhich is the source code for this route (such as XML, YAML, Groovy or Java source file)- Specified by:
setResourcein interfaceorg.apache.camel.spi.ResourceAware
-
addRoutes
public static void addRoutes(org.apache.camel.CamelContext context, LambdaRouteBuilder rbc) throws ExceptionAdd routes to a context using a lambda expression. It can be used as following:RouteBuilder.addRoutes(context, rb -> rb.from("direct:inbound").bean(MyBean.class)));- Parameters:
context- the camel context to add routesrbc- a lambda expression receiving theRouteBuilderto use to create routes- Throws:
Exception- if an error occurs
-
loadRoutesBuilder
public static RouteBuilder loadRoutesBuilder(org.apache.camel.spi.Resource resource, org.apache.camel.util.function.ThrowingBiConsumer<Reader,RouteBuilder,Exception> consumer)
- Parameters:
resource- the resource to be loaded.consumer- the function used to create aRoutesBuilder- Returns:
- a
RoutesBuilder
-
loadRoutesBuilder
public static RouteBuilder loadRoutesBuilder(org.apache.camel.util.function.ThrowingConsumer<RouteBuilder,Exception> consumer)
LoadsRoutesBuilderusing the given consumer to create aRouteBuilderinstance.- Parameters:
consumer- the function used to create aRoutesBuilder- Returns:
- a
RoutesBuilder
-
getOrder
public int getOrder()
Override this method to define ordering ofRouteBuilderclasses that are added to Camel from various runtimes such as camel-main, camel-spring-boot. This allows end users to control the ordering if some routes must be added and started before others. Use low numbers for higher priority. Normally the sorting will start from 0 and move upwards. So if you want to be last then useInteger.MAX_VALUEor egOrdered.LOWEST.- Specified by:
getOrderin interfaceorg.apache.camel.Ordered
-
configure
public abstract void configure() throws ExceptionCalled on initialization to build the routes using the fluent builder syntax. This is a central method for RouteBuilder implementations to implement the routes using the Java fluent builder syntax.- Throws:
Exception- can be thrown during configuration
-
configuration
public void configuration() throws ExceptionCalled on initialization to build routes configuration (global routes configurations) using the fluent builder syntax.- Throws:
Exception- can be thrown during configuration
-
bindToRegistry
public void bindToRegistry(String id, Object bean)
Binds the bean to the repository (if possible).- Parameters:
id- the id of the beanbean- the bean
-
bindToRegistry
public void bindToRegistry(String id, Class<?> type, Object bean)
Binds the bean to the repository (if possible).- Parameters:
id- the id of the beantype- the type of the bean to associate the bindingbean- the bean
-
restConfiguration
public RestConfigurationDefinition restConfiguration()
Configures the REST services- Returns:
- the builder
-
routeTemplate
public RouteTemplateDefinition routeTemplate(String id)
Creates a new route template- Returns:
- the builder
-
templatedRoute
public TemplatedRouteDefinition templatedRoute(String routeTemplateId)
Creates a new templated route- Returns:
- the builder
-
rest
public RestDefinition rest()
Creates a new REST service- Returns:
- the builder
-
rest
public RestDefinition rest(String path)
Creates a new REST service- Parameters:
path- the base path- Returns:
- the builder
-
transformer
public TransformerBuilder transformer()
Create a newTransformerBuilder.- Returns:
- the builder
-
validator
public ValidatorBuilder validator()
Create a newValidatorBuilder.- Returns:
- the builder
-
from
public RouteDefinition from(String uri)
Creates a new route from the given URI input- Parameters:
uri- the from uri- Returns:
- the builder
-
fromF
public RouteDefinition fromF(String uri, Object... args)
Creates a new route from the given URI input- Parameters:
uri- the String formatted from uriargs- arguments for the string formatting of the uri- Returns:
- the builder
-
from
public RouteDefinition from(org.apache.camel.Endpoint endpoint)
Creates a new route from the given endpoint- Parameters:
endpoint- the from endpoint- Returns:
- the builder
-
from
public RouteDefinition from(EndpointConsumerBuilder endpointDefinition)
-
errorHandler
public void errorHandler(org.apache.camel.ErrorHandlerFactory errorHandlerFactory)
Installs the given error handler builder- Parameters:
errorHandlerFactory- the error handler to be used by default for all child routes
-
errorHandler
public void errorHandler(String ref)
Installs the given error handler builder- Parameters:
ref- reference to the error handler to use
-
propertyInject
public <T> T propertyInject(String key, Class<T> type) throws Exception
Injects a property placeholder value with the given key converted to the given type.- Parameters:
key- the property keytype- the type to convert the value as- Returns:
- the value, or null if value is empty
- Throws:
Exception- is thrown if property with key not found or error converting to the given type.
-
property
public String property(String key)
Refers to the property placeholder- Parameters:
key- the property key- Returns:
- the reference to the property using syntax {{key}}
-
intercept
public InterceptDefinition intercept()
Adds a route for an interceptor that intercepts every processing step.- Returns:
- the builder
-
interceptFrom
public InterceptFromDefinition interceptFrom()
Adds a route for an interceptor that intercepts incoming messages on any inputs in this route- Returns:
- the builder
-
interceptFrom
public InterceptFromDefinition interceptFrom(String uri)
Adds a route for an interceptor that intercepts incoming messages on the given endpoint.- Parameters:
uri- endpoint uri- Returns:
- the builder
-
interceptSendToEndpoint
public InterceptSendToEndpointDefinition interceptSendToEndpoint(String uri)
Applies a route for an interceptor if an exchange is send to the given endpoint- Parameters:
uri- endpoint uri- Returns:
- the builder
-
onException
public OnExceptionDefinition onException(Class<? extends Throwable> exception)
Exception clause for catching certain exceptions and handling them.- Parameters:
exception- exception to catch- Returns:
- the builder
-
onException
public OnExceptionDefinition onException(Class<? extends Throwable>... exceptions)
Exception clause for catching certain exceptions and handling them.- Parameters:
exceptions- list of exceptions to catch- Returns:
- the builder
-
onCompletion
public OnCompletionDefinition onCompletion()
On completion callback for doing custom routing when theExchangeis complete.- Returns:
- the builder
-
addRoutesToCamelContext
public void addRoutesToCamelContext(org.apache.camel.CamelContext context) throws Exception- Specified by:
addRoutesToCamelContextin interfaceorg.apache.camel.RoutesBuilder- Throws:
Exception
-
updateRoutesToCamelContext
public Set<String> updateRoutesToCamelContext(org.apache.camel.CamelContext context) throws Exception
- Specified by:
updateRoutesToCamelContextin interfaceorg.apache.camel.RoutesBuilder- Throws:
Exception
-
configureRoutes
public RoutesDefinition configureRoutes(org.apache.camel.CamelContext context) throws Exception
Configures the routes- Parameters:
context- the Camel context- Returns:
- the routes configured
- Throws:
Exception- can be thrown during configuration
-
configureRests
public RestsDefinition configureRests(org.apache.camel.CamelContext context) throws Exception
Configures the rests- Parameters:
context- the Camel context- Returns:
- the rests configured
- Throws:
Exception- can be thrown during configuration
-
setErrorHandlerFactory
public void setErrorHandlerFactory(org.apache.camel.ErrorHandlerFactory errorHandlerFactory)
Description copied from class:BuilderSupportSets the error handler to use with processors created by this builder- Overrides:
setErrorHandlerFactoryin classBuilderSupport
-
addLifecycleInterceptor
public void addLifecycleInterceptor(RouteBuilderLifecycleStrategy interceptor)
Adds the givenRouteBuilderLifecycleStrategyto be used.
-
removeLifecycleInterceptor
public void removeLifecycleInterceptor(RouteBuilderLifecycleStrategy interceptor)
Adds the givenRouteBuilderLifecycleStrategy.
-
populateTransformers
protected void populateTransformers()
-
populateValidators
protected void populateValidators()
-
getRestCollection
public RestsDefinition getRestCollection()
-
setRestCollection
public void setRestCollection(RestsDefinition restCollection)
-
getRestConfiguration
public RestConfigurationDefinition getRestConfiguration()
-
getRouteCollection
public RoutesDefinition getRouteCollection()
-
setRouteCollection
public void setRouteCollection(RoutesDefinition routeCollection)
-
getRouteTemplateCollection
public RouteTemplatesDefinition getRouteTemplateCollection()
-
setRouteTemplateCollection
public void setRouteTemplateCollection(RouteTemplatesDefinition routeTemplateCollection)
-
getTemplatedRouteCollection
public TemplatedRoutesDefinition getTemplatedRouteCollection()
-
setTemplatedRouteCollection
public void setTemplatedRouteCollection(TemplatedRoutesDefinition templatedRouteCollection)
-
configureRest
protected void configureRest(RestDefinition rest)
-
configureRoute
protected void configureRoute(RouteDefinition route)
-
configureRouteTemplate
protected void configureRouteTemplate(RouteTemplateDefinition routeTemplate)
-
configureTemplatedRoute
protected void configureTemplatedRoute(org.apache.camel.CamelContextAware templatedRoute)
-
configureRouteConfiguration
protected void configureRouteConfiguration(RouteConfigurationDefinition routesConfiguration)
-
-