Class EndpointHelper

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

public final class EndpointHelper extends Object
Some helper methods for working with Endpoint instances
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    A helper method for Endpoint implementations to create new Ids for Endpoints which also implement HasId
    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
    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 the Registry.
    static boolean
    matchEndpoint(org.apache.camel.CamelContext context, String uri, String pattern)
    Matches the endpoint with the given pattern.
    static String
    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 a PollingConsumer and polls all pending messages on the endpoint and invokes the given Processor to process each Exchange 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 a PollingConsumer and polls all pending messages on the endpoint and invokes the given Processor to process each Exchange 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
    Attempts to resolve if the url has an exchangePattern option configured
    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.
    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.

    Methods inherited from class java.lang.Object

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

    • 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 context
      uri - 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 a PollingConsumer and polls all pending messages on the endpoint and invokes the given Processor to process each Exchange 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 a PollingConsumer and polls all pending messages on the endpoint and invokes the given Processor to process each Exchange 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 using resolveEndpointUriPropertyPlaceholders(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 uri
      pattern - a pattern to match
      Returns:
      true if match, false otherwise.
    • 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 if mandatory is false).
      Throws:
      org.apache.camel.NoSuchBeanException - if object was not found in registry and mandatory is true.
    • 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 implement HasId
    • lookupEndpointRegistryId

      public static String lookupEndpointRegistryId(org.apache.camel.Endpoint endpoint)
      Lookup the id the given endpoint has been enlisted with in the Registry.
      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.