Forum Discussion
Borigor
11 years agoNew Contributor
soapug wrote: I would recommend that you use the approach mentioned in the SoapUI documentation section.
Specifically, create a few XML templates using the JSP-like syntax to get to the context. SoapUI chooses the template based on the return value of the script. For example:
Script:
context._3 = 'MSQ'
if (isFour) {
context._4 = 'Whatever'
return "Response with 4"
}
return "Response"
Template "Response with 4":
<three>${_3}</three>
<four>${_4}</four>
You could customize the templates and do things your way but you'll lose out on a lot of built-in functionality, like the response template name appearing in the web page for the mock service. My team finds this invaluable when actually using the mock services. This is because you can actually see what template the mock service is using.
Alternatively, you can also just use Groovy, without using SoapUI. Creating Web Services in Groovy is pretty easy.
Thank you, soapug!
Unfortunately, this approach does not suit me, because I need to compose Response from repeated (20-50 times) almost the same complex (about 200 tags each) XML structures with different tag/attributes values. It means that I need only one template, but with different placeholder values for each iteration. That's why I need Map and conditional handling (for customizing some slight differences in composed xml's). Something like handling XML in FreeMarker or Velocity.