camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bengt Rodehav <>
Subject Adding custom type converter
Date Thu, 20 Mar 2014 09:27:11 GMT
I'm using Camel 2.12.3 running in Karaf 2.3.4.

I'm trying to add a custom type converter to my context but can't get it to
work. My code is essentially as follows:

InputStream.class, new MmlMessage2StringTypeConverter());

from(...).process(new Processor() {
  public void process(Exchange theExchange) throws Exception {
    Message message = theExchange.getIn();
    MmlMessage mmlMessage = ... // Create an MmlMessage

    System.out.println("Trying to convert");
    try {
      TypeConverter tc = theExchange.getContext().getTypeConverter();
      System.out.println("tc: " + tc);
      InputStream is = tc.convertTo(InputStream.class, mmlMessage);
      System.out.println("is: " + is);
    } catch (Exception e) {
      System.out.println("Conversion failed");

My type converter looks something like this:

public class MmlMessage2StringTypeConverter extends TypeConverterSupport {
  public <T> T convertTo(Class<T> theType, Exchange theExchange, Object
theValue) {
    System.out.println("convertTo: " + theValue);
    InputStream stream = null;
    ... // Create an InputStream from an MmlMessage
    return (T) stream;

The output I get in the Karaf console is:

Trying to convert
tc: org.apache.camel.core.osgi.OsgiTypeConverter@4316e1c9
is: null

Thus my type converter is never found and never used.

Am I'm doing this wrong? Isn't this the way to add a custom type converter?


  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message