JMeter - Remove empty elements in SOAP request

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

JMeter - Remove empty elements in SOAP request

SandeepKommineni
This post has NOT been accepted by the mailing list yet.
I am using CSV Data Set Config to fill SOAP/XML variables to request in JMeter. My problem is, when some variables are empty, then i get error on validation caused by this so I need to get rid of those.

There is very similar topic, well described (Jmeter remove empty strings at a SOAP/xml reqeust), unfortunately the solution is not working for me, iam getting:

meter.util.BeanShellInterpreter: Error invoking bsh method: eval Sourced file: inline evaluation of: ``String data = sampler.getXmlData(); data = data.replaceAll("",""); . . . '' : Typed variable declaration : Error in method invocation: Method getXmlData() not found in class'org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy'
Reply | Threaded
Open this post in threaded view
|

Re: JMeter - Remove empty elements in SOAP request

glinius@live.com
This post has NOT been accepted by the mailing list yet.
Add a JSR223 PreProcessor as a child of the HTTP Request sampler and put the following code into "Script" area:

import groovy.xml.XmlUtil

def content = sampler.getArguments().getArgument(0).getValue();
sampler.getArguments().removeAllArguments()

Node xml = new XmlParser().parseText(content)
cleanNode(xml)

def newContent = XmlUtil.serialize(xml)
sampler.addNonEncodedArgument("", newContent, "")


boolean cleanNode(Node node) {
    node.attributes().with { a ->
        a.findAll { !it.value }.each { a.remove(it.key) }
    }
    node.children().with { kids ->
        kids.findAll { it instanceof Node ? !cleanNode(it) : false }
                .each { kids.remove(it) }
    }
    node.attributes() || node.children() || node.text()
}
See Apache Groovy - Why and How You Should Use It article for more information.