Package org.apache.camel.support
Class EndpointHelper
- java.lang.Object
-
- org.apache.camel.support.EndpointHelper
-
public final class EndpointHelper extends Object
Some helper methods for working withEndpoint
instances
-
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static String
createEndpointId()
A helper method for Endpoint implementations to create new Ids for Endpoints which also implementHasId
static String
getRouteIdFromEndpoint(org.apache.camel.Endpoint endpoint)
Gets the route id for the given endpoint in which there is a consumer listening.static boolean
isReferenceParameter(String parameter)
Is the given parameter a reference parameter (starting with a # char)static String
lookupEndpointRegistryId(org.apache.camel.Endpoint endpoint)
Lookup the id the given endpoint has been enlisted with in theRegistry
.static boolean
matchEndpoint(org.apache.camel.CamelContext context, String uri, String pattern)
Matches the endpoint with the given pattern.static String
normalizeEndpointUri(String uri)
Normalize uri so we can do endpoint hits with minor mistakes and parameters is not in the same order.static void
pollEndpoint(org.apache.camel.Endpoint endpoint, org.apache.camel.Processor processor)
Creates aPollingConsumer
and polls all pending messages on the endpoint and invokes the givenProcessor
to process eachExchange
and then closes down the consumer and throws any exceptions thrown.static void
pollEndpoint(org.apache.camel.Endpoint endpoint, org.apache.camel.Processor processor, long timeout)
Creates aPollingConsumer
and polls all pending messages on the endpoint and invokes the givenProcessor
to process eachExchange
and then closes down the consumer and throws any exceptions thrown.static String
resolveEndpointUriPropertyPlaceholders(org.apache.camel.CamelContext camelContext, String uri)
Resolves the endpoint uri that may have property placeholders (supports optional property placeholders).static org.apache.camel.ExchangePattern
resolveExchangePatternFromUrl(String url)
Attempts to resolve if the url has an exchangePattern option configuredstatic <T> T
resolveParameter(org.apache.camel.CamelContext context, String value, Class<T> type)
Resolves a parameter, by doing a reference lookup if the parameter is a reference, and converting the parameter to the given type.static <T> List<T>
resolveReferenceListParameter(org.apache.camel.CamelContext context, String value, Class<T> elementType)
Resolves a reference list parameter by making lookups in the registry.static <T> T
resolveReferenceParameter(org.apache.camel.CamelContext context, String value, Class<T> type)
Resolves a reference parameter by making a lookup in the registry.static <T> T
resolveReferenceParameter(org.apache.camel.CamelContext context, String value, Class<T> type, boolean mandatory)
Resolves a reference parameter by making a lookup in the registry.static void
setProperties(org.apache.camel.CamelContext context, Object bean, Map<String,Object> parameters)
Deprecated.use PropertyBindingSupportstatic void
setReferenceProperties(org.apache.camel.CamelContext context, Object bean, Map<String,Object> parameters)
Deprecated.use PropertyBindingSupport
-
-
-
Method Detail
-
resolveEndpointUriPropertyPlaceholders
public static String resolveEndpointUriPropertyPlaceholders(org.apache.camel.CamelContext camelContext, String uri)
Resolves the endpoint uri that may have property placeholders (supports optional property placeholders).- Parameters:
camelContext
- the camel contexturi
- the endpoint uri- Returns:
- returns endpoint uri with property placeholders resolved
-
normalizeEndpointUri
public static String normalizeEndpointUri(String uri)
Normalize uri so we can do endpoint hits with minor mistakes and parameters is not in the same order.- Parameters:
uri
- the uri- Returns:
- normalized uri
- Throws:
org.apache.camel.ResolveEndpointFailedException
- if uri cannot be normalized
-
pollEndpoint
public static void pollEndpoint(org.apache.camel.Endpoint endpoint, org.apache.camel.Processor processor, long timeout) throws Exception
Creates aPollingConsumer
and polls all pending messages on the endpoint and invokes the givenProcessor
to process eachExchange
and then closes down the consumer and throws any exceptions thrown.- Throws:
Exception
-
pollEndpoint
public static void pollEndpoint(org.apache.camel.Endpoint endpoint, org.apache.camel.Processor processor) throws Exception
Creates aPollingConsumer
and polls all pending messages on the endpoint and invokes the givenProcessor
to process eachExchange
and then closes down the consumer and throws any exceptions thrown.- Throws:
Exception
-
matchEndpoint
public static boolean matchEndpoint(org.apache.camel.CamelContext context, String uri, String pattern)
Matches the endpoint with the given pattern. The endpoint will first resolve property placeholders usingresolveEndpointUriPropertyPlaceholders(CamelContext, String)
The match rules are applied in this order:- exact match, returns true
- wildcard match (pattern ends with a * and the uri starts with the pattern), returns true
- regular expression match, returns true
- exact match with uri normalization of the pattern if possible, returns true
- otherwise returns false
- Parameters:
context
- the Camel context, if null then property placeholder resolution is skipped.uri
- the endpoint uripattern
- a pattern to match- Returns:
- true if match, false otherwise.
-
setProperties
@Deprecated public static void setProperties(org.apache.camel.CamelContext context, Object bean, Map<String,Object> parameters) throws Exception
Deprecated.use PropertyBindingSupportSets the regular properties on the given bean- Parameters:
context
- the camel contextbean
- the beanparameters
- parameters- Throws:
Exception
- is thrown if setting property fails
-
setReferenceProperties
@Deprecated public static void setReferenceProperties(org.apache.camel.CamelContext context, Object bean, Map<String,Object> parameters) throws Exception
Deprecated.use PropertyBindingSupportSets the reference properties on the given bean This is convention over configuration, setting all reference parameters (usingisReferenceParameter(String)
by looking it up in registry and setting it on the bean if possible.- Parameters:
context
- the camel contextbean
- the beanparameters
- parameters- Throws:
Exception
- is thrown if setting property fails
-
isReferenceParameter
public static boolean isReferenceParameter(String parameter)
Is the given parameter a reference parameter (starting with a # char)- Parameters:
parameter
- the parameter- Returns:
- true if its a reference parameter
-
resolveReferenceParameter
public static <T> T resolveReferenceParameter(org.apache.camel.CamelContext context, String value, Class<T> type)
Resolves a reference parameter by making a lookup in the registry.- Type Parameters:
T
- type of object to lookup.- Parameters:
context
- Camel context to use for lookup.value
- reference parameter value.type
- type of object to lookup.- Returns:
- lookup result.
- Throws:
IllegalArgumentException
- if referenced object was not found in registry.
-
resolveReferenceParameter
public static <T> T resolveReferenceParameter(org.apache.camel.CamelContext context, String value, Class<T> type, boolean mandatory)
Resolves a reference parameter by making a lookup in the registry.- Type Parameters:
T
- type of object to lookup.- Parameters:
context
- Camel context to use for lookup.value
- reference parameter value.type
- type of object to lookup.- Returns:
- lookup result (or
null
only ifmandatory
isfalse
). - Throws:
org.apache.camel.NoSuchBeanException
- if object was not found in registry andmandatory
istrue
.
-
resolveReferenceListParameter
public static <T> List<T> resolveReferenceListParameter(org.apache.camel.CamelContext context, String value, Class<T> elementType)
Resolves a reference list parameter by making lookups in the registry. The parameter value must be one of the following:- a comma-separated list of references to beans of type T
- a single reference to a bean type T
- a single reference to a bean of type java.util.List
- Parameters:
context
- Camel context to use for lookup.value
- reference parameter value.elementType
- result list element type.- Returns:
- list of lookup results, will always return a list.
- Throws:
IllegalArgumentException
- if any referenced object was not found in registry.
-
resolveParameter
public static <T> T resolveParameter(org.apache.camel.CamelContext context, String value, Class<T> type)
Resolves a parameter, by doing a reference lookup if the parameter is a reference, and converting the parameter to the given type.- Type Parameters:
T
- type of object to convert the parameter value as.- Parameters:
context
- Camel context to use for lookup.value
- parameter or reference parameter value.type
- type of object to lookup.- Returns:
- lookup result if it was a reference parameter, or the value converted to the given type
- Throws:
IllegalArgumentException
- if referenced object was not found in registry.
-
getRouteIdFromEndpoint
public static String getRouteIdFromEndpoint(org.apache.camel.Endpoint endpoint)
Gets the route id for the given endpoint in which there is a consumer listening.- Parameters:
endpoint
- the endpoint- Returns:
- the route id, or null if none found
-
createEndpointId
public static String createEndpointId()
A helper method for Endpoint implementations to create new Ids for Endpoints which also implementHasId
-
lookupEndpointRegistryId
public static String lookupEndpointRegistryId(org.apache.camel.Endpoint endpoint)
Lookup the id the given endpoint has been enlisted with in theRegistry
.- Parameters:
endpoint
- the endpoint- Returns:
- the endpoint id, or null if not found
-
resolveExchangePatternFromUrl
public static org.apache.camel.ExchangePattern resolveExchangePatternFromUrl(String url)
Attempts to resolve if the url has an exchangePattern option configured- Parameters:
url
- the url- Returns:
- the exchange pattern, or null if the url has no exchangePattern configured.
-
-