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.
  • 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 interface org.apache.camel.Component
      Throws:
      Exception
    • createEndpoint

      public org.apache.camel.Endpoint createEndpoint(String uri) throws Exception
      Specified by:
      createEndpoint in interface org.apache.camel.Component
      Throws:
      Exception
    • useRawUri

      public boolean useRawUri()
      Specified by:
      useRawUri in interface org.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 (if possible) occurred while the Camel consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. Important: This is only possible if the 3rd party component allows Camel to be alerted if an exception was thrown. Some components handle this internally only, and therefore bridgeErrorHandler is not possible. In other situations we may improve the Camel component to hook into the 3rd party component and make this possible for future releases.

      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 interface org.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 Exception
      Strategy 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 uri
      remaining - the remaining part of the URI without the query parameters or component prefix
      endpoint - the created endpoint
      parameters - 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

      protected void validateParameters(String uri, Map<String,Object> parameters, String optionPrefix)
      Strategy for validation of parameters, that was not able to be resolved to any endpoint options.
      Parameters:
      uri - the uri
      parameters - the parameters, an empty map if no parameters given
      optionPrefix - 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

      protected void validateURI(String uri, String path, Map<String,Object> parameters)
      Strategy for validation of the uri when creating the endpoint.
      Parameters:
      uri - the uri
      path - the path - part after the scheme
      parameters - 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 by createEndpoint(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 interface org.apache.camel.spi.HasCamelContext
    • setCamelContext

      public void setCamelContext(org.apache.camel.CamelContext context)
      Specified by:
      setCamelContext in interface org.apache.camel.CamelContextAware
    • getDefaultName

      public String getDefaultName()
      Specified by:
      getDefaultName in interface org.apache.camel.Component
    • doBuild

      protected void doBuild() throws Exception
      Overrides:
      doBuild in class org.apache.camel.support.service.BaseService
      Throws:
      Exception
    • doInit

      protected void doInit() throws Exception
      Overrides:
      doInit in class org.apache.camel.support.service.BaseService
      Throws:
      Exception
    • createEndpoint

      protected abstract org.apache.camel.Endpoint createEndpoint(String uri, String remaining, Map<String,Object> parameters) throws Exception
      A 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 endpoint
      remaining - the remaining part of the URI without the query parameters or component prefix
      parameters - 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 Exception
      Configure an endpoint using the given parameters. In the usual cases, this is the only call needed after having created the endpoint in the createEndpoint(String, String, Map) method's implementation. This method will call the Endpoint.configureProperties(Map) method which should delegate the the endpoint's PropertyConfigurer 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 endpoint
      parameters - properties to set
      Throws:
      Exception
    • setProperties

      protected void setProperties(Object bean, Map<String,Object> parameters) throws Exception
      Sets the bean properties on the given bean
      Parameters:
      bean - the bean
      parameters - properties to set
      Throws:
      Exception
    • setProperties

      protected void setProperties(org.apache.camel.CamelContext camelContext, Object bean, Map<String,Object> parameters) throws Exception
      Sets the bean properties on the given bean using the given CamelContext.
      Parameters:
      camelContext - the CamelContext to use
      bean - the bean
      parameters - properties to set
      Throws:
      Exception
    • getComponentPropertyConfigurer

      public org.apache.camel.spi.PropertyConfigurer getComponentPropertyConfigurer()
      Specified by:
      getComponentPropertyConfigurer in interface org.apache.camel.Component
    • getEndpointPropertyConfigurer

      public org.apache.camel.spi.PropertyConfigurer getEndpointPropertyConfigurer()
      Specified by:
      getEndpointPropertyConfigurer in interface org.apache.camel.Component
    • useIntrospectionOnEndpoint

      protected boolean useIntrospectionOnEndpoint()
      Derived classes may wish to overload this to prevent the default introspection of URI parameters on the created Endpoint instance.
    • getAndRemoveParameter

      public <T> T getAndRemoveParameter(Map<String,Object> parameters, String key, Class<T> type)
      Gets the parameter and remove it from the parameter map. This method doesn't resolve reference parameters in the registry.
      Parameters:
      parameters - the parameters
      key - the key
      type - the requested type to convert the value from the parameter
      Returns:
      the converted value parameter, null if parameter does not exist.
      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 parameters
      key - the key
      type - the requested type to convert the value from the parameter
      defaultValue - 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 parameters
      key - the key
      type - 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 parameters
      key - the key
      type - the requested type to convert the value from the parameter
      defaultValue - 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

      protected String ifStartsWithReturnRemainder(String prefix, String text)
      Returns the reminder of the text if it starts with the prefix.

      Is useable for string parameters that contains commands.

      Parameters:
      prefix - the prefix
      text - 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 interface org.apache.camel.Component
    • getExtension

      public <T extends org.apache.camel.component.extension.ComponentExtension> Optional<T> getExtension(Class<T> extensionType)
      Specified by:
      getExtension in interface org.apache.camel.Component