Nav
You are viewing an older version of this section. Click here to navigate to the latest version.

Injecting the Payload

Used on components, this annotation marks the method parameter that will be used to pass in the message payload. Note that they parameter type will be used to do any auto conversions using the transformer available inside the Mule container. Mule has a number of standard transformers for dealing with common, Java types such as XML documents, streams, byte array, strings, etc. It is also very easy for users to define their own Transformations.

Restrictions

A method annotate with @Processor can have at most one parameter annotated with @Payload, @InboundHeaders, @InvocationHeader or @OutboundHeaders.

For example this is not possible:


         
      
1
2
@Processor
    public Object myMethod(@Payload Object payload, @InvocationHeaders("*") Map<?, ?> headers) {

Examples

Inject the payload without specifying the type:


         
      
1
2
3
4
5
@Processor
    public Object myMethod(@Payload Object payload) {
        // code here
        return payload;
    }

Inject the payload which is of type byte [] and return a java.lang.String


         
      
1
2
3
4
5
@Processor
    public String myMethod(@Payload byte[] payload) {
        // code here
        return new String(payload);
    }

In this topic: