org.apache.camel.util
Class ExchangeHelper

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

public final class ExchangeHelper
extends Object

Some helper methods for working with Exchange objects

Version:
$Revision: 732393 $

Method Summary
static
<T> T
convertToMandatoryType(Exchange exchange, Class<T> type, Object value)
          Converts the value to the given expected type or throws an exception
static
<T> T
convertToType(Exchange exchange, Class<T> type, Object value)
          Converts the value to the given expected type returning null if it could not be converted
static void copyResults(Exchange result, Exchange source)
          Copies the results of a message exchange from the source exchange to the result exchange which will copy the out and fault message contents and the exception
static Map createVariableMap(Exchange exchange)
          Creates a Map of the variables which are made available to a script or template
static String getContentType(Exchange exchange)
          Returns the MIME content type on the input message or null if one is not defined
static
<T> T
getExchangeProperty(Exchange exchange, String propertyName, Class<T> type, T defaultValue)
          Extracts the exchange property of the given name and type; if it is not present then the default value will be used
static
<T> T
getMandatoryHeader(Exchange exchange, String propertyName, Class<T> type)
           
static Object getMandatoryInBody(Exchange exchange)
          Returns the mandatory inbound message body of the correct type or throws an exception if it is not present
static
<T> T
getMandatoryInBody(Exchange exchange, Class<T> type)
          Returns the mandatory inbound message body of the correct type or throws an exception if it is not present
static Object getMandatoryOutBody(Exchange exchange)
          Returns the mandatory outbound message body of the correct type or throws an exception if it is not present
static
<T> T
getMandatoryOutBody(Exchange exchange, Class<T> type)
          Returns the mandatory outbound message body of the correct type or throws an exception if it is not present
static
<T> T
getMandatoryProperty(Exchange exchange, String propertyName, Class<T> type)
           
static boolean isInCapable(Exchange exchange)
          Returns true if the given exchange pattern (if defined) can support IN messagea
static boolean isOutCapable(Exchange exchange)
          Returns true if the given exchange pattern (if defined) can support OUT messagea
static Object lookupBean(Exchange exchange, String name)
          Performs a lookup in the registry of the bean name
static
<T> T
lookupBean(Exchange exchange, String name, Class<T> type)
          Performs a lookup in the registry of the bean name and type
static Object lookupMandatoryBean(Exchange exchange, String name)
          Performs a lookup in the registry of the mandatory bean name and throws an exception if it could not be found
static
<T> T
lookupMandatoryBean(Exchange exchange, String name, Class<T> type)
          Performs a lookup in the registry of the mandatory bean name and throws an exception if it could not be found
static
<T> T
newInstance(Exchange exchange, Class<T> type)
          Creates a new instance of the given type from the injector
static void populateVariableMap(Exchange exchange, Map map)
          Populates the Map with the variables which are made available to a script or template
static
<E extends Exchange>
Endpoint<E>
resolveEndpoint(E exchange, Object value)
          Attempts to resolve the endpoint for the given value
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getExchangeProperty

public static <T> T getExchangeProperty(Exchange exchange,
                                        String propertyName,
                                        Class<T> type,
                                        T defaultValue)
Extracts the exchange property of the given name and type; if it is not present then the default value will be used

Parameters:
exchange - the message exchange
propertyName - the name of the property on the exchange
type - the expected type of the property
defaultValue - the default value to be used if the property name does not exist or could not be converted to the given type
Returns:
the property value as the given type or the defaultValue if it could not be found or converted

resolveEndpoint

public static <E extends Exchange> Endpoint<E> resolveEndpoint(E exchange,
                                                               Object value)
                                                    throws NoSuchEndpointException
Attempts to resolve the endpoint for the given value

Parameters:
exchange - the message exchange being processed
value - the value which can be an Endpoint or an object which provides a String representation of an endpoint via Object.toString()
Returns:
the endpoint
Throws:
NoSuchEndpointException - if the endpoint cannot be resolved

getMandatoryProperty

public static <T> T getMandatoryProperty(Exchange exchange,
                                         String propertyName,
                                         Class<T> type)
                              throws NoSuchPropertyException
Throws:
NoSuchPropertyException

getMandatoryHeader

public static <T> T getMandatoryHeader(Exchange exchange,
                                       String propertyName,
                                       Class<T> type)
                            throws NoSuchHeaderException
Throws:
NoSuchHeaderException

getMandatoryInBody

public static Object getMandatoryInBody(Exchange exchange)
                                 throws InvalidPayloadException
Returns the mandatory inbound message body of the correct type or throws an exception if it is not present

Throws:
InvalidPayloadException

getMandatoryInBody

public static <T> T getMandatoryInBody(Exchange exchange,
                                       Class<T> type)
                            throws InvalidPayloadException
Returns the mandatory inbound message body of the correct type or throws an exception if it is not present

Throws:
InvalidPayloadException

getMandatoryOutBody

public static Object getMandatoryOutBody(Exchange exchange)
                                  throws InvalidPayloadException
Returns the mandatory outbound message body of the correct type or throws an exception if it is not present

Throws:
InvalidPayloadException

getMandatoryOutBody

public static <T> T getMandatoryOutBody(Exchange exchange,
                                        Class<T> type)
                             throws InvalidPayloadException
Returns the mandatory outbound message body of the correct type or throws an exception if it is not present

Throws:
InvalidPayloadException

convertToMandatoryType

public static <T> T convertToMandatoryType(Exchange exchange,
                                           Class<T> type,
                                           Object value)
                                throws InvalidTypeException
Converts the value to the given expected type or throws an exception

Throws:
InvalidTypeException

convertToType

public static <T> T convertToType(Exchange exchange,
                                  Class<T> type,
                                  Object value)
Converts the value to the given expected type returning null if it could not be converted


copyResults

public static void copyResults(Exchange result,
                               Exchange source)
Copies the results of a message exchange from the source exchange to the result exchange which will copy the out and fault message contents and the exception

Parameters:
result - the result exchange which will have the output and error state added
source - the source exchange which is not modified

isInCapable

public static boolean isInCapable(Exchange exchange)
Returns true if the given exchange pattern (if defined) can support IN messagea

Parameters:
exchange - the exchange to interrogate
Returns:
true if the exchange is defined as an ExchangePattern which supports IN messages

isOutCapable

public static boolean isOutCapable(Exchange exchange)
Returns true if the given exchange pattern (if defined) can support OUT messagea

Parameters:
exchange - the exchange to interrogate
Returns:
true if the exchange is defined as an ExchangePattern which supports OUT messages

newInstance

public static <T> T newInstance(Exchange exchange,
                                Class<T> type)
Creates a new instance of the given type from the injector


createVariableMap

public static Map createVariableMap(Exchange exchange)
Creates a Map of the variables which are made available to a script or template

Parameters:
exchange - the exchange to make available
Returns:
a Map populated with the require dvariables

populateVariableMap

public static void populateVariableMap(Exchange exchange,
                                       Map map)
Populates the Map with the variables which are made available to a script or template

Parameters:
exchange - the exchange to make available
map - the map to populate

getContentType

public static String getContentType(Exchange exchange)
Returns the MIME content type on the input message or null if one is not defined


lookupMandatoryBean

public static Object lookupMandatoryBean(Exchange exchange,
                                         String name)
Performs a lookup in the registry of the mandatory bean name and throws an exception if it could not be found


lookupMandatoryBean

public static <T> T lookupMandatoryBean(Exchange exchange,
                                        String name,
                                        Class<T> type)
Performs a lookup in the registry of the mandatory bean name and throws an exception if it could not be found


lookupBean

public static Object lookupBean(Exchange exchange,
                                String name)
Performs a lookup in the registry of the bean name


lookupBean

public static <T> T lookupBean(Exchange exchange,
                               String name,
                               Class<T> type)
Performs a lookup in the registry of the bean name and type



Apache CAMEL