Adam_White
17 years agoNew Contributor
Help getting node value with groovy script
Hi,
I'm having trouble accessing a node value, I keep getting null returned. I'm using the free version of SoapUI to prove what we need to do can be done, but I'm having trouble getting it to work.
The groovy script below is for a Mockservice. I'm trying to access a value from the request and send back a response based on a node value.
The XML Request is:
ccmsUser
ccmsPassword
Y
2
1
10
1-I6TS
232432
27E1460B-A5B9-4082-9968-235AAE728C22
My groovy script is:
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
def holder = groovyUtils.getXmlHolder( mockRequest.requestContent )
//return holder.getNodeValue( "//wsse:Username" )
return holder.getNodeValue( "//ServiceProviderEnrolmentReference" )
def sper = holder.getNodeValue( "//ServiceProviderEnrolmentReference" )
if (sper == "1")
return "Response 1"
else if (sper == "2")
return "Response 2"
else
return "Response 1"
The line return holder.getNodeValue( "//wsse:Username" ) works and returns a response. But holder.getNodeValue( "//ServiceProviderEnrolmentReference" ) returns null. If I change the node to anything contained within the tags I get null.
Can you tell me what I'm doing wrong?
Thanks,
Adam
I'm having trouble accessing a node value, I keep getting null returned. I'm using the free version of SoapUI to prove what we need to do can be done, but I'm having trouble getting it to work.
The groovy script below is for a Mockservice. I'm trying to access a value from the request and send back a response based on a node value.
The XML Request is:
My groovy script is:
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
def holder = groovyUtils.getXmlHolder( mockRequest.requestContent )
//return holder.getNodeValue( "//wsse:Username" )
return holder.getNodeValue( "//ServiceProviderEnrolmentReference" )
def sper = holder.getNodeValue( "//ServiceProviderEnrolmentReference" )
if (sper == "1")
return "Response 1"
else if (sper == "2")
return "Response 2"
else
return "Response 1"
The line return holder.getNodeValue( "//wsse:Username" ) works and returns a response. But holder.getNodeValue( "//ServiceProviderEnrolmentReference" ) returns null. If I change the node to anything contained within the tags I get null.
Can you tell me what I'm doing wrong?
Thanks,
Adam