Contact Free trial Login

@InboundHeaders Annotation

MuleSoft recommends against deployments to Mule 3.8. Standard Support for this version ended on November 16, 2018, and Mule 3.8 will reach its End of Life on November 16, 2021, when Extended Support ends.

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

Accessing Message Information

All messages in Mule have headers. If you need to access the headers, add a parameter to the component method signature or transformer method signature annotated with the @InboundHeaders annotation:

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

@Transformer
public Person xmlToPerson(@Payload Document data, @InboundHeaders("*") Map headers)

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

@Transformer
public Person xmlToPerson(@Payload Document data, @InboundHeaders("X-*") Map headers)

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

@Transformer
public Person xmlToPerson(@Payload InputStream data, @InboundHeaders("Content-Type") String contentType)

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

@Transformer
public Person xmlToPerson(@Payload InputStream data, @InboundHeaders("Content-Type, Host, X-MyHeader") Map headers)

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

@Transformer
public Person xmlToPerson(@Payload InputStream data, @InboundHeaders("Content-Type, Host, X-MyHeader?") Map headers)

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

@Transformer
public Person xmlToPerson(@Payload InputStream data, @InboundHeaders("Content-Type, Host, X-MyHeader?") List headers)

Was this article helpful?

💙 Thanks for your feedback!

Edit on GitHub