smoothe19
12 years agoNew Contributor
[Resolved] GroovyScript updating XML
This is a soapUI load test and a REST service request with a media Type of: text/plain;charset=UTF8
I have a payload that is as follows
It is then altered by the following groovy script
However by the time the groovy script is done executing the "<?xml version="1.0" encoding="UTF-8"?>" in the payload request is stripped away and it causes the request to fail against my proxy service. How may I prevent ths from being removed or add it back to the top of my xml?
I have a payload that is as follows
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Header>
<Header>
</Header>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<Invoice>
</Invoice>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
It is then altered by the following groovy script
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
def holder = groovyUtils.getXmlHolder("InvoiceTestRequest1#request")
Random r = new Random()
def refnum = r.nextInt(999999)
while (refnum < 100000) {
refnum = r.nextInt(999999)
}
def cor = r.nextInt(999999)
while (cor < 100000) {
cor = r.nextInt(999999)
}
def mes = r.nextInt(999999)
while (mes < 100000) {
mes = r.nextInt(999999)
}
holder.setNodeValue( "//Header/MessageId" , ""+mes);
holder.setNodeValue( "//Header/CorrelationId" , ""+cor);
holder.updateProperty()
However by the time the groovy script is done executing the "<?xml version="1.0" encoding="UTF-8"?>" in the payload request is stripped away and it causes the request to fail against my proxy service. How may I prevent ths from being removed or add it back to the top of my xml?