org.apache.camel.util
Class EndpointHelper

java.lang.Object
  extended by org.apache.camel.util.EndpointHelper

public final class EndpointHelper
extends Object

Some helper methods for working with Endpoint instances

Version:

Method Summary
static String browseRangeMessagesAsXml(BrowsableEndpoint endpoint, Integer fromIndex, Integer toIndex, Boolean includeBody)
          Browses the BrowsableEndpoint within the given range, and returns the messages as a XML payload.
static String createEndpointId()
          A helper method for Endpoint implementations to create new Ids for Endpoints which also implement HasId
static String getRouteIdFromEndpoint(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(Endpoint endpoint)
          Lookup the id the given endpoint has been enlisted with in the Registry.
static boolean matchEndpoint(CamelContext context, String uri, String pattern)
          Matches the endpoint with the given pattern.
static boolean matchEndpoint(String uri, String pattern)
          Deprecated. use matchEndpoint(org.apache.camel.CamelContext, String, String) instead.
static boolean matchPattern(String name, String pattern)
          Matches the name with the given pattern.
static void pollEndpoint(Endpoint endpoint, 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(Endpoint endpoint, 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
<T> List<T>
resolveReferenceListParameter(CamelContext context, String value, Class<T> elementType)
          Resolves a reference list parameter by making lookups in the registry.
static
<T> T
resolveReferenceParameter(CamelContext context, String value, Class<T> type)
          Resolves a reference parameter by making a lookup in the registry.
static
<T> T
resolveReferenceParameter(CamelContext context, String value, Class<T> type, boolean mandatory)
          Resolves a reference parameter by making a lookup in the registry.
static void setProperties(CamelContext context, Object bean, Map<String,Object> parameters)
          Sets the regular properties on the given bean
static void setReferenceProperties(CamelContext context, Object bean, Map<String,Object> parameters)
          Sets the reference properties on the given bean

This is convention over configuration, setting all reference parameters (using isReferenceParameter(String) by looking it up in registry and setting it on the bean if possible.

 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

pollEndpoint

public static void pollEndpoint(Endpoint endpoint,
                                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(Endpoint endpoint,
                                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(CamelContext context,
                                    String uri,
                                    String pattern)
Matches the endpoint with the given pattern.

The endpoint will first resolve property placeholders using CamelContext.resolvePropertyPlaceholders(String).

The match rules are applied in this order:

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.

matchEndpoint

@Deprecated
public static boolean matchEndpoint(String uri,
                                               String pattern)
Deprecated. use matchEndpoint(org.apache.camel.CamelContext, String, String) instead.

Matches the endpoint with the given pattern.

See Also:
matchEndpoint(org.apache.camel.CamelContext, String, String)

matchPattern

public static boolean matchPattern(String name,
                                   String pattern)
Matches the name with the given pattern.

The match rules are applied in this order:

Parameters:
name - the name
pattern - a pattern to match
Returns:
true if match, false otherwise.

setProperties

public static void setProperties(CamelContext context,
                                 Object bean,
                                 Map<String,Object> parameters)
                          throws Exception
Sets the regular properties on the given bean

Parameters:
context - the camel context
bean - the bean
parameters - parameters
Throws:
Exception - is thrown if setting property fails

setReferenceProperties

public static void setReferenceProperties(CamelContext context,
                                          Object bean,
                                          Map<String,Object> parameters)
                                   throws Exception
Sets the reference properties on the given bean

This is convention over configuration, setting all reference parameters (using isReferenceParameter(String) by looking it up in registry and setting it on the bean if possible.

Parameters:
context - the camel context
bean - the bean
parameters - 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(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(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:
IllegalArgumentException - if object was not found in registry and mandatory is true.

resolveReferenceListParameter

public static <T> List<T> resolveReferenceListParameter(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:

Parameters:
context - Camel context to use for lookup.
value - reference parameter value.
elementType - result list element type.
Returns:
list of lookup results.
Throws:
IllegalArgumentException - if any referenced object was not found in registry.

getRouteIdFromEndpoint

public static String getRouteIdFromEndpoint(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(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

browseRangeMessagesAsXml

public static String browseRangeMessagesAsXml(BrowsableEndpoint endpoint,
                                              Integer fromIndex,
                                              Integer toIndex,
                                              Boolean includeBody)
Browses the BrowsableEndpoint within the given range, and returns the messages as a XML payload.

Parameters:
endpoint - the browsable endpoint
fromIndex - from range
toIndex - to range
includeBody - whether to include the message body in the XML payload
Returns:
XML payload with the messages
Throws:
IllegalArgumentException - if the from and to range is invalid
See Also:
MessageHelper.dumpAsXml(org.apache.camel.Message)


Apache CAMEL