cancel
Showing results for 
Search instead for 
Did you mean: 

Write SOAP Body to File for Mock Service

Highlighted
Occasional Contributor

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 9
Highlighted
Community Hero

Re: Write SOAP Body to File for Mock Service

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

if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
Highlighted
Occasional Contributor

Re: Write SOAP Body to File for Mock Service

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

Highlighted
Community Hero

Re: Write SOAP Body to File for Mock Service

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
if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
Highlighted
Occasional Contributor

Re: Write SOAP Body to File for Mock Service

Richie

 

Apologies for the delay.

What I want to get is the Request which contains the Soap Envelope inside is the Soap Body and inside this is the payload message Its the payload message inside the Soap Body I want to save off to a file.

 

I have tried the following...

def req = new XmlHolder(messageExchange.requestContent)

def req = new XmlHolder(mockRequest.requestContent)

def req = new XmlHolder(context.request)

def req = new XmlSlurper(messageExchange.requestContent)

def req = new XmlSlurper(mockRequest.requestContent)

def req = new XmlSlurper(context.request)

...but I get either an error or null returned.

Highlighted
Occasional Contributor

Re: Write SOAP Body to File for Mock Service

Richie

 

OK, an update.

I have been able to get hold of the Request i.e. the SOAP Envelope using the following...

 

def request = mockRequest.getRequestContent()

 

Now I need to extract the payload inside the SOAP Body. That's what I need help on now.

Highlighted
Community Hero

Re: Write SOAP Body to File for Mock Service

Hey @Admins,

I think i've found a fix for this.

I will post later, however, forgive me but im gonna ask the question again just to be sure. You want the payload from the soapbody but from the request NOT the response returned from the mock service? How are you building the request body initially? I'm just wondering why you want request when youre building the request body....??

Ta

Rich
if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
Highlighted
Occasional Contributor

Re: Write SOAP Body to File for Mock Service

I can confirm I want the Payload inside the SOAP Body for the Request. I have a application that sends the Request to the Mock Service and as part of my Unit Testing I want to compare the Payload with my expected results.

Highlighted
Community Hero

Re: Write SOAP Body to File for Mock Service

Hey @Admins,

Are you still looking to extract the payload from the soapbody container tag once the request has been submitted?
Apologies, i couldnt find this post to answer. I did put a bit of groovy together (essentially using the replaceAll() method).
If you still need this i'll chuck that groovy together....its not pretty and is just a sequential strip out of the xml content you dont want....but it does do what you asked for.....if i understood correctly!

Ta

Rich
if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
Highlighted
Occasional Contributor

Re: Write SOAP Body to File for Mock Service

Rich

 

Yes I am still wanting to extract the Payload from the SOAP Body.

 

Appreciate if you could provide the groovy code.

 

Regards

New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors