Package org.apache.camel.support
Class CamelContextHelper
java.lang.Object
org.apache.camel.support.CamelContextHelper
A number of helper methods
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> TConverts the given value to the requested typestatic <T> TfindSingleByType(org.apache.camel.CamelContext camelContext, Class<T> type) Look up a bean of the give type in theRegistryon theCamelContextreturning an instance if only one bean is present,static PropertiesgetCamelPropertiesWithPrefix(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 givenCamelContextthat match with the given predicate.static org.apache.camel.EndpointgetEndpointInjection(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 givenCamelContextthat match with the given predicatestatic org.apache.camel.EndpointgetMandatoryEndpoint(org.apache.camel.CamelContext camelContext, String uri) Returns the mandatory endpoint for the given URI or theNoSuchEndpointExceptionis 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 theNoSuchEndpointExceptionis thrownstatic org.apache.camel.EndpointgetMandatoryEndpoint(org.apache.camel.CamelContext camelContext, org.apache.camel.spi.NormalizedEndpointUri uri) Returns the mandatory endpoint for the given URI or theNoSuchEndpointExceptionis thrownstatic org.apache.camel.EndpointgetMandatoryPrototypeEndpoint(org.apache.camel.CamelContext camelContext, String uri) Returns the mandatory endpoint (prototype scope) for the given URI or theNoSuchEndpointExceptionis thrownstatic org.apache.camel.EndpointgetMandatoryPrototypeEndpoint(org.apache.camel.CamelContext camelContext, org.apache.camel.spi.NormalizedEndpointUri uri) Returns the mandatory endpoint (prototype scope) for the given URI or theNoSuchEndpointExceptionis thrownstatic intgetMaximumCachePoolSize(org.apache.camel.CamelContext camelContext) Gets the maximum cache pool size.static intgetMaximumEndpointCacheSize(org.apache.camel.CamelContext camelContext) Gets the maximum endpoint cache size.static intgetMaximumSimpleCacheSize(org.apache.camel.CamelContext camelContext) Gets the maximum simple cache size.static intgetMaximumTransformerCacheSize(org.apache.camel.CamelContext camelContext) Gets the maximum transformer cache size.static intgetMaximumValidatorCacheSize(org.apache.camel.CamelContext camelContext) Gets the maximum validator cache size.static org.apache.camel.spi.RestConfigurationgetRestConfiguration(org.apache.camel.CamelContext camelContext, String component) Gets theRestConfigurationfrom theCamelContextand 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.RestConfigurationgetRestConfiguration(org.apache.camel.CamelContext camelContext, String component, String producerComponent) Gets theRestConfigurationfrom theCamelContextand 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.NamedRoutegetRoute(org.apache.camel.NamedNode node) Gets the route the given node belongs to.static StringgetRouteId(org.apache.camel.NamedNode node) Gets the route id the given node belongs to.static intgetRouteStartupOrder(org.apache.camel.CamelContext camelContext, String routeId) Gets the route startup order for the given route idstatic DategetStartDate(org.apache.camel.CamelContext context) Gets the date and time Camel was started up.static StringgetUptime(org.apache.camel.CamelContext context) Gets the uptime in a human-readable formatstatic longgetUptimeMillis(org.apache.camel.CamelContext context) Gets the uptime in millisecondsstatic ObjectLook up the given named bean in theRegistryon theCamelContextstatic <T> TLook up the given named bean of the given type in theRegistryon theCamelContextstatic <T> TlookupAndConvert(org.apache.camel.CamelContext context, String name, Class<T> beanType) Look up the given named bean in theRegistryon theCamelContextand try to convert it to the given type.static <T> TmandatoryConvertTo(org.apache.camel.CamelContext context, Class<T> type, Object value) Converts the given value to the specified type throwing anIllegalArgumentExceptionif the value could not be converted to a non null valuestatic <T> TmandatoryFindSingleByType(org.apache.camel.CamelContext camelContext, Class<T> type) Look up a bean of the give type in theRegistryon theCamelContextor throwsNoSuchBeanTypeExceptionif not a single bean was found.static ObjectmandatoryLookup(org.apache.camel.CamelContext context, String name) Look up the given named bean in theRegistryon theCamelContextor throwsNoSuchBeanExceptionif not found.static <T> TmandatoryLookup(org.apache.camel.CamelContext context, String name, Class<T> beanType) Look up the given named bean of the given type in theRegistryon theCamelContextor throws NoSuchBeanException if not found.static <T> TmandatoryLookupAndConvert(org.apache.camel.CamelContext context, String name, Class<T> beanType) Look up the given named bean in theRegistryon theCamelContextand convert it to the given type or throws NoSuchBeanException if not found.static <T> TnewInstance(org.apache.camel.CamelContext context, Class<T> beanType) Creates a new instance of the given type using theInjectoron the givenCamelContextstatic <T> TParses the given text and converts it to the specified class and handling property placeholders as wellstatic BooleanparseBoolean(org.apache.camel.CamelContext camelContext, String text) Parses the given text and converts it to an Boolean and handling property placeholders as wellstatic DoubleparseDouble(org.apache.camel.CamelContext camelContext, String text) Parses the given text and converts it to a Double and handling property placeholders as wellstatic DurationparseDuration(org.apache.camel.CamelContext camelContext, String text) Parses the given text and converts it to a Duration and handling property placeholders as wellstatic FloatparseFloat(org.apache.camel.CamelContext camelContext, String text) Parses the given text and converts it to a Float and handling property placeholders as wellstatic IntegerParses the given text and converts it to an Integer and handling property placeholders as wellstatic IntegerparseInteger(org.apache.camel.CamelContext camelContext, String text) Parses the given text and converts it to an Integer and handling property placeholders as wellstatic LongParses the given text and converts it to an Long and handling property placeholders as wellstatic StringParses the given text and handling property placeholders as wellstatic org.apache.camel.EndpointresolveEndpoint(org.apache.camel.CamelContext camelContext, String uri, String ref) static <T> TtryConvertTo(org.apache.camel.CamelContext context, Class<T> type, Object value) Tried to convert the given value to the requested type
-
Field Details
-
MODEL_DOCUMENTATION_PREFIX
- See Also:
-
-
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 theNoSuchEndpointExceptionis 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 theNoSuchEndpointExceptionis 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 theNoSuchEndpointExceptionis 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 theNoSuchEndpointExceptionis 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 theNoSuchEndpointExceptionis thrown -
resolveEndpoint
-
convertTo
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 anIllegalArgumentExceptionif the value could not be converted to a non null value -
newInstance
Creates a new instance of the given type using theInjectoron the givenCamelContext -
lookup
Look up the given named bean in theRegistryon theCamelContext -
lookup
Look up the given named bean of the given type in theRegistryon theCamelContext -
lookupAndConvert
public static <T> T lookupAndConvert(org.apache.camel.CamelContext context, String name, Class<T> beanType) Look up the given named bean in theRegistryon theCamelContextand try to convert it to the given type. -
findSingleByType
Look up a bean of the give type in theRegistryon theCamelContextreturning 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 theRegistryon theCamelContextor throwsNoSuchBeanTypeExceptionif not a single bean was found. -
mandatoryLookup
Look up the given named bean in theRegistryon theCamelContextor throwsNoSuchBeanExceptionif 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 theRegistryon theCamelContextor 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 theRegistryon theCamelContextand 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
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
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
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
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
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
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
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
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
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
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
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 theRestConfigurationfrom theCamelContextand 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 theRestConfigurationset-up
-
getRestConfiguration
public static org.apache.camel.spi.RestConfiguration getRestConfiguration(org.apache.camel.CamelContext camelContext, String component, String producerComponent) Gets theRestConfigurationfrom theCamelContextand 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 theRestConfigurationproducerComponent- the producer component that will consume theRestConfiguration- Returns:
- the
RestConfiguration - Throws:
IllegalArgumentException- is the component is not compatible with theRestConfigurationset-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 givenCamelContextthat 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 givenCamelContextthat 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.
-
getUptime
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
Gets the date and time Camel was started up.
-