Search code examples
javamuletransformer-model

Mule custom transformer with


I'm having some trouble finding out how to create a custom transformer that can input and output a file in Mule 3.2. I have prototyped the code for the transformation and that works fine but I can't find any documentation on how to take in a file in a transformer.

Here is what I have so far as I'm but even this throws an error:

@ContainsTransformerMethods
  public class xmlToJson {

  @Transformer
  public File xmlIn(File file) {
    // logic to go here
    return file;
  }
}

Here is the exception that is thrown:

ERROR 2012-06-27 14:08:37,664 [main] org.mule.tooling.server.application.
ApplicationDeployer: null
java.lang.IllegalStateException: Cannot convert value of type [convert.xmlToJson]
to required type [org.mule.api.processor.MessageProcessor] for property 'messageProcessors[0]': no matching editors or conversion strategy found

I can't seem to find any documentation or tutorials that show how to structure a custom transformer to take in a file.


Solution

  • The annoteted transformer are usually intended for automatic transformation as explained here:

    http://www.mulesoft.org/documentation/display/MULE3USER/Creating+Custom+Transformers

    What would probably fit better you use case is creating a custom transforme by extending the AbstractTransformer as explained here:

    http://www.mulesoft.org/documentation/display/MULE3USER/Creating+Custom+Transformer+Class

    You can find a good tutorial about how to use either of this approaches at the following link

    http://www.mulesoft.org/documentation/display/MULE3EXAMPLES/Invoking+Component+Methods