Nav
You are viewing an older version of this topic. To go to a different version, use the version menu at the upper-right. +

@InboundAttachments Annotation

This annotation controls how the current message inbound attachments are passed into a method. The annotation supports, Map, List, single attachment, wildcards and optional entries. It can be used on component entry points and @Transformer methods.

Accessing Message Attachments

A message in Mule can optionally have attachments. THe modules in Mule that support attachments are HTTP, Email, Axis and VM. If you need to access the attachments, add a parameter to the component method signature or transformer method signature annotated with the @InboundAttachments annotation -

The '*' indicates that all headers should be returned.


         
      
1
2
3
@Transformer
public Person xmlToOrder(@Payload Document data,
             @InboundAttachments("*") Map<String, DataHandler> headers)

Note that the Map type will be Map<String, DataHandler>. The attahcment information can be queried from the javax.activation.DataHandler instance.

Wildcard expressions can be used to match a subset of attachments too -


         
      
1
2
3
@Transformer
public Person xmlToOrder(@Payload Document data,
                  @InboundAttachments("*.pdf") Map<String, DataHandler> headers)

Alternatively, you can specify a single header name and just return the value of that attachment:


         
      
1
2
3
4
5
6
public class OrderService {
   public OrderConfirmation processOrder(@Payload InputStream data,
             @InboundAttachments("shipping-info.doc") DataHandler attachment) {
         //do stuff
    }
}

To receive a subset of specific attachments, you can list them as comma-separated values:


         
      
1
2
3
4
5
6
public class OrderService {
   public OrderConfirmation processOrder(@Payload InputStream data,
         @InboundAttachments("shipping-info.doc, invoice.pdf") Map<String, DataHandler> attachments) {
         //do stuff
    }
}

By default an error will be thrown if a listed attachment is not on the response. To avoid this error, mark the header as optional with '?'. For example, shipping-info.doc is optional in the following code:


         
      
1
2
3
4
5
6
public class OrderService {
   public OrderConfirmation processOrder(@Payload InputStream data,
           @InboundAttachments("shipping-info.doc?, invoice.pdf") Map headers) {
         //do stuff
    }
}

If the return type for the @InboundAttachments param is a java.util.List, just the values will be returned.


         
      
1
2
3
4
5
6
public class OrderService {
   public OrderConfirmation processOrder(@Payload InputStream data,
        @InboundAttachments("shipping-info.doc?, invoice.pdf") List<DataHandler> attachments) {
         //do stuff
    }
}

We use cookies to make interactions with our websites and services easy and meaningful, to better understand how they are used and to tailor advertising. You can read more and make your cookie choices here. By continuing to use this site you are giving us your consent to do this.

+