简体   繁体   中英

Mule 3: How to get the HTTP headers from a MuleMessage

Given a MuleMessage object that was created from an HTTP request, how do you get the HTTP headers of the request? I'm using Mule 3.2.1. Thanks.

HTTP headers are stored as inbound-scoped properties. Their property names are prefixed with http. . For example:

MuleMessage message = ...
String contentType = (String)message.getInboundProperty("http.Content-Type");

But there are other HTTP-related properties inside of the "http." property namespace as well, such as "http.status" for the status code and "http.request" for the request URL. So, while it's possible to retrieve individual headers, there's no reliable, automated way of getting a list of all HTTP headers.

This issue is slated to be fixed in Mule 3.3 . Mule 3.3 will organize HTTP-related properties better. For example, all headers will be stored in a property named "http.headers", and all query string parameters will be parsed and stored in "http.query.params".

所有HTTP标头都位于MuleMessage的入站范围属性中。

You can also check by putting log message

<logger message="=============test= #[message.inboundProperties]" level="INFO" doc:name="Logger"/>

Let me know if that works for you.

Thanks

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM