|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.camel.util.ExchangeHelper
public final class ExchangeHelper
Some helper methods for working with Exchange
objects
Method Summary | ||
---|---|---|
static
|
convertToMandatoryType(Exchange exchange,
Class<T> type,
Object value)
Converts the value to the given expected type or throws an exception |
|
static
|
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 void |
copyResultsPreservePattern(Exchange result,
Exchange source)
Copies the source exchange to target exchange
preserving the ExchangePattern of target . |
|
static Map |
createVariableMap(Exchange exchange)
Creates a Map of the variables which are made available to a script or template |
|
static
|
extractFutureBody(CamelContext context,
Future future,
Class<T> type)
Extracts the body from the given future, that represents a handle to an asynchronous exchange. |
|
static
|
extractFutureBody(CamelContext context,
Future future,
long timeout,
TimeUnit unit,
Class<T> type)
Extracts the body from the given future, that represents a handle to an asynchronous exchange. |
|
static Object |
extractResultBody(Exchange exchange,
ExchangePattern pattern)
Extracts the body from the given exchange. |
|
static
|
getBinding(Exchange exchange,
Class<T> type)
Extracts the Exchange.BINDING of the given type or null if not present |
|
static String |
getContentEncoding(Exchange exchange)
Returns the MIME content encoding on the input message or null if one is not defined |
|
static String |
getContentType(Exchange exchange)
Returns the MIME content type on the input message or null if one is not defined |
|
static Exchange |
getExchangeById(Iterable<Exchange> exchanges,
String exchangeId)
Returns the first exchange in the given collection of exchanges which has the same exchange ID as the one given or null if none could be found |
|
static
|
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
|
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
|
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
|
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
|
getMandatoryProperty(Exchange exchange,
String propertyName,
Class<T> type)
|
|
static Message |
getResultMessage(Exchange exchange)
Returns the message where to write results in an exchange-pattern-sensitive way. |
|
static boolean |
hasFaultMessage(Exchange exchange)
Tests whether the exchange has a fault message set and that its not null. |
|
static boolean |
isFailureHandled(Exchange exchange)
|
|
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
|
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
|
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
|
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 void |
prepareAggregation(Exchange oldExchange,
Exchange newExchange)
Prepares the exchanges for aggregation. |
|
static Endpoint |
resolveEndpoint(Exchange exchange,
Object value)
Attempts to resolve the endpoint for the given value |
|
static void |
setFailureHandled(Exchange exchange)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static <T> T getExchangeProperty(Exchange exchange, String propertyName, Class<T> type, T defaultValue)
exchange
- the message exchangepropertyName
- the name of the property on the exchangetype
- the expected type of the propertydefaultValue
- the default value to be used if the property name does not exist or could not be
converted to the given type
public static <T> T getBinding(Exchange exchange, Class<T> type)
exchange
- the message exchangetype
- the expected binding type
public static Endpoint resolveEndpoint(Exchange exchange, Object value) throws NoSuchEndpointException
exchange
- the message exchange being processedvalue
- the value which can be an Endpoint
or an object
which provides a String representation of an endpoint via
Object.toString()
NoSuchEndpointException
- if the endpoint cannot be resolvedpublic static <T> T getMandatoryProperty(Exchange exchange, String propertyName, Class<T> type) throws NoSuchPropertyException
NoSuchPropertyException
public static <T> T getMandatoryHeader(Exchange exchange, String propertyName, Class<T> type) throws NoSuchHeaderException
NoSuchHeaderException
public static Object getMandatoryInBody(Exchange exchange) throws InvalidPayloadException
InvalidPayloadException
public static <T> T getMandatoryInBody(Exchange exchange, Class<T> type) throws InvalidPayloadException
InvalidPayloadException
public static Object getMandatoryOutBody(Exchange exchange) throws InvalidPayloadException
InvalidPayloadException
public static <T> T getMandatoryOutBody(Exchange exchange, Class<T> type) throws InvalidPayloadException
InvalidPayloadException
public static <T> T convertToMandatoryType(Exchange exchange, Class<T> type, Object value) throws NoTypeConversionAvailableException
NoTypeConversionAvailableException
public static <T> T convertToType(Exchange exchange, Class<T> type, Object value)
public static void copyResults(Exchange result, Exchange source)
result
- the result exchange which will have the output and error state addedsource
- the source exchange which is not modifiedpublic static void copyResultsPreservePattern(Exchange result, Exchange source)
source
exchange to target
exchange
preserving the ExchangePattern
of target
.
source
- source exchange.result
- target exchange.public static Message getResultMessage(Exchange exchange)
exchange
- message exchange.
public static boolean isInCapable(Exchange exchange)
exchange
- the exchange to interrogate
ExchangePattern
which supports
IN messagespublic static boolean isOutCapable(Exchange exchange)
exchange
- the exchange to interrogate
ExchangePattern
which supports
OUT messagespublic static <T> T newInstance(Exchange exchange, Class<T> type)
public static Map createVariableMap(Exchange exchange)
exchange
- the exchange to make available
public static void populateVariableMap(Exchange exchange, Map map)
exchange
- the exchange to make availablemap
- the map to populatepublic static String getContentType(Exchange exchange)
public static String getContentEncoding(Exchange exchange)
public static Object lookupMandatoryBean(Exchange exchange, String name)
public static <T> T lookupMandatoryBean(Exchange exchange, String name, Class<T> type)
public static Object lookupBean(Exchange exchange, String name)
public static <T> T lookupBean(Exchange exchange, String name, Class<T> type)
public static Exchange getExchangeById(Iterable<Exchange> exchanges, String exchangeId)
public static void prepareAggregation(Exchange oldExchange, Exchange newExchange)
oldExchange
- the old exchangenewExchange
- the new exchangepublic static boolean isFailureHandled(Exchange exchange)
public static void setFailureHandled(Exchange exchange)
public static Object extractResultBody(Exchange exchange, ExchangePattern pattern)
exchange
- the exchangepattern
- exchange pattern if given, can be null
CamelExecutionException
- if the processing of the exchange failedpublic static boolean hasFaultMessage(Exchange exchange)
exchange
- the exchange
public static <T> T extractFutureBody(CamelContext context, Future future, Class<T> type)
context
- the camel contextfuture
- the future handletype
- the expected body response type
CamelExecutionException
- if the processing of the exchange failedpublic static <T> T extractFutureBody(CamelContext context, Future future, long timeout, TimeUnit unit, Class<T> type) throws TimeoutException
context
- the camel contextfuture
- the future handletimeout
- timeout valueunit
- timeout unittype
- the expected body response type
CamelExecutionException
- if the processing of the exchange failed
TimeoutException
- is thrown if a timeout triggered
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |