Forum Discussion

Admins's avatar
Admins
Occasional Contributor
4 years ago

Write SOAP Body to File for Mock Service

I have a Mock Service running in SOAPUI and I want to get the message inside the SOAP Body for the Request and write it out to a file.

I have tried many methods but just can't seem to get the SOAP Body. I can get the Request which is the SOAP Envelope but get stuck here.

I am writing some groovy script in the OnRequest Script for the Mock Service, not sure if this is the right place.

Any help would be most appreciated.

9 Replies

  • richie's avatar
    richie
    Community Hero
    Hey Admins,

    I'm a bit confused by your post. Can you just clarify a couple of points.

    Where you state " I want to get the message inside the SOAP Body for the Request and write it out to a file." , what do you actually mean by "get the message inside the soap body". Are you saying that you have a payload contained within your soapbody container tag (which is all standard stuff) and youre using a mockservice/virt and you want to get the request's payload saved to a file or the response's payload saved to a file?

    When you say "you've tried many methods", can you explain what you've tried?

    In summary, if you coulr explain exactly what you need so its really clear, that'll only help people be able to sort you out.

    Ta

    Rich

    • Admins's avatar
      Admins
      Occasional Contributor

      Rich

       

      Yes, I want the XML Payload (ApplicationOutcomeUpdate) in the SOAP Body...

      <s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope"

      <s:Body>
      <ns0:ApplicationOutcomeUpdate xmlns:ns0="http://CompanyA/v1">....

      ...and I have a MockService which accepts this Request from an Application and I want to save the XML Payload inside the SOAP Body to a file.

       

      I have got the Request using... 

      def request = new XmlParser().parseText(mockRequest.requestContent)

      I then try and use XmlHolder, XmlSlurper or XmlParser to extract the Xml I need inside the SOAP Body but all I seem to get is Null.

       

      Regards

      Stewart

      • richie's avatar
        richie
        Community Hero
        Hey Admins,

        Cool, i might be able to help with th4 groovy, but the real scripters on here are better placed to do that.

        Can you provide exactly whst you've tried using each of the xml scraping methods you mention? There's no point me duplicating effort.
        It shouldn't be strsightforward to extract the whole response the whole envelope, then it just needs a bit of tinkering to scrape thr payload from the soapbody.

        I've just re-read what you've written. Are you saying you want to save the payload from the request or the response? It sounds like you want to save the request...

        Ta

        Rich