Mule ESB 3 transformer cannot be converted to MessageProcessor

Tag: mule Author: lichangrui Date: 2012-08-13

I'm trying to follow the transformer example in the documentation that converts a string input into a list of URLs, but it's throwing an error.

The example is here: http://www.mulesoft.org/documentation/display/MULE3USER/Transformer+Annotation#TransformerAnnotation-WorkingwithCollections

My code for the transformer is copy-pasted from theirs.

When I first did it, I set the transformer by putting in my config xml:

<custom-transformer class="com.test.transformer.StringToListTransformer" doc:name="StringToUrlList"/>

Noting the requirement to 'register' the transformer, I later added in the beginning of the file (after the opening tag):

<spring:bean id="stringToListTransformer" class="com.test.transformer.StringToListTransformer"/>

However, when I run the app, I get the following error:

Exception in thread "main" org.mule.module.launcher.DeploymentInitException: IllegalStateException: Cannot convert value of type [com.test.transformer.StringToListTransformer] to required type [org.mule.api.processor.MessageProcessor] for property 'messageProcessors[3]': no matching editors or conversion strategy found

Best Answer

You can't use a class annotated with @Transformer as a custom-transformer because it is not a real org.mule.api.processor.MessageProcessor. Only real message processors can be used directly in the XML configuration and invoked explicitly.

As the doc for @Transformer says:

There is no mechanism in Mule 3.x to actually invoke a transformer which is being constructed from an annotated method.

If you want to have your transformer kick-in in a flow, you'll need to use:

<auto-transformer returnClass="java.util.List.class"/>

assuming it returns a list and there are no other suitable registered transformers with a higher priority.

Otherwise, create a real transformer by extending org.mule.transformer.AbstractMessageTransformer and then use it with custom-transformer.

comments:

Thanks, just getting started w/ Mule and I guess I misunderstood their walk-through on the resolvers.