web services - Mule http request returns complete soap message

Below http:outbound-endpoint returns the expected response as CDATA but when i change it to http:request it returns the whole SOAP message instead of just CDATA. I don't want to write any custom code to extract the CDATA.

Any help is appreciated!

Flow works with http:outbound-endpoint:

<flow name="Client">
    <logger message="REQUEST : #[payload]" level="WARN"/>
    <http:outbound-endpoint exchange-pattern="request-response" address="http://server:8080/RoomStatusService/webservices.asmx" >
        <cxf:jaxws-client clientClass="com.test.webservices.WebServices" operation="UpdateRoomStatus" port="WebServicesSoap" />
    </http:outbound-endpoint>
    <logger message="RESPONSE : #[payload]" level="WARN"/>
</flow>

Expected Response:

REQUEST : <?xml version="1.0" encoding="UTF-8" standalone="yes"?><RoomStatusDetail><InspBy>AUTO</InspBy><RoomNumber>402</RoomNumber><RoomStatus>3</RoomStatus><Wing>ST</Wing></RoomStatusDetail>
RESPONSE : <UpdateRoomStatusResult><RoomStatusDetail>Room updated.</RoomStatusDetail></UpdateRoomStatusResult>

Flow doesn't work with http:request:

<http:request-config  name="CONFIG"  host="server" port="8080" doc:name="HTTP Request Configuration"/>
    <flow name="Client">
        <logger message="REQUEST : #[payload]" level="WARN"/>

        <cxf:jaxws-client clientClass="com.test.webservices.WebServices" operation="UpdateRoomStatus" port="WebServicesSoap" />
        <http:request config-ref="CONFIG"  path="RoomStatusService/webservices.asmx"  method="POST" doc:name="HTTP"  >
            <http:success-status-code-validator values="0..599"/>
        </http:request>
        <logger message="RESPONSE : #[payload]" level="WARN"/>
    </flow>

Incorrect Response:

REQUEST : <?xml version="1.0" encoding="UTF-8" standalone="yes"?><RoomStatusDetail><InspBy>AUTO</InspBy><RoomNumber>402</RoomNumber><RoomStatus>3</RoomStatus><Wing>ST</Wing></RoomStatusDetail>
RESPONSE  : <?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><UpdateRoomStatusResponse xmlns="http://testsoftware.com/webservices/"><UpdateRoomStatusResult><UpdateRoomStatusResult><RoomStatusDetail>Room updated.</RoomStatusDetail></UpdateRoomStatusResult></UpdateRoomStatusResult></UpdateRoomStatusResponse></soap:Body></soap:Envelope>

Sample Request & Response:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://testsoftware.com/webservices/">
   <soapenv:Header/>
   <soapenv:Body>
      <web:UpdateRoomStatus>
         <web:UpdateRoomStatusRequest><![CDATA[<?xml version="1.0" encoding="UTF-8" standalone="yes"?><RoomStatusDetail><Wing>ET</Wing><RoomNumber>50102</RoomNumber><RoomStatus>1</RoomStatus><InspBy>test</InspBy></RoomStatusDetail>]]></web:UpdateRoomStatusRequest>
      </web:UpdateRoomStatus>
   </soapenv:Body>
</soapenv:Envelope>

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   <soap:Body>
      <UpdateRoomStatusResponse xmlns="http://testsoftware.com/webservices/">
         <UpdateRoomStatusResult><UpdateRoomStatusResult><RoomStatusDetail>Room updated.</RoomStatusDetail></UpdateRoomStatusResult></UpdateRoomStatusResult>
      </UpdateRoomStatusResponse>
   </soap:Body>
</soap:Envelope>

2 Answers

  1. Chris- Reply

    2019-11-13

    http:outbound is not doing anything but it is the tag which removes the SOAP envelope around the response. If you are consuming SOAP web service, better use Web service consumer.

  2. Colin- Reply

    2019-11-13

    You can use replace function to remove soap envelope like as below.Once you receive the payload ,use Set payload :

     #[message.payloadAs(String).replace('<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
       <soap:Body>
          <UpdateRoomStatusResponse xmlns="http://testsoftware.com/webservices/">','')]
    

    and again use replace function to remove end part of Soap envelope and then pretty print the response

    <mulexml:xml-prettyprinter-transformer xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml" newlines="false" indentEnabled="false" padText="false" trimText="true"/>
    

Leave a Reply

Your email address will not be published. Required fields are marked *

You can use these HTML tags and attributes <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>