Package org.apache.camel.support
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 String
MODEL_DOCUMENTATION_PREFIX
-
Method Summary
All Methods Static Methods Concrete Methods 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 typestatic <T> T
findSingleByType(org.apache.camel.CamelContext camelContext, Class<T> type)
Look up a bean of the give type in theRegistry
on theCamelContext
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 prefixstatic List<org.apache.camel.Component>
getComponents(org.apache.camel.CamelContext camelContext, Predicate<org.apache.camel.Component> predicate)
Gets the components from the givenCamelContext
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 contextstatic List<org.apache.camel.Endpoint>
getEndpoints(org.apache.camel.CamelContext camelContext, Predicate<org.apache.camel.Endpoint> predicate)
Gets the endpoints from the givenCamelContext
that match with the given predicatestatic org.apache.camel.Endpoint
getMandatoryEndpoint(org.apache.camel.CamelContext camelContext, String uri)
Returns the mandatory endpoint for the given URI or theNoSuchEndpointException
is thrownstatic <T extends org.apache.camel.Endpoint>
TgetMandatoryEndpoint(org.apache.camel.CamelContext camelContext, String uri, Class<T> type)
Returns the mandatory endpoint for the given URI and type or theNoSuchEndpointException
is thrownstatic 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 theNoSuchEndpointException
is thrownstatic org.apache.camel.Endpoint
getMandatoryPrototypeEndpoint(org.apache.camel.CamelContext camelContext, String uri)
Returns the mandatory endpoint (prototype scope) for the given URI or theNoSuchEndpointException
is thrownstatic 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 theNoSuchEndpointException
is thrownstatic 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 theRestConfiguration
from theCamelContext
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 theRestConfiguration
from theCamelContext
and check if the component which consumes the configuration is compatible with the one for which the rest configuration is set-up.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 idstatic Object
lookup(org.apache.camel.CamelContext context, String name)
Look up the given named bean in theRegistry
on theCamelContext
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 theRegistry
on theCamelContext
static <T> T
lookupAndConvert(org.apache.camel.CamelContext context, String name, Class<T> beanType)
Look up the given named bean in theRegistry
on theCamelContext
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 anIllegalArgumentException
if the value could not be converted to a non null valuestatic Object
mandatoryLookup(org.apache.camel.CamelContext context, String name)
Look up the given named bean in theRegistry
on theCamelContext
or throwsNoSuchBeanException
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 theRegistry
on theCamelContext
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 theRegistry
on theCamelContext
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 theInjector
on the givenCamelContext
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 wellstatic Boolean
parseBoolean(org.apache.camel.CamelContext camelContext, String text)
Parses the given text and converts it to an Boolean and handling property placeholders as wellstatic Double
parseDouble(org.apache.camel.CamelContext camelContext, String text)
Parses the given text and converts it to a Double and handling property placeholders as wellstatic Duration
parseDuration(org.apache.camel.CamelContext camelContext, String text)
Parses the given text and converts it to a Duration and handling property placeholders as wellstatic Float
parseFloat(org.apache.camel.CamelContext camelContext, String text)
Parses the given text and converts it to a Float and handling property placeholders as wellstatic Integer
parseInt(org.apache.camel.CamelContext camelContext, String text)
Parses the given text and converts it to an Integer and handling property placeholders as wellstatic Integer
parseInteger(org.apache.camel.CamelContext camelContext, String text)
Parses the given text and converts it to an Integer and handling property placeholders as wellstatic Long
parseLong(org.apache.camel.CamelContext camelContext, String text)
Parses the given text and converts it to an Long and handling property placeholders as wellstatic String
parseText(org.apache.camel.CamelContext camelContext, String text)
Parses the given text and handling property placeholders as wellstatic 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
-
-
-
Field Detail
-
MODEL_DOCUMENTATION_PREFIX
public static final String MODEL_DOCUMENTATION_PREFIX
- See Also:
- Constant Field Values
-
-
Method Detail
-
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 theNoSuchEndpointException
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 theNoSuchEndpointException
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 theNoSuchEndpointException
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 theNoSuchEndpointException
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 theNoSuchEndpointException
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 anIllegalArgumentException
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 theInjector
on the givenCamelContext
-
lookup
public static Object lookup(org.apache.camel.CamelContext context, String name)
Look up the given named bean in theRegistry
on theCamelContext
-
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 theRegistry
on theCamelContext
-
lookupAndConvert
public static <T> T lookupAndConvert(org.apache.camel.CamelContext context, String name, Class<T> beanType)
Look up the given named bean in theRegistry
on theCamelContext
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 theRegistry
on theCamelContext
returning an instance if only one bean is present,
-
mandatoryLookup
public static Object mandatoryLookup(org.apache.camel.CamelContext context, String name)
Look up the given named bean in theRegistry
on theCamelContext
or throwsNoSuchBeanException
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 theRegistry
on theCamelContext
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 theRegistry
on theCamelContext
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 keyExchange.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 keyExchange.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 keyExchange.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 keyExchange.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 keyExchange.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 contexttext
- 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 contexttext
- 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 contexttext
- 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 contexttext
- 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 contexttext
- 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 contexttext
- 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 contexttext
- 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 contexttext
- 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 contextclazz
- the class to convert the value totext
- 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 contextrouteId
- 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 prefixcamelContext
- 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
-
getRestConfiguration
public static org.apache.camel.spi.RestConfiguration getRestConfiguration(org.apache.camel.CamelContext camelContext, String component)
Gets theRestConfiguration
from theCamelContext
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 contextcomponent
- the component that will consume theRestConfiguration
- Returns:
- the
RestConfiguration
- Throws:
IllegalArgumentException
- is the component is not compatible with theRestConfiguration
set-up
-
getRestConfiguration
public static org.apache.camel.spi.RestConfiguration getRestConfiguration(org.apache.camel.CamelContext camelContext, String component, String producerComponent)
Gets theRestConfiguration
from theCamelContext
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 contextcomponent
- the component that will consume theRestConfiguration
producerComponent
- the producer component that will consume theRestConfiguration
- Returns:
- the
RestConfiguration
- Throws:
IllegalArgumentException
- is the component is not compatible with theRestConfiguration
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 givenCamelContext
that match with the given predicate.- Parameters:
camelContext
- the camel contextpredicate
- 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 givenCamelContext
that match with the given predicate- Parameters:
camelContext
- the camel contextpredicate
- the predicate to evaluate to know whether a given endpoint should be returned or not.- Returns:
- the existing endpoints that match the predicate.
-
-