Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The Message interface defines a helper method to allow conversions to be done via the getBody(Class) method.

So in an endpoint you can convert a body to another type via

...

The type conversion strategy is defined by the TypeConverter interface which that can be customized on a CamelContext.

The default implementation, DefaultTypeConverter, uses pluggable strategies to load type converters via TypeConverterLoader. The default strategy, AnnotationTypeConverterLoader, uses a discovery mechanism to find converters.

...

The default implementation, DefaultTypeConverter, now throws a NoTypeConversionAvailableException if a suitable conversion cannot be found (CAMEL-84). The semantical ambiguity of null (both valid result and indication of no conversion found) is now resolved, but this may impact existing code in that it should now catch the exception instead of checking for null.

TypeConverterRegistry

New in Camel 2.0

Exposed the TypeConverterRegistry from CamelContext so end users more easily will be able to add type converters at runtime. This is also usable in situations where the default discovering of type converters fails , on platforms with classloading issues.

To access the registry, you get it from the CamelContext

...

Camel can gather utilization statistics of the runtime usage of type converters. These stats is are available in JMX, and ass as well as from the getStatistics() method from TypeConverterRegistry.

From Camel 2.11.0/2.10.5 onwards these statistics is default are turned off , by default as there is a little some performance overhead under very high concurrent load. To enable the statistics you can do this from java within Java, do the following:

Code Block
   CamelContext context = ...
   context.setTypeConverterStatisticsEnabled(true);

Or from in the XML DSL bywith:

Code Block
xml
xml
<camelContext xmlns="http://camel.apache.org/schema/spring" typeConverterStatisticsEnabled="true">
...
</camelContext>

...

Available in Camel 2.0
The AnnotationTypeConverterLoader has been enhanced to also look for methods defined with a @FallbackConverter annotation, and register it as a fallback type converter.

Fallback type converters is are used as a last resort of hopes for converting a given value to another type. Its used when the regular type converters give up.
The fallback converters is also meant for a broader scope, so its method signature is a bit different:

...

  • static methods are encouraged to reduce caching; , but instance methods are fine, particularly if you want to allow optional dependency injection to customize the converter
  • converter methods should be thread safe and reentrant

...

Code Block
com.foo
com.bar

Each line in the file is a package name. This tells Camel to go scan those packages for any classes which that has been annotated with the @Converter.

...

Available as of Camel 2.8
In Camel 2.8 we improved the type converter loader to support specifying the FQN class name of the converter classes. This has a much better advantage as it avoids the advantage of avoiding having to scan packages for @Converter classes. Instead it loads the @Converter class directly. This is a highly recommend approach to use going forward.

...