Forum Discussion
SmartBear_Suppo
12 years agoSmartBear Alumni (Retired)
Hi,
Unfortunately "Remove Empty Content" property applies to SOAP requests only. With REST requests we can't be sure whether the payload is XML, JSON, any text, etc. So there's no applied logic to remove XML.
For a workaround I would suggest using an event filter: http://www.soapui.org/Scripting-Propert ... dlers.html
So I have the following code that works in my instance but it is just a suggestion and requires full blown testing. This is not part of core SoapUI Pro offering and we can't provide support for it if there are edge cases where it fails.
You can create "RequestFilter.filterRequest" (http://www.soapui.org/Scripting-Propert ... dlers.html) and paste in the following code:
**UPDATE (1/17/2014)**
I have since seen an issue with the above code. It leaves property expansion without evaluating it. Also, it didn't take into an account whether the node removed was an endnode. The following improved workaround code takes care of those issues:
Thanks,
Michael Giller
SmartBear Software
Unfortunately "Remove Empty Content" property applies to SOAP requests only. With REST requests we can't be sure whether the payload is XML, JSON, any text, etc. So there's no applied logic to remove XML.
For a workaround I would suggest using an event filter: http://www.soapui.org/Scripting-Propert ... dlers.html
So I have the following code that works in my instance but it is just a suggestion and requires full blown testing. This is not part of core SoapUI Pro offering and we can't provide support for it if there are edge cases where it fails.
You can create "RequestFilter.filterRequest" (http://www.soapui.org/Scripting-Propert ... dlers.html) and paste in the following code:
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
def stepName = context.getCurrentStep().getLabel()
def holder = groovyUtils.getXmlHolder( stepName + "#Request" )
// set default value here
def defaultVal = ""
for( item in holder.getDomNodes( "//*[. = '']" )){
holder.removeDomNodes("//"+item.nodeName)
}
// update request
holder.updateProperty()
// write updated request back to teststep
context.requestContent = holder.xml
**UPDATE (1/17/2014)**
I have since seen an issue with the above code. It leaves property expansion without evaluating it. Also, it didn't take into an account whether the node removed was an endnode. The following improved workaround code takes care of those issues:
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
def holder = groovyUtils.getXmlHolder( context.requestContent )
// find end nodes that also only consist of whitespace
for( item in holder.getDomNodes( "//*[normalize-space(.) = '' and count(*) = 0]" )){
item.removeXobj()
}
// update request and write updated request back to teststep
holder.updateProperty()
context.requestContent = holder.xml
Thanks,
Michael Giller
SmartBear Software
Related Content
- 7 years ago
Recent Discussions
- 7 days ago