Package org.apache.camel.support
Class DefaultComponent
java.lang.Object
org.apache.camel.support.service.BaseService
org.apache.camel.support.service.ServiceSupport
org.apache.camel.support.DefaultComponent
- All Implemented Interfaces:
AutoCloseable
,org.apache.camel.CamelContextAware
,org.apache.camel.Component
,org.apache.camel.Service
,org.apache.camel.ShutdownableService
,org.apache.camel.spi.HasCamelContext
,org.apache.camel.StatefulService
,org.apache.camel.SuspendableService
- Direct Known Subclasses:
AbstractApiComponent
,HeaderFilterStrategyComponent
,HealthCheckComponent
public abstract class DefaultComponent
extends org.apache.camel.support.service.ServiceSupport
implements org.apache.camel.Component
Default component to use for base for components implementations.
-
Field Summary
Fields inherited from class org.apache.camel.support.service.BaseService
BUILT, FAILED, INITIALIZED, INITIALIZING, lock, NEW, SHUTDOWN, SHUTTING_DOWN, STARTED, STARTING, status, STOPPED, STOPPING, SUSPENDED, SUSPENDING
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
afterConfiguration
(String uri, String remaining, org.apache.camel.Endpoint endpoint, Map<String, Object> parameters) Strategy to do post configuration logic.org.apache.camel.Endpoint
createEndpoint
(String uri) protected abstract org.apache.camel.Endpoint
A factory method allowing derived components to create a new endpoint from the given URI, remaining path and optional parametersorg.apache.camel.Endpoint
createEndpoint
(String uri, Map<String, Object> properties) protected void
doBuild()
protected void
doInit()
<T> T
Gets the parameter and remove it from the parameter map.<T> T
getAndRemoveOrResolveReferenceParameter
(Map<String, Object> parameters, String key, Class<T> type, T defaultValue) Gets the parameter and remove it from the parameter map.<T> T
Gets the parameter and remove it from the parameter map.<T> T
Gets the parameter and remove it from the parameter map.org.apache.camel.CamelContext
org.apache.camel.spi.PropertyConfigurer
org.apache.camel.spi.PropertyConfigurer
<T extends org.apache.camel.component.extension.ComponentExtension>
Optional<T>getExtension
(Class<T> extensionType) Collection<Class<? extends org.apache.camel.component.extension.ComponentExtension>>
protected String
ifStartsWithReturnRemainder
(String prefix, String text) Returns the reminder of the text if it starts with the prefix.boolean
boolean
boolean
protected void
registerExtension
(Supplier<org.apache.camel.component.extension.ComponentExtension> supplier) protected void
registerExtension
(org.apache.camel.component.extension.ComponentExtension extension) <T> List<T>
resolveAndRemoveReferenceListParameter
(Map<String, Object> parameters, String key, Class<T> elementType) Resolves a reference list parameter in the registry and removes it from the map.<T> List<T>
resolveAndRemoveReferenceListParameter
(Map<String, Object> parameters, String key, Class<T> elementType, List<T> defaultValue) Resolves a reference list parameter in the registry and removes it from the map.<T> T
Resolves a reference parameter in the registry and removes it from the map.<T> T
resolveAndRemoveReferenceParameter
(Map<String, Object> parameters, String key, Class<T> type, T defaultValue) Resolves a reference parameter in the registry and removes it from the map.protected boolean
Configure if the parameters using the RAW token syntax need to be resolved before being consumed bycreateEndpoint(String, Map)
.void
setAutowiredEnabled
(boolean autowiredEnabled) Whether autowiring is enabled.void
setBridgeErrorHandler
(boolean bridgeErrorHandler) Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler.void
setCamelContext
(org.apache.camel.CamelContext context) void
setLazyStartProducer
(boolean lazyStartProducer) Whether the producer should be started lazy (on the first message).protected void
setProperties
(Object bean, Map<String, Object> parameters) Sets the bean properties on the given beanprotected void
setProperties
(org.apache.camel.CamelContext camelContext, Object bean, Map<String, Object> parameters) Sets the bean properties on the given bean using the givenCamelContext
.protected void
setProperties
(org.apache.camel.Endpoint endpoint, Map<String, Object> parameters) Configure an endpoint using the given parameters.protected boolean
Derived classes may wish to overload this to prevent the default introspection of URI parameters on the createdEndpoint
instance.boolean
protected void
Strategy for validation of parameters, that was not able to be resolved to any endpoint options.protected void
Strategy for validation of the uri when creating the endpoint.Methods inherited from class org.apache.camel.support.service.BaseService
build, doFail, doLifecycleChange, doResume, doShutdown, doStart, doStop, doSuspend, fail, getStatus, init, isBuild, isInit, isNew, isRunAllowed, isShutdown, isStarted, isStarting, isStartingOrStarted, isStopped, isStopping, isStoppingOrStopped, isSuspended, isSuspending, isSuspendingOrSuspended, resume, shutdown, start, stop, suspend
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.apache.camel.Service
build, close, init, start, stop
Methods inherited from interface org.apache.camel.ShutdownableService
shutdown
Methods inherited from interface org.apache.camel.StatefulService
getStatus, isRunAllowed, isStarted, isStarting, isStopped, isStopping, isSuspending
Methods inherited from interface org.apache.camel.SuspendableService
isSuspended, resume, suspend
-
Constructor Details
-
DefaultComponent
public DefaultComponent() -
DefaultComponent
public DefaultComponent(org.apache.camel.CamelContext context)
-
-
Method Details
-
createEndpoint
public org.apache.camel.Endpoint createEndpoint(String uri, Map<String, Object> properties) throws Exception- Specified by:
createEndpoint
in interfaceorg.apache.camel.Component
- Throws:
Exception
-
createEndpoint
- Specified by:
createEndpoint
in interfaceorg.apache.camel.Component
- Throws:
Exception
-
useRawUri
public boolean useRawUri()- Specified by:
useRawUri
in interfaceorg.apache.camel.Component
-
isLazyStartProducer
public boolean isLazyStartProducer() -
setLazyStartProducer
public void setLazyStartProducer(boolean lazyStartProducer) Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel's routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing. -
isBridgeErrorHandler
public boolean isBridgeErrorHandler() -
setBridgeErrorHandler
public void setBridgeErrorHandler(boolean bridgeErrorHandler) Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN/ERROR level and ignored. -
isAutowiredEnabled
public boolean isAutowiredEnabled()- Specified by:
isAutowiredEnabled
in interfaceorg.apache.camel.Component
-
setAutowiredEnabled
public void setAutowiredEnabled(boolean autowiredEnabled) Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc. -
afterConfiguration
protected void afterConfiguration(String uri, String remaining, org.apache.camel.Endpoint endpoint, Map<String, Object> parameters) throws ExceptionStrategy to do post configuration logic. Can be used to construct an URI based on the remaining parameters. For example the parameters that configures the endpoint have been removed from the parameters which leaves only the additional parameters left.- Parameters:
uri
- the uriremaining
- the remaining part of the URI without the query parameters or component prefixendpoint
- the created endpointparameters
- the remaining parameters after the endpoint has been created and parsed the parameters- Throws:
Exception
- can be thrown to indicate error creating the endpoint
-
validateParameters
Strategy for validation of parameters, that was not able to be resolved to any endpoint options.- Parameters:
uri
- the uriparameters
- the parameters, an empty map if no parameters givenoptionPrefix
- optional prefix to filter the parameters for validation. Use null for validate all.- Throws:
org.apache.camel.ResolveEndpointFailedException
- should be thrown if the URI validation failed
-
validateURI
Strategy for validation of the uri when creating the endpoint.- Parameters:
uri
- the uripath
- the path - part after the schemeparameters
- the parameters, an empty map if no parameters given- Throws:
org.apache.camel.ResolveEndpointFailedException
- should be thrown if the URI validation failed
-
resolveRawParameterValues
protected boolean resolveRawParameterValues()Configure if the parameters using the RAW token syntax need to be resolved before being consumed bycreateEndpoint(String, Map)
. As the parameters are used to create an endpoint, by default they should have the token removed so its only the value we have in parameters however there are some cases where the endpoint may act as a proxy for another endpoint and you need to preserve the values as they are. -
getCamelContext
public org.apache.camel.CamelContext getCamelContext()- Specified by:
getCamelContext
in interfaceorg.apache.camel.spi.HasCamelContext
-
setCamelContext
public void setCamelContext(org.apache.camel.CamelContext context) - Specified by:
setCamelContext
in interfaceorg.apache.camel.CamelContextAware
-
getDefaultName
- Specified by:
getDefaultName
in interfaceorg.apache.camel.Component
-
doBuild
- Overrides:
doBuild
in classorg.apache.camel.support.service.BaseService
- Throws:
Exception
-
doInit
- Overrides:
doInit
in classorg.apache.camel.support.service.BaseService
- Throws:
Exception
-
createEndpoint
protected abstract org.apache.camel.Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws ExceptionA factory method allowing derived components to create a new endpoint from the given URI, remaining path and optional parameters- Parameters:
uri
- the full URI of the endpointremaining
- the remaining part of the URI without the query parameters or component prefixparameters
- the optional parameters passed in- Returns:
- a newly created endpoint or null if the endpoint cannot be created based on the inputs
- Throws:
Exception
- is thrown if error creating the endpoint
-
setProperties
protected void setProperties(org.apache.camel.Endpoint endpoint, Map<String, Object> parameters) throws ExceptionConfigure an endpoint using the given parameters. In the usual cases, this is the only call needed after having created the endpoint in thecreateEndpoint(String, String, Map)
method's implementation. This method will call theEndpoint.configureProperties(Map)
method which should delegate the the endpoint'sPropertyConfigurer
instance. In some rare cases, you need to override this method to explicitely set parameters in case a simple generated configurer can not be used.- Parameters:
endpoint
- the endpointparameters
- properties to set- Throws:
Exception
-
setProperties
Sets the bean properties on the given bean- Parameters:
bean
- the beanparameters
- properties to set- Throws:
Exception
-
setProperties
protected void setProperties(org.apache.camel.CamelContext camelContext, Object bean, Map<String, Object> parameters) throws ExceptionSets the bean properties on the given bean using the givenCamelContext
.- Parameters:
camelContext
- theCamelContext
to usebean
- the beanparameters
- properties to set- Throws:
Exception
-
getComponentPropertyConfigurer
public org.apache.camel.spi.PropertyConfigurer getComponentPropertyConfigurer()- Specified by:
getComponentPropertyConfigurer
in interfaceorg.apache.camel.Component
-
getEndpointPropertyConfigurer
public org.apache.camel.spi.PropertyConfigurer getEndpointPropertyConfigurer()- Specified by:
getEndpointPropertyConfigurer
in interfaceorg.apache.camel.Component
-
useIntrospectionOnEndpoint
protected boolean useIntrospectionOnEndpoint()Derived classes may wish to overload this to prevent the default introspection of URI parameters on the createdEndpoint
instance. -
getAndRemoveParameter
Gets the parameter and remove it from the parameter map. This method doesn't resolve reference parameters in the registry.- Parameters:
parameters
- the parameterskey
- the keytype
- the requested type to convert the value from the parameter- Returns:
- the converted value parameter, null if parameter does not exists.
- See Also:
-
getAndRemoveParameter
public <T> T getAndRemoveParameter(Map<String, Object> parameters, String key, Class<T> type, T defaultValue) Gets the parameter and remove it from the parameter map. This method doesn't resolve reference parameters in the registry.- Parameters:
parameters
- the parameterskey
- the keytype
- the requested type to convert the value from the parameterdefaultValue
- use this default value if the parameter does not contain the key- Returns:
- the converted value parameter
- See Also:
-
getAndRemoveOrResolveReferenceParameter
public <T> T getAndRemoveOrResolveReferenceParameter(Map<String, Object> parameters, String key, Class<T> type) Gets the parameter and remove it from the parameter map. This method resolves reference parameters in the registry as well.- Parameters:
parameters
- the parameterskey
- the keytype
- the requested type to convert the value from the parameter- Returns:
- the converted value parameter
-
getAndRemoveOrResolveReferenceParameter
public <T> T getAndRemoveOrResolveReferenceParameter(Map<String, Object> parameters, String key, Class<T> type, T defaultValue) Gets the parameter and remove it from the parameter map. This method resolves reference parameters in the registry as well.- Parameters:
parameters
- the parameterskey
- the keytype
- the requested type to convert the value from the parameterdefaultValue
- use this default value if the parameter does not contain the key- Returns:
- the converted value parameter
-
resolveAndRemoveReferenceParameter
public <T> T resolveAndRemoveReferenceParameter(Map<String, Object> parameters, String key, Class<T> type) Resolves a reference parameter in the registry and removes it from the map.- Type Parameters:
T
- type of object to lookup in the registry.- Parameters:
parameters
- parameter map.key
- parameter map key.type
- type of object to lookup in the registry.- Returns:
- the referenced object or
null
if the parameter map doesn't contain the key. - Throws:
IllegalArgumentException
- if a non-null reference was not found in registry.
-
resolveAndRemoveReferenceParameter
public <T> T resolveAndRemoveReferenceParameter(Map<String, Object> parameters, String key, Class<T> type, T defaultValue) Resolves a reference parameter in the registry and removes it from the map.- Type Parameters:
T
- type of object to lookup in the registry.- Parameters:
parameters
- parameter map.key
- parameter map key.type
- type of object to lookup in the registry.defaultValue
- default value to use if the parameter map doesn't contain the key.- Returns:
- the referenced object or the default value.
- Throws:
IllegalArgumentException
- if referenced object was not found in registry.
-
resolveAndRemoveReferenceListParameter
public <T> List<T> resolveAndRemoveReferenceListParameter(Map<String, Object> parameters, String key, Class<T> elementType) Resolves a reference list parameter in the registry and removes it from the map.- Parameters:
parameters
- parameter map.key
- parameter map key.elementType
- result list element type.- Returns:
- the list of referenced objects or an empty list if the parameter map doesn't contain the key.
- Throws:
IllegalArgumentException
- if any of the referenced objects was not found in registry.- See Also:
-
resolveAndRemoveReferenceListParameter
public <T> List<T> resolveAndRemoveReferenceListParameter(Map<String, Object> parameters, String key, Class<T> elementType, List<T> defaultValue) Resolves a reference list parameter in the registry and removes it from the map.- Parameters:
parameters
- parameter map.key
- parameter map key.elementType
- result list element type.defaultValue
- default value to use if the parameter map doesn't contain the key.- Returns:
- the list of referenced objects or the default value.
- Throws:
IllegalArgumentException
- if any of the referenced objects was not found in registry.- See Also:
-
ifStartsWithReturnRemainder
Returns the reminder of the text if it starts with the prefix. Is useable for string parameters that contains commands.- Parameters:
prefix
- the prefixtext
- the text- Returns:
- the reminder, or null if no reminder
-
registerExtension
protected void registerExtension(org.apache.camel.component.extension.ComponentExtension extension) -
registerExtension
protected void registerExtension(Supplier<org.apache.camel.component.extension.ComponentExtension> supplier) -
getSupportedExtensions
public Collection<Class<? extends org.apache.camel.component.extension.ComponentExtension>> getSupportedExtensions()- Specified by:
getSupportedExtensions
in interfaceorg.apache.camel.Component
-
getExtension
public <T extends org.apache.camel.component.extension.ComponentExtension> Optional<T> getExtension(Class<T> extensionType) - Specified by:
getExtension
in interfaceorg.apache.camel.Component
-