Log the SOAP request xml in Mule flow
- Get link
- X
- Other Apps
Hello Reader,
Recently I came across in a situation where I wanted to see the actual SOAP request xml which was sent to Mule endpoint. I tried adding a Logger component as advised on mulesoft blog but the request was not getting logged. So I did some hit and trials in the Mule flow mentioned here to finally make the SOAP request xml print in the logs.
Below is what I did to success :
1. In Anypoint studio, searched for logger component from right pane and dropped it just before the SOAP component. 2. In the "Mule Properties View" of this component, put #[payload] against "message" textbox. This text box is to log whatever you want to log using this component. Since we want whole xml to be logged hence we will use #[payload] 3. Save and run the Mule application. 4. Call the Mule SOAP endpoint using your favorite tool like SOAPUI. 5. You will see below logging in the logs
INFO 2015-04-01 17:11:19,307 [[soap-ws-mule].Connector_Config.worker.01] org.mule.api.processor.LoggerMessageProcessor: org.glassfish.grizzly.utils.BufferInputStream@1edafedbBut this was not that what we intended to print in logs. Here Mule passes the request input stream to the logger component and the logger tries to print it directly using toString() method of the input stream. In order to print the request message in correct format we need to tell Mule to convert the request stream to a String first and then pass it to Logger component.
For this we need add a "Object to String" transformer before the logger component. This transformer will transform the request xml object to a String and pass it to logger component for further processing.
After adding the transformer, restart mule application again and send the soap request again. You can now see the soap request xml in console.
Below is the updated mule flow xml with these 2 new components added (object-to-string-transformer and logger)
<?xml version="1.0" encoding="UTF-8"?> <mule xmlns:cxf="http://www.mulesoft.org/schema/mule/cxf" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.6.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd http://www.mulesoft.org/schema/mule/cxf http://www.mulesoft.org/schema/mule/cxf/current/mule-cxf.xsd"> <http:listener-config name="Connector_Config" host="localhost" port="8090" doc:name="HTTP Listener Configuration" basePath="mulesvc"/> <flow name="soap-webservice-muleFlow"> <http:listener config-ref="Connector_Config" path="sample/soapws/DoubleIt.svc" doc:name="HTTP"/> <object-to-string-transformer doc:name="Object to String"/> <logger message="#[payload]" level="INFO" doc:name="Logger"/> <cxf:jaxws-service service="DoubleIt.svc" serviceClass="com.sample.mule.DoubleItPortType" doc:name="CXF" wsdlLocation="C:\Mule-workspace\workspace\soap-ws-mule\src\main\resources\example-soap-ws.wsdl"/> <component class="com.sample.mule.impl.DoubleItPortTypeImpl" doc:name="Java"/> </flow> </mule>
See the highlighted lines above which were added by these 2 new components. Hope this helps.
- Get link
- X
- Other Apps
Comments
Learning new technolgoy would help oneself at hard part of their career. And staying updated is the only way to survive in current position. Your content tells the same. Thanks for sharing this information in here. Keep blogging like this.
ReplyDeleteBest JAVA Training institute in Chennai
Thanks for sharing this valuable information.
ReplyDeletelenovo laptop service center in chennai
lenovo thinkpad service center chennai
lenovo ideapad service center chennai
be projects in chennai
ReplyDeletens2 projects in chennai
ieee java projects in chennai
ieee dotnet projects in chennai
mba projects in chennai
mca projects in chennai
bulk projects in chennai
ReplyDeletethe blog is about log the soap request xml in mule flow for more updates on mulesoft follow the link
mulesoft Online Training
For more info on other technologies go with below links
tableau online training hyderabad
ServiceNow Online Training
Python Online Training
the blog is good and Interactive it is about Mulesoft Anypoint Studio it is useful for students and Mulesoft Developers for more updates on Mulesoft mulesoft Online training hyderabad
ReplyDelete