Class CamelContextHelper

java.lang.Object
org.apache.camel.support.CamelContextHelper

public final class CamelContextHelper extends Object
A number of helper methods
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static <T> T
    convertTo(org.apache.camel.CamelContext context, Class<T> type, Object value)
    Converts the given value to the requested type
    static <T> T
    findSingleByType(org.apache.camel.CamelContext camelContext, Class<T> type)
    Look up a bean of the give type in the Registry on the CamelContext returning an instance if only one bean is present,
    static Properties
    getCamelPropertiesWithPrefix(String prefix, org.apache.camel.CamelContext camelContext)
    A helper method to access a camel context properties with a prefix
    static List<org.apache.camel.Component>
    getComponents(org.apache.camel.CamelContext camelContext, Predicate<org.apache.camel.Component> predicate)
    Gets the components from the given CamelContext that match with the given predicate.
    static org.apache.camel.Endpoint
    getEndpointInjection(org.apache.camel.CamelContext camelContext, String uri, String injectionPointName, boolean mandatory)
    Evaluates the @EndpointInject annotation using the given context
    static List<org.apache.camel.Endpoint>
    getEndpoints(org.apache.camel.CamelContext camelContext, Predicate<org.apache.camel.Endpoint> predicate)
    Gets the endpoints from the given CamelContext that match with the given predicate
    static org.apache.camel.Endpoint
    getMandatoryEndpoint(org.apache.camel.CamelContext camelContext, String uri)
    Returns the mandatory endpoint for the given URI or the NoSuchEndpointException is thrown
    static <T extends org.apache.camel.Endpoint>
    T
    getMandatoryEndpoint(org.apache.camel.CamelContext camelContext, String uri, Class<T> type)
    Returns the mandatory endpoint for the given URI and type or the NoSuchEndpointException is thrown
    static org.apache.camel.Endpoint
    getMandatoryEndpoint(org.apache.camel.CamelContext camelContext, org.apache.camel.spi.NormalizedEndpointUri uri)
    Returns the mandatory endpoint for the given URI or the NoSuchEndpointException is thrown
    static org.apache.camel.Endpoint
    getMandatoryPrototypeEndpoint(org.apache.camel.CamelContext camelContext, String uri)
    Returns the mandatory endpoint (prototype scope) for the given URI or the NoSuchEndpointException is thrown
    static org.apache.camel.Endpoint
    getMandatoryPrototypeEndpoint(org.apache.camel.CamelContext camelContext, org.apache.camel.spi.NormalizedEndpointUri uri)
    Returns the mandatory endpoint (prototype scope) for the given URI or the NoSuchEndpointException is thrown
    static int
    getMaximumCachePoolSize(org.apache.camel.CamelContext camelContext)
    Gets the maximum cache pool size.
    static int
    getMaximumEndpointCacheSize(org.apache.camel.CamelContext camelContext)
    Gets the maximum endpoint cache size.
    static int
    getMaximumSimpleCacheSize(org.apache.camel.CamelContext camelContext)
    Gets the maximum simple cache size.
    static int
    getMaximumTransformerCacheSize(org.apache.camel.CamelContext camelContext)
    Gets the maximum transformer cache size.
    static int
    getMaximumValidatorCacheSize(org.apache.camel.CamelContext camelContext)
    Gets the maximum validator cache size.
    static org.apache.camel.spi.RestConfiguration
    getRestConfiguration(org.apache.camel.CamelContext camelContext, String component)
    Gets the RestConfiguration from the CamelContext and check if the component which consumes the configuration is compatible with the one for which the rest configuration is set-up.
    static org.apache.camel.spi.RestConfiguration
    getRestConfiguration(org.apache.camel.CamelContext camelContext, String component, String producerComponent)
    Gets the RestConfiguration from the CamelContext and check if the component which consumes the configuration is compatible with the one for which the rest configuration is set-up.
    static org.apache.camel.NamedRoute
    getRoute(org.apache.camel.NamedNode node)
    Gets the route the given node belongs to.
    static String
    getRouteId(org.apache.camel.NamedNode node)
    Gets the route id the given node belongs to.
    static int
    getRouteStartupOrder(org.apache.camel.CamelContext camelContext, String routeId)
    Gets the route startup order for the given route id
    static Date
    getStartDate(org.apache.camel.CamelContext context)
    Gets the date and time Camel was started up.
    static String
    getUptime(org.apache.camel.CamelContext context)
    Gets the uptime in a human-readable format
    static long
    getUptimeMillis(org.apache.camel.CamelContext context)
    Gets the uptime in milliseconds
    static Object
    lookup(org.apache.camel.CamelContext context, String name)
    Look up the given named bean in the Registry on the CamelContext
    static <T> T
    lookup(org.apache.camel.CamelContext context, String name, Class<T> beanType)
    Look up the given named bean of the given type in the Registry on the CamelContext
    static <T> T
    lookupAndConvert(org.apache.camel.CamelContext context, String name, Class<T> beanType)
    Look up the given named bean in the Registry on the CamelContext and try to convert it to the given type.
    static <T> T
    mandatoryConvertTo(org.apache.camel.CamelContext context, Class<T> type, Object value)
    Converts the given value to the specified type throwing an IllegalArgumentException if the value could not be converted to a non null value
    static <T> T
    mandatoryFindSingleByType(org.apache.camel.CamelContext camelContext, Class<T> type)
    Look up a bean of the give type in the Registry on the CamelContext or throws NoSuchBeanTypeException if not a single bean was found.
    static Object
    mandatoryLookup(org.apache.camel.CamelContext context, String name)
    Look up the given named bean in the Registry on the CamelContext or throws NoSuchBeanException if not found.
    static <T> T
    mandatoryLookup(org.apache.camel.CamelContext context, String name, Class<T> beanType)
    Look up the given named bean of the given type in the Registry on the CamelContext or throws NoSuchBeanException if not found.
    static <T> T
    mandatoryLookupAndConvert(org.apache.camel.CamelContext context, String name, Class<T> beanType)
    Look up the given named bean in the Registry on the CamelContext and convert it to the given type or throws NoSuchBeanException if not found.
    static <T> T
    newInstance(org.apache.camel.CamelContext context, Class<T> beanType)
    Creates a new instance of the given type using the Injector on the given CamelContext
    static <T> T
    parse(org.apache.camel.CamelContext camelContext, Class<T> clazz, String text)
    Parses the given text and converts it to the specified class and handling property placeholders as well
    static Boolean
    parseBoolean(org.apache.camel.CamelContext camelContext, String text)
    Parses the given text and converts it to an Boolean and handling property placeholders as well
    static Double
    parseDouble(org.apache.camel.CamelContext camelContext, String text)
    Parses the given text and converts it to a Double and handling property placeholders as well
    static Duration
    parseDuration(org.apache.camel.CamelContext camelContext, String text)
    Parses the given text and converts it to a Duration and handling property placeholders as well
    static Float
    parseFloat(org.apache.camel.CamelContext camelContext, String text)
    Parses the given text and converts it to a Float and handling property placeholders as well
    static Integer
    parseInt(org.apache.camel.CamelContext camelContext, String text)
    Parses the given text and converts it to an Integer and handling property placeholders as well
    static Integer
    parseInteger(org.apache.camel.CamelContext camelContext, String text)
    Parses the given text and converts it to an Integer and handling property placeholders as well
    static Long
    parseLong(org.apache.camel.CamelContext camelContext, String text)
    Parses the given text and converts it to an Long and handling property placeholders as well
    static String
    parseText(org.apache.camel.CamelContext camelContext, String text)
    Parses the given text and handling property placeholders as well
    static org.apache.camel.Endpoint
    resolveEndpoint(org.apache.camel.CamelContext camelContext, String uri, String ref)
     
    static <T> T
    tryConvertTo(org.apache.camel.CamelContext context, Class<T> type, Object value)
    Tried to convert the given value to the requested type

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Method Details

    • getMandatoryEndpoint

      public static org.apache.camel.Endpoint getMandatoryEndpoint(org.apache.camel.CamelContext camelContext, String uri) throws org.apache.camel.NoSuchEndpointException
      Returns the mandatory endpoint for the given URI or the NoSuchEndpointException is thrown
      Throws:
      org.apache.camel.NoSuchEndpointException
    • getMandatoryEndpoint

      public static org.apache.camel.Endpoint getMandatoryEndpoint(org.apache.camel.CamelContext camelContext, org.apache.camel.spi.NormalizedEndpointUri uri) throws org.apache.camel.NoSuchEndpointException
      Returns the mandatory endpoint for the given URI or the NoSuchEndpointException is thrown
      Throws:
      org.apache.camel.NoSuchEndpointException
    • getMandatoryPrototypeEndpoint

      public static org.apache.camel.Endpoint getMandatoryPrototypeEndpoint(org.apache.camel.CamelContext camelContext, String uri) throws org.apache.camel.NoSuchEndpointException
      Returns the mandatory endpoint (prototype scope) for the given URI or the NoSuchEndpointException is thrown
      Throws:
      org.apache.camel.NoSuchEndpointException
    • getMandatoryPrototypeEndpoint

      public static org.apache.camel.Endpoint getMandatoryPrototypeEndpoint(org.apache.camel.CamelContext camelContext, org.apache.camel.spi.NormalizedEndpointUri uri) throws org.apache.camel.NoSuchEndpointException
      Returns the mandatory endpoint (prototype scope) for the given URI or the NoSuchEndpointException is thrown
      Throws:
      org.apache.camel.NoSuchEndpointException
    • getMandatoryEndpoint

      public static <T extends org.apache.camel.Endpoint> T getMandatoryEndpoint(org.apache.camel.CamelContext camelContext, String uri, Class<T> type)
      Returns the mandatory endpoint for the given URI and type or the NoSuchEndpointException is thrown
    • resolveEndpoint

      public static org.apache.camel.Endpoint resolveEndpoint(org.apache.camel.CamelContext camelContext, String uri, String ref)
    • convertTo

      public static <T> T convertTo(org.apache.camel.CamelContext context, Class<T> type, Object value)
      Converts the given value to the requested type
    • tryConvertTo

      public static <T> T tryConvertTo(org.apache.camel.CamelContext context, Class<T> type, Object value)
      Tried to convert the given value to the requested type
    • mandatoryConvertTo

      public static <T> T mandatoryConvertTo(org.apache.camel.CamelContext context, Class<T> type, Object value)
      Converts the given value to the specified type throwing an IllegalArgumentException if the value could not be converted to a non null value
    • newInstance

      public static <T> T newInstance(org.apache.camel.CamelContext context, Class<T> beanType)
      Creates a new instance of the given type using the Injector on the given CamelContext
    • lookup

      public static Object lookup(org.apache.camel.CamelContext context, String name)
      Look up the given named bean in the Registry on the CamelContext
    • lookup

      public static <T> T lookup(org.apache.camel.CamelContext context, String name, Class<T> beanType)
      Look up the given named bean of the given type in the Registry on the CamelContext
    • lookupAndConvert

      public static <T> T lookupAndConvert(org.apache.camel.CamelContext context, String name, Class<T> beanType)
      Look up the given named bean in the Registry on the CamelContext and try to convert it to the given type.
    • findSingleByType

      public static <T> T findSingleByType(org.apache.camel.CamelContext camelContext, Class<T> type)
      Look up a bean of the give type in the Registry on the CamelContext returning an instance if only one bean is present,
    • mandatoryFindSingleByType

      public static <T> T mandatoryFindSingleByType(org.apache.camel.CamelContext camelContext, Class<T> type)
      Look up a bean of the give type in the Registry on the CamelContext or throws NoSuchBeanTypeException if not a single bean was found.
    • mandatoryLookup

      public static Object mandatoryLookup(org.apache.camel.CamelContext context, String name)
      Look up the given named bean in the Registry on the CamelContext or throws NoSuchBeanException if not found.
    • mandatoryLookup

      public static <T> T mandatoryLookup(org.apache.camel.CamelContext context, String name, Class<T> beanType)
      Look up the given named bean of the given type in the Registry on the CamelContext or throws NoSuchBeanException if not found.
    • mandatoryLookupAndConvert

      public static <T> T mandatoryLookupAndConvert(org.apache.camel.CamelContext context, String name, Class<T> beanType)
      Look up the given named bean in the Registry on the CamelContext and convert it to the given type or throws NoSuchBeanException if not found.
    • getEndpointInjection

      public static org.apache.camel.Endpoint getEndpointInjection(org.apache.camel.CamelContext camelContext, String uri, String injectionPointName, boolean mandatory)
      Evaluates the @EndpointInject annotation using the given context
    • getMaximumCachePoolSize

      public static int getMaximumCachePoolSize(org.apache.camel.CamelContext camelContext) throws IllegalArgumentException
      Gets the maximum cache pool size.

      Will use the property set on CamelContext with the key Exchange.MAXIMUM_CACHE_POOL_SIZE. If no property has been set, then it will fallback to return a size of 1000.

      Parameters:
      camelContext - the camel context
      Returns:
      the maximum cache size
      Throws:
      IllegalArgumentException - is thrown if the property is illegal
    • getMaximumEndpointCacheSize

      public static int getMaximumEndpointCacheSize(org.apache.camel.CamelContext camelContext) throws IllegalArgumentException
      Gets the maximum endpoint cache size.

      Will use the property set on CamelContext with the key Exchange.MAXIMUM_ENDPOINT_CACHE_SIZE. If no property has been set, then it will fallback to return a size of 1000.

      Parameters:
      camelContext - the camel context
      Returns:
      the maximum cache size
      Throws:
      IllegalArgumentException - is thrown if the property is illegal
    • getMaximumSimpleCacheSize

      public static int getMaximumSimpleCacheSize(org.apache.camel.CamelContext camelContext) throws IllegalArgumentException
      Gets the maximum simple cache size.

      Will use the property set on CamelContext with the key Exchange.MAXIMUM_SIMPLE_CACHE_SIZE. If no property has been set, then it will fallback to return a size of 1000. Use value of 0 or negative to disable the cache.

      Parameters:
      camelContext - the camel context
      Returns:
      the maximum cache size
      Throws:
      IllegalArgumentException - is thrown if the property is illegal
    • getMaximumTransformerCacheSize

      public static int getMaximumTransformerCacheSize(org.apache.camel.CamelContext camelContext) throws IllegalArgumentException
      Gets the maximum transformer cache size.

      Will use the property set on CamelContext with the key Exchange.MAXIMUM_TRANSFORMER_CACHE_SIZE. If no property has been set, then it will fallback to return a size of 1000.

      Parameters:
      camelContext - the camel context
      Returns:
      the maximum cache size
      Throws:
      IllegalArgumentException - is thrown if the property is illegal
    • getMaximumValidatorCacheSize

      public static int getMaximumValidatorCacheSize(org.apache.camel.CamelContext camelContext) throws IllegalArgumentException
      Gets the maximum validator cache size.

      Will use the property set on CamelContext with the key Exchange.MAXIMUM_VALIDATOR_CACHE_SIZE. If no property has been set, then it will fallback to return a size of 1000.

      Parameters:
      camelContext - the camel context
      Returns:
      the maximum cache size
      Throws:
      IllegalArgumentException - is thrown if the property is illegal
    • parseText

      public static String parseText(org.apache.camel.CamelContext camelContext, String text)
      Parses the given text and handling property placeholders as well
      Parameters:
      camelContext - the camel context
      text - the text
      Returns:
      the parsed text, or null if the text was null
      Throws:
      IllegalStateException - is thrown if illegal argument
    • parseInteger

      public static Integer parseInteger(org.apache.camel.CamelContext camelContext, String text)
      Parses the given text and converts it to an Integer and handling property placeholders as well
      Parameters:
      camelContext - the camel context
      text - the text
      Returns:
      the integer vale, or null if the text was null
      Throws:
      IllegalStateException - is thrown if illegal argument or type conversion not possible
    • parseInt

      public static Integer parseInt(org.apache.camel.CamelContext camelContext, String text)
      Parses the given text and converts it to an Integer and handling property placeholders as well
      Parameters:
      camelContext - the camel context
      text - the text
      Returns:
      the int value, or null if the text was null
      Throws:
      IllegalStateException - is thrown if illegal argument or type conversion not possible
    • parseLong

      public static Long parseLong(org.apache.camel.CamelContext camelContext, String text)
      Parses the given text and converts it to an Long and handling property placeholders as well
      Parameters:
      camelContext - the camel context
      text - the text
      Returns:
      the long value, or null if the text was null
      Throws:
      IllegalStateException - is thrown if illegal argument or type conversion not possible
    • parseDuration

      public static Duration parseDuration(org.apache.camel.CamelContext camelContext, String text)
      Parses the given text and converts it to a Duration and handling property placeholders as well
      Parameters:
      camelContext - the camel context
      text - the text
      Returns:
      the Duration value, or null if the text was null
      Throws:
      IllegalStateException - is thrown if illegal argument or type conversion not possible
    • parseFloat

      public static Float parseFloat(org.apache.camel.CamelContext camelContext, String text)
      Parses the given text and converts it to a Float and handling property placeholders as well
      Parameters:
      camelContext - the camel context
      text - the text
      Returns:
      the float value, or null if the text was null
      Throws:
      IllegalStateException - is thrown if illegal argument or type conversion not possible
    • parseDouble

      public static Double parseDouble(org.apache.camel.CamelContext camelContext, String text)
      Parses the given text and converts it to a Double and handling property placeholders as well
      Parameters:
      camelContext - the camel context
      text - the text
      Returns:
      the double vale, or null if the text was null
      Throws:
      IllegalStateException - is thrown if illegal argument or type conversion not possible
    • parseBoolean

      public static Boolean parseBoolean(org.apache.camel.CamelContext camelContext, String text)
      Parses the given text and converts it to an Boolean and handling property placeholders as well
      Parameters:
      camelContext - the camel context
      text - the text
      Returns:
      the boolean vale, or null if the text was null
      Throws:
      IllegalArgumentException - is thrown if illegal argument or type conversion not possible
    • parse

      public static <T> T parse(org.apache.camel.CamelContext camelContext, Class<T> clazz, String text)
      Parses the given text and converts it to the specified class and handling property placeholders as well
      Parameters:
      camelContext - the camel context
      clazz - the class to convert the value to
      text - the text
      Returns:
      the boolean vale, or null if the text was null
      Throws:
      IllegalArgumentException - is thrown if illegal argument or type conversion not possible
    • getRouteStartupOrder

      public static int getRouteStartupOrder(org.apache.camel.CamelContext camelContext, String routeId)
      Gets the route startup order for the given route id
      Parameters:
      camelContext - the camel context
      routeId - the id of the route
      Returns:
      the startup order, or 0 if not possible to determine
    • getCamelPropertiesWithPrefix

      public static Properties getCamelPropertiesWithPrefix(String prefix, org.apache.camel.CamelContext camelContext)
      A helper method to access a camel context properties with a prefix
      Parameters:
      prefix - the prefix
      camelContext - the camel context
      Returns:
      the properties which holds the camel context properties with the prefix, and the key omit the prefix part
    • getRouteId

      public static String getRouteId(org.apache.camel.NamedNode node)
      Gets the route id the given node belongs to.
      Parameters:
      node - the node
      Returns:
      the route id, or null if not possible to find
    • getRoute

      public static org.apache.camel.NamedRoute getRoute(org.apache.camel.NamedNode node)
      Gets the route the given node belongs to.
      Parameters:
      node - the node
      Returns:
      the route, or null if not possible to find
    • getRestConfiguration

      public static org.apache.camel.spi.RestConfiguration getRestConfiguration(org.apache.camel.CamelContext camelContext, String component)
      Gets the RestConfiguration from the CamelContext and check if the component which consumes the configuration is compatible with the one for which the rest configuration is set-up.
      Parameters:
      camelContext - the camel context
      component - the component that will consume the RestConfiguration
      Returns:
      the RestConfiguration
      Throws:
      IllegalArgumentException - is the component is not compatible with the RestConfiguration set-up
    • getRestConfiguration

      public static org.apache.camel.spi.RestConfiguration getRestConfiguration(org.apache.camel.CamelContext camelContext, String component, String producerComponent)
      Gets the RestConfiguration from the CamelContext and check if the component which consumes the configuration is compatible with the one for which the rest configuration is set-up.
      Parameters:
      camelContext - the camel context
      component - the component that will consume the RestConfiguration
      producerComponent - the producer component that will consume the RestConfiguration
      Returns:
      the RestConfiguration
      Throws:
      IllegalArgumentException - is the component is not compatible with the RestConfiguration set-up
    • getComponents

      public static List<org.apache.camel.Component> getComponents(org.apache.camel.CamelContext camelContext, Predicate<org.apache.camel.Component> predicate)
      Gets the components from the given CamelContext that match with the given predicate.
      Parameters:
      camelContext - the camel context
      predicate - the predicate to evaluate to know whether a given component should be returned or not.
      Returns:
      the existing components that match the predicate.
    • getEndpoints

      public static List<org.apache.camel.Endpoint> getEndpoints(org.apache.camel.CamelContext camelContext, Predicate<org.apache.camel.Endpoint> predicate)
      Gets the endpoints from the given CamelContext that match with the given predicate
      Parameters:
      camelContext - the camel context
      predicate - the predicate to evaluate to know whether a given endpoint should be returned or not.
      Returns:
      the existing endpoints that match the predicate.
    • getUptime

      public static String getUptime(org.apache.camel.CamelContext context)
      Gets the uptime in a human-readable format
      Returns:
      the uptime in days/hours/minutes
    • getUptimeMillis

      public static long getUptimeMillis(org.apache.camel.CamelContext context)
      Gets the uptime in milliseconds
      Returns:
      the uptime in milliseconds
    • getStartDate

      public static Date getStartDate(org.apache.camel.CamelContext context)
      Gets the date and time Camel was started up.