简体   繁体   中英

How to read parameter in mule esb

I am sending some parameter to mule which is listening through http inbound in 8081 I am sending.

http://localhost:8081/hey?age=manoj

But I don't know How can I take this as from message?? I know I can access it from message and payload but when I try to do this

#[message payload: ['age']]

I am getting error that payload is a String type and I am very much confuse in mule. I want age value.

If you are using Mule 3.6 version or above, the expression has been changed ..
So now, you need the following expression to get the value :-

#[message.inboundProperties.'http.query.params'.age]

You can find the reference here for you query :- https://developer.mulesoft.com/docs/display/current/HTTP+Listener+Connector

This will come in as an inbound property. You can access it using MEL:

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

Be careful though you need to make sure to use the inboundProperty in the same flow as your HTTP Inbound endpoint.

You can retrieve the HTTP query parameters through the inbound property http.query.params . To obtain the age parameter, use the following MEL expression

#[message.inboundProperties.'http.query.params'.get('age')]

You need to use Mule HTTP Body to Param Map transformer, to convert the Params to a Map.

<http:body-to-parameter-map-transformer />      

Then inorder to access the parameter the MEL expression to be used is #[payload['age']]

Hope this helps.

In Mule 3.6 or 3.7, if you been using the Body to Parameter transformer in your mule applications, this has been deprecated. If you need to access the inbound properties values, you can do that using message.inboundProperties .

#[message.inboundProperties.'http.query.params']

Example:

 <set-payload value="#[message.inboundProperties.'http.query.params']" doc:name="Set Payload"/>

If you want to use it in a groovy script please refer to this

getting inbound properties of ESB Mule message using Groovy

which basically tells you can use it as

message.getInboundProperty('http.query.params')?.yourFantasticParam

or

message.getInboundProperty('http.query.params')?.age

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