Contact Us 1-800-596-4880

@InboundHeaders Annotation

Mule Runtime Engine versions 3.5, 3.6, and 3.7 reached End of Life on or before January 25, 2020. For more information, contact your Customer Success Manager to determine how you can migrate to the latest Mule version.

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)