Forum Discussion
soapug
11 years agoNew Contributor
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.
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.