public final class ExchangeHelper extends Object
Exchange
objectsModifier and Type | Method and Description |
---|---|
static <T> T |
convertToMandatoryType(org.apache.camel.Exchange exchange,
Class<T> type,
Object value)
Converts the value to the given expected type or throws an exception
|
static <T> T |
convertToType(org.apache.camel.Exchange exchange,
Class<T> type,
Object value)
Converts the value to the given expected type
|
static org.apache.camel.Exchange |
copyExchangeAndSetCamelContext(org.apache.camel.Exchange exchange,
org.apache.camel.CamelContext context)
Copies the exchange but the copy will be tied to the given context
|
static org.apache.camel.Exchange |
copyExchangeAndSetCamelContext(org.apache.camel.Exchange exchange,
org.apache.camel.CamelContext context,
boolean handover)
Copies the exchange but the copy will be tied to the given context
|
static void |
copyResults(org.apache.camel.Exchange target,
org.apache.camel.Exchange source)
Copies the results of a message exchange from the source exchange to the result exchange which will copy the
message contents, exchange properties and the exception.
|
static void |
copyResultsPreservePattern(org.apache.camel.Exchange target,
org.apache.camel.Exchange source)
Copies the
source exchange to target exchange preserving the ExchangePattern of
target . |
static org.apache.camel.Exchange |
createCopy(org.apache.camel.Exchange exchange,
boolean preserveExchangeId)
Creates a new instance and copies from the current message exchange so that it can be forwarded to another
destination as a new instance.
|
static org.apache.camel.Exchange |
createCorrelatedCopy(org.apache.camel.Exchange exchange,
boolean handover)
Creates a new instance and copies from the current message exchange so that it can be forwarded to another
destination as a new instance.
|
static org.apache.camel.Exchange |
createCorrelatedCopy(org.apache.camel.Exchange exchange,
boolean handover,
boolean useSameMessageId)
Creates a new instance and copies from the current message exchange so that it can be forwarded to another
destination as a new instance.
|
static org.apache.camel.Exchange |
createCorrelatedCopy(org.apache.camel.Exchange exchange,
boolean handover,
boolean useSameMessageId,
Predicate<org.apache.camel.spi.Synchronization> filter)
Creates a new instance and copies from the current message exchange so that it can be forwarded to another
destination as a new instance.
|
static Map<String,Object> |
createVariableMap(org.apache.camel.Exchange exchange,
boolean allowContextMapAll)
Creates a Map of the variables which are made available to a script or template
|
static <T> T |
extractFutureBody(org.apache.camel.CamelContext context,
Future<?> future,
Class<T> type)
Extracts the body from the given future, that represents a handle to an asynchronous exchange.
|
static <T> T |
extractFutureBody(org.apache.camel.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(org.apache.camel.Exchange exchange,
org.apache.camel.ExchangePattern pattern)
Extracts the body from the given exchange.
|
static String |
getAtRouteId(org.apache.camel.Exchange exchange) |
static <T> T |
getBinding(org.apache.camel.Exchange exchange,
Class<T> type)
Extracts the Exchange.BINDING of the given type or null if not present
|
static String |
getCharsetName(org.apache.camel.Exchange exchange) |
static String |
getCharsetName(org.apache.camel.Exchange exchange,
boolean useDefault)
Gets the charset name if set as header or property
Exchange.CHARSET_NAME . |
static String |
getContentEncoding(org.apache.camel.Exchange exchange)
Returns the MIME content encoding on the input message or null if one is not defined
|
static String |
getContentType(org.apache.camel.Exchange exchange)
Returns the MIME content type on the input message or null if one is not defined
|
static <T> T |
getHeaderOrProperty(org.apache.camel.Exchange exchange,
String name,
Class<T> type)
Gets an header or property of the correct type
|
static <T> T |
getMandatoryHeader(org.apache.camel.Exchange exchange,
String headerName,
Class<T> type)
Gets the mandatory inbound header of the correct type
|
static <T> T |
getMandatoryHeader(org.apache.camel.Message message,
String headerName,
Class<T> type)
Gets the mandatory inbound header of the correct type
|
static <T> T |
getMandatoryProperty(org.apache.camel.Exchange exchange,
String propertyName,
Class<T> type)
Gets the mandatory property of the exchange of the correct type
|
static org.apache.camel.Message |
getOriginalInMessage(org.apache.camel.Exchange exchange)
Gets the original IN
Message this Unit of Work was started with. |
static org.apache.camel.Message |
getResultMessage(org.apache.camel.Exchange exchange)
Returns the message where to write results in an exchange-pattern-sensitive way.
|
static org.apache.camel.Route |
getRoute(org.apache.camel.Exchange exchange) |
static String |
getRouteId(org.apache.camel.Exchange exchange) |
static org.apache.camel.util.Scanner |
getScanner(org.apache.camel.Exchange exchange,
Object value,
String delimiter)
Creates a
Scanner for scanning the given value. |
static boolean |
isErrorHandlerBridge(org.apache.camel.Exchange exchange)
Checks whether the exchange has been error handler bridged
|
static boolean |
isFailureHandled(org.apache.camel.Exchange exchange)
Checks whether the exchange has been failure handed
|
static boolean |
isOutCapable(org.apache.camel.Exchange exchange)
Returns true if the given exchange pattern (if defined) can support OUT messages
|
static boolean |
isRedelivered(org.apache.camel.Exchange exchange)
Checks whether the exchange
UnitOfWork is redelivered |
static boolean |
isStreamCachingEnabled(org.apache.camel.Exchange exchange)
Check whether or not stream caching is enabled for the given route or globally.
|
static boolean |
isUnitOfWorkExhausted(org.apache.camel.Exchange exchange)
Checks whether the exchange
UnitOfWork is exhausted |
static String |
logIds(org.apache.camel.Exchange exchange)
Gets both the messageId and exchangeId to be used for logging purposes.
|
static Object |
lookupBean(org.apache.camel.Exchange exchange,
String name)
Performs a lookup in the registry of the bean name
|
static <T> T |
lookupBean(org.apache.camel.Exchange exchange,
String name,
Class<T> type)
Performs a lookup in the registry of the bean name and type
|
static Object |
lookupMandatoryBean(org.apache.camel.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(org.apache.camel.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(org.apache.camel.Exchange exchange,
Class<T> type)
Creates a new instance of the given type from the injector
|
static void |
onClassloaded(org.slf4j.Logger log) |
static void |
populateVariableMap(org.apache.camel.Exchange exchange,
Map<String,Object> map,
boolean allowContextMapAll)
Populates the Map with the variables which are made available to a script or template
|
static void |
prepareAggregation(org.apache.camel.Exchange oldExchange,
org.apache.camel.Exchange newExchange)
Prepares the exchanges for aggregation.
|
static void |
prepareOutToIn(org.apache.camel.Exchange exchange)
Strategy to prepare results before next iterator or when we are complete, which is done by copying OUT to IN, so
there is only an IN as input for the next iteration.
|
static void |
replaceMessage(org.apache.camel.Exchange exchange,
org.apache.camel.Message newMessage,
boolean outOnly)
Replaces the existing message with the new message
|
static org.apache.camel.Endpoint |
resolveEndpoint(org.apache.camel.CamelContext context,
Object value)
Attempts to resolve the endpoint for the given value
|
static org.apache.camel.Endpoint |
resolveEndpoint(org.apache.camel.Exchange exchange,
Object value)
Attempts to resolve the endpoint for the given value
|
static org.apache.camel.Endpoint |
resolvePrototypeEndpoint(org.apache.camel.CamelContext context,
Object value)
Attempts to resolve the endpoint (prototype scope) for the given value
|
static org.apache.camel.Endpoint |
resolvePrototypeEndpoint(org.apache.camel.Exchange exchange,
Object value)
Attempts to resolve the endpoint (prototype scope) for the given value
|
static String |
resolveScheme(String uri)
Resolve the component scheme (aka name) from the given endpoint uri
|
static void |
setFailureHandled(org.apache.camel.Exchange exchange)
Sets the exchange to be failure handled.
|
public static void onClassloaded(org.slf4j.Logger log)
public static <T> T getBinding(org.apache.camel.Exchange exchange, Class<T> type)
exchange
- the message exchangetype
- the expected binding typepublic static org.apache.camel.Endpoint resolveEndpoint(org.apache.camel.Exchange exchange, Object value) throws org.apache.camel.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()
org.apache.camel.NoSuchEndpointException
- if the endpoint cannot be resolvedpublic static org.apache.camel.Endpoint resolveEndpoint(org.apache.camel.CamelContext context, Object value) throws org.apache.camel.NoSuchEndpointException
context
- the camel contextvalue
- the value which can be an Endpoint
or an object which provides a String
representation of an endpoint via Object.toString()
org.apache.camel.NoSuchEndpointException
- if the endpoint cannot be resolvedpublic static org.apache.camel.Endpoint resolvePrototypeEndpoint(org.apache.camel.Exchange exchange, Object value) throws org.apache.camel.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()
org.apache.camel.NoSuchEndpointException
- if the endpoint cannot be resolvedpublic static org.apache.camel.Endpoint resolvePrototypeEndpoint(org.apache.camel.CamelContext context, Object value) throws org.apache.camel.NoSuchEndpointException
context
- the camel contextvalue
- the value which can be an Endpoint
or an object which provides a String
representation of an endpoint via Object.toString()
org.apache.camel.NoSuchEndpointException
- if the endpoint cannot be resolvedpublic static <T> T getMandatoryProperty(org.apache.camel.Exchange exchange, String propertyName, Class<T> type) throws org.apache.camel.NoSuchPropertyException
exchange
- the exchangepropertyName
- the property nametype
- the typeorg.apache.camel.TypeConversionException
- is thrown if error during type conversionorg.apache.camel.NoSuchPropertyException
- is thrown if no property existspublic static <T> T getMandatoryHeader(org.apache.camel.Exchange exchange, String headerName, Class<T> type) throws org.apache.camel.TypeConversionException, org.apache.camel.NoSuchHeaderException
exchange
- the exchangeheaderName
- the header nametype
- the typeorg.apache.camel.TypeConversionException
- is thrown if error during type conversionorg.apache.camel.NoSuchHeaderException
- is thrown if no headers existspublic static <T> T getMandatoryHeader(org.apache.camel.Message message, String headerName, Class<T> type) throws org.apache.camel.TypeConversionException, org.apache.camel.NoSuchHeaderException
message
- the messageheaderName
- the header nametype
- the typeorg.apache.camel.TypeConversionException
- is thrown if error during type conversionorg.apache.camel.NoSuchHeaderException
- is thrown if no headers existspublic static <T> T getHeaderOrProperty(org.apache.camel.Exchange exchange, String name, Class<T> type) throws org.apache.camel.TypeConversionException
exchange
- the exchangename
- the name of the header or the propertytype
- the typeorg.apache.camel.TypeConversionException
- is thrown if error during type conversionorg.apache.camel.NoSuchHeaderException
- is thrown if no headers existspublic static <T> T convertToMandatoryType(org.apache.camel.Exchange exchange, Class<T> type, Object value) throws org.apache.camel.TypeConversionException, org.apache.camel.NoTypeConversionAvailableException
org.apache.camel.TypeConversionException
- is thrown if error during type conversionNoTypeConversionAvailableException}
- if no type converters exists to convert to the given typeorg.apache.camel.NoTypeConversionAvailableException
public static <T> T convertToType(org.apache.camel.Exchange exchange, Class<T> type, Object value) throws org.apache.camel.TypeConversionException
org.apache.camel.TypeConversionException
- is thrown if error during type conversionpublic static org.apache.camel.Exchange createCorrelatedCopy(org.apache.camel.Exchange exchange, boolean handover)
UnitOfWork
so its should be used for async messaging, where the original and copied
exchange are independent.exchange
- original copy of the exchangehandover
- whether the on completion callbacks should be handed over to the new copy.public static org.apache.camel.Exchange createCorrelatedCopy(org.apache.camel.Exchange exchange, boolean handover, boolean useSameMessageId)
UnitOfWork
so its should be used for async messaging, where the original and copied
exchange are independent.exchange
- original copy of the exchangehandover
- whether the on completion callbacks should be handed over to the new copy.useSameMessageId
- whether to use same message id on the copy message.public static org.apache.camel.Exchange createCorrelatedCopy(org.apache.camel.Exchange exchange, boolean handover, boolean useSameMessageId, Predicate<org.apache.camel.spi.Synchronization> filter)
UnitOfWork
so its should be used for async messaging, where the original and copied
exchange are independent.exchange
- original copy of the exchangehandover
- whether the on completion callbacks should be handed over to the new copy.useSameMessageId
- whether to use same message id on the copy message.filter
- whether to handover the on completionpublic static org.apache.camel.Exchange createCopy(org.apache.camel.Exchange exchange, boolean preserveExchangeId)
exchange
- original copy of the exchangepreserveExchangeId
- whether or not the exchange id should be preservedpublic static void copyResults(org.apache.camel.Exchange target, org.apache.camel.Exchange source)
ExchangePattern
is not
copied/altered.target
- the target exchange which will have the output and error state added (result)source
- the source exchange which is not modifiedpublic static void copyResultsPreservePattern(org.apache.camel.Exchange target, org.apache.camel.Exchange source)
source
exchange to target
exchange preserving the ExchangePattern
of
target
.target
- the target exchange which will have the output and error state added (result)source
- source exchange.public static org.apache.camel.Message getResultMessage(org.apache.camel.Exchange exchange)
exchange
- message exchange.public static boolean isOutCapable(org.apache.camel.Exchange exchange)
exchange
- the exchange to interrogateExchangePattern
which supports OUT messagespublic static <T> T newInstance(org.apache.camel.Exchange exchange, Class<T> type)
exchange
- the exchangetype
- the given typepublic static Map<String,Object> createVariableMap(org.apache.camel.Exchange exchange, boolean allowContextMapAll)
exchange
- the exchange to make availableallowContextMapAll
- whether to allow access to all context map or not (prefer to use false due to security
reasons preferred to only allow access to body/headers)public static void populateVariableMap(org.apache.camel.Exchange exchange, Map<String,Object> map, boolean allowContextMapAll)
exchange
- the exchange to make availablemap
- the map to populateallowContextMapAll
- whether to allow access to all context map or not (prefer to use false due to security
reasons preferred to only allow access to body/headers)public static String getContentType(org.apache.camel.Exchange exchange)
exchange
- the exchangepublic static String getContentEncoding(org.apache.camel.Exchange exchange)
exchange
- the exchangepublic static Object lookupMandatoryBean(org.apache.camel.Exchange exchange, String name) throws org.apache.camel.NoSuchBeanException
exchange
- the exchangename
- the bean nameorg.apache.camel.NoSuchBeanException
- if no bean could be found in the registrypublic static <T> T lookupMandatoryBean(org.apache.camel.Exchange exchange, String name, Class<T> type)
exchange
- the exchangename
- the bean nametype
- the expected bean typeorg.apache.camel.NoSuchBeanException
- if no bean could be found in the registrypublic static Object lookupBean(org.apache.camel.Exchange exchange, String name)
exchange
- the exchangename
- the bean namepublic static <T> T lookupBean(org.apache.camel.Exchange exchange, String name, Class<T> type)
exchange
- the exchangename
- the bean nametype
- the expected bean typepublic static void prepareAggregation(org.apache.camel.Exchange oldExchange, org.apache.camel.Exchange newExchange)
oldExchange
- the old exchangenewExchange
- the new exchangepublic static boolean isFailureHandled(org.apache.camel.Exchange exchange)
exchange
- the exchangepublic static boolean isErrorHandlerBridge(org.apache.camel.Exchange exchange)
exchange
- the exchangepublic static boolean isUnitOfWorkExhausted(org.apache.camel.Exchange exchange)
UnitOfWork
is exhaustedexchange
- the exchangepublic static void setFailureHandled(org.apache.camel.Exchange exchange)
exchange
- the exchangepublic static boolean isRedelivered(org.apache.camel.Exchange exchange)
UnitOfWork
is redeliveredexchange
- the exchangepublic static boolean isStreamCachingEnabled(org.apache.camel.Exchange exchange)
exchange
- the exchangepublic static Object extractResultBody(org.apache.camel.Exchange exchange, org.apache.camel.ExchangePattern pattern)
exchange
- the exchangepattern
- exchange pattern if given, can be nullorg.apache.camel.CamelExecutionException
- is thrown if the processing of the exchange failedpublic static <T> T extractFutureBody(org.apache.camel.CamelContext context, Future<?> future, Class<T> type)
context
- the camel contextfuture
- the future handletype
- the expected body response typeorg.apache.camel.CamelExecutionException
- is thrown if the processing of the exchange failedpublic static <T> T extractFutureBody(org.apache.camel.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 typeorg.apache.camel.CamelExecutionException
- is thrown if the processing of the exchange failedTimeoutException
- is thrown if a timeout triggeredpublic static void prepareOutToIn(org.apache.camel.Exchange exchange)
exchange
- the exchange to preparepublic static String logIds(org.apache.camel.Exchange exchange)
exchange
- the exchangepublic static org.apache.camel.Exchange copyExchangeAndSetCamelContext(org.apache.camel.Exchange exchange, org.apache.camel.CamelContext context)
exchange
- the source exchangecontext
- the camel contextpublic static org.apache.camel.Exchange copyExchangeAndSetCamelContext(org.apache.camel.Exchange exchange, org.apache.camel.CamelContext context, boolean handover)
exchange
- the source exchangecontext
- the camel contexthandover
- whether to handover on completions from the source to the copypublic static void replaceMessage(org.apache.camel.Exchange exchange, org.apache.camel.Message newMessage, boolean outOnly)
exchange
- the exchangenewMessage
- the new messageoutOnly
- whether to replace the message as OUT messagepublic static org.apache.camel.Message getOriginalInMessage(org.apache.camel.Exchange exchange)
Message
this Unit of Work was started with.
The original message is only returned if the option
RuntimeConfiguration.isAllowUseOriginalMessage()
is enabled. If it is disabled, then
IllegalStateException is thrown.Message
public static String resolveScheme(String uri)
uri
- the endpoint uripublic static String getCharsetName(org.apache.camel.Exchange exchange)
getCharsetName(Exchange, boolean)
public static String getCharsetName(org.apache.camel.Exchange exchange, boolean useDefault)
Exchange.CHARSET_NAME
. Notice: The lookup from
the header has priority over the property.exchange
- the exchangeuseDefault
- should we fallback and use JVM default charset if no property existed?public static org.apache.camel.util.Scanner getScanner(org.apache.camel.Exchange exchange, Object value, String delimiter)
Scanner
for scanning the given value.exchange
- the current exchangevalue
- the value, typically the message IN bodydelimiter
- the delimiter pattern to usepublic static String getRouteId(org.apache.camel.Exchange exchange)
public static String getAtRouteId(org.apache.camel.Exchange exchange)
public static org.apache.camel.Route getRoute(org.apache.camel.Exchange exchange)
Apache Camel