Paperbag Writer
Paperbag Writer

Reputation: 823

How to log HTTP Request's Body (POST) (XML) in Mule ESB

Hello I am trying to log the content of the POST content in Mule ESB as the other end receives all content except the the ContactId which is in binary. We are trying to identify where the error is. Here is the flow.

<flow name="ContactUpdate">
    <http:inbound-endpoint exchange-pattern="request-response" host="host" port="port" path="ContactUpdate" doc:name="HTTP"/>
    <logger level="INFO" doc:name="Logger" message="#[payload]"/>
    <ws:consumer config-ref="Web_Service_Consumer" operation="UpdateContact" doc:name="UpdateContact"/>
</flow>

In the log I can only see the content's lenght and other informations but not the actual content of the body that is sent in POST. Is it possible to do such a thing?

Thanks for helping

Upvotes: 1

Views: 4116

Answers (3)

duddukurimd
duddukurimd

Reputation: 30

We can retrieve the message payload in a particular format, using Mule’s auto-transformation capability, use payloadAs:

<logger message="#[message.payloadAs(java.lang.String)]" />

your code can be changed as

<flow name="ContactUpdate">
    <http:inbound-endpoint exchange-pattern="request-response" host="host" port="port" path="ContactUpdate" doc:name="HTTP"/>
    <logger level="INFO" message="#[message.payloadAs(java.lang.String)]"/>
    <ws:consumer config-ref="Web_Service_Consumer" operation="UpdateContact" doc:name="UpdateContact"/>
</flow>

Upvotes: 0

Ranga
Ranga

Reputation: 1

  1. In Any-point Studio, place a Logger component, just before the Web Consumer Component
  2. In General section, Message : #[message.payloadAs(java.lang.String)] Level : INFO(Default).

Upvotes: 0

David Dossot
David Dossot

Reputation: 33413

As explained in the documentation, you can retrieve the payload as a String in a MEL expression:

<logger level="INFO" message="#[message.payloadAs(java.lang.String)]"/>

Keep in mind this will deserialize the HTTP request input stream payload, which could hit your memory badly if you're receiving a huge payload.

Upvotes: 5

Related Questions