Successfully reported this slideshow.
Your SlideShare is downloading. ×

Parameters as a part of body

Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Upcoming SlideShare
Setting filedynamically
Setting filedynamically
Loading in …3
×

Check these out next

1 of 18 Ad

More Related Content

Similar to Parameters as a part of body (20)

Advertisement

More from Anirban Sen Chowdhary (20)

Recently uploaded (20)

Advertisement

Parameters as a part of body

  1. 1. By Anirban Sen Chowdhary
  2. 2. Today we will be looking at how to map an inbound properties of a Mule message with the Message payload
  3. 3. But before we go forward let’s quickly into what is a Mule Messages and the structure of a Mule message
  4. 4. If we look at the Mule message format, we find that Mule message is generally divided into 3 parts as follows:- You can see there are basically 3 parts :- 1) Properties :- Outbound or Inbound properties like our query param 2) Payload :- Contains the actual message content 3) Attachment :- It’s optional field may or may not contain attachment Image source :- Mule Soft
  5. 5. Now, in our application what ever we send as a query parameter in the browser comes into our application as inbound properties of Message. For example if we use the following url in our browser :- http://localhost:8888/test?id=231&name=Anirban Here we are sending 2 query parameters id=231&name=Anirban in our application which will come as an inbound properties in our application
  6. 6. .
  7. 7. We can use following MEL expression in our logger to extract the values of query parameter in our Mule application :- #[message.inboundProperties['id']] #[message.inboundProperties['name']] If we put the above expression in a logger :- <logger message="inbound #[message.inboundProperties['id']] #[message.inboundProperties['name']]" level="INFO" doc:name="Logger"/> we will get the following values in our console :-
  8. 8. Now what if we want to put the query parameter as a part of Message payload and not as an Inbound properties of Message ???
  9. 9. Yes, you can easily map an Inbound properties of a Mule Message with Mule payload by using :- <http:body-to-parameter-map-transformer/> This component will transform all the Inbound properties ( query parameter in our case ) as a part of actual Message payload
  10. 10. Now, we will see a simple example to know how the component http:body-to-parameter-map-transformer transform all the Inbound message properties into actual message payload
  11. 11. You can see a simple flow, where we have put http:body-to-parameter- map-transformer after Http inbound endpoint. The main task of this component will be transforming all the Inbound properties of messages into the message payload as a hash map of name-value pairs
  12. 12. The flow in the Mule config will be :- <flow name="Body-To-Parameter-MapFlow1" doc:name="Body-To-Parameter-MapFlow1"> <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8888" path="test" doc:name="HTTP" /> <logger message="inbound #[message.inboundProperties['id']] #[message.inboundProperties['name']]" level="INFO" doc:name="Logger"/> <http:body-to-parameter-map-transformer doc:name="Body to Parameter Map"/> <logger level="INFO" category="Log1" doc:name="Logger" message="#[message.payload['id']] #[message.payload['name']]"/> <logger level="INFO" category="Full Message" doc:name="Logger" message="#[message.payload]"/> </flow>
  13. 13. The flow in the Mule config will be :- <flow name="Body-To-Parameter-MapFlow1" doc:name="Body-To-Parameter-MapFlow1"> <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8888" path="test" doc:name="HTTP" /> <logger message="inbound #[message.inboundProperties['id']] #[message.inboundProperties['name']]" level="INFO" doc:name="Logger"/> <http:body-to-parameter-map-transformer doc:name="Body to Parameter Map"/> <logger level="INFO" category="Log1" doc:name="Logger" message="#[message.payload['id']] #[message.payload['name']]"/> <logger level="INFO" category="Full Message" doc:name="Logger" message="#[message.payload]"/> </flow> As you can see here we have put 2 loggers to check the message payload content after http:body-to-parameter-map-transformer with the MEL expression :- #[message.payload['id']] and #[message.payload['name']] And to check full message payload :- #[message.payload]
  14. 14. If we check behind the scene what the http:body-to-parameter-map- transformer is actually doing :- You can see it’s transforming message properties into payload content
  15. 15. Now, if we test our application and hit the following url :- http://localhost:8888/test?id=231&name=Anirban We will get the following in our console :- You can see in the log that the query parameters are now part of actual message payload
  16. 16. For more information on this http:body-to-parameter-map-transformer please visit MuleSoft documentation :- http://www.mulesoft.org/documentation/display/current/HTTP+Transport+R eference PS: As of Mule 3.6 and later, the HTTP endpoint-based connector and transport has been replaced by an operation-based HTTP connector.
  17. 17. Hope you enjoyed the simple yet an amazing trick in Mule. And I wish these simple trick would be beneficial for a beginner in Mule and help him/her in learning and implementing these concepts in Mule

×