Forum Discussion

tpowers's avatar
tpowers
Occasional Contributor
15 years ago

[SOLVED] Help with the 'groovyUtils.getXmlHolder'

I am using soapUI mock service to test a client calling from a DB (Intersystems Cache), and I can't seem to read properties into my dispatch script (I also am using them in the response) from the xml holder.

I am thinking it has something to do with the format of the incoming request, but i cannot seem to make the XML holder read in the values from my live client WS.

This request, generated from soapUI works fine...
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
<soapenv:Header/>
   <soapenv:Body>
      <tem:RunScript>
         <!--Optional:-->
         <tem:optionObject>
            <tem:EntityID>5</tem:EntityID>
            <tem:Facility>98</tem:Facility>
              <Forms>
               <FormObject....


I am able to assign properties with the following code.....

def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
def holder = groovyUtils.getXmlHolder( mockRequest.requestContent )

context.Facility = holder.getNodeValue( "//tem:Facility")
context.EntityID = holder.getNodeValue( "//tem:EntityID")


However when I get the following request from my client (or the same format when sent from soapUI)...
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:s="http://www.w3.org/2001/XMLSchema">
   <SOAP-ENV:Body>
      <RunScript xmlns="http://tempuri.org/">
         <optionObject>
            <EntityID>5</EntityID>
            <Facility>98</Facility>
            <Forms>
               <FormObject....


I cannot assign any values if the script is written as follows.....


def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
def holder = groovyUtils.getXmlHolder( mockRequest.requestContent )

context.Facility = holder.getNodeValue( "//Facility")
context.EntityID = holder.getNodeValue( "//EntityID")


I also notice that this request is read in 'flat' meaning that when I view the request detail from the mock service editor it looks like this....(note the !CDATA[string]] at the end)

<?xml version="1.0" encoding="UTF-8" ?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:s='http://www.w3.org/2001/XMLSchema'>
  <SOAP-ENV:Body>
<RunScript xmlns="http://tempuri.org/"><optionObject><EntityID>5</EntityID><Facility>98</Facility><Forms><FormObject><CurrentRow><Fields><FieldObject><FieldNumber>2</FieldNumber><FieldValue><![CDATA[ROSS,JOE]]>....
</SOAP-ENV:Envelope>


...While the first sample from above appears as formatted XML when viewed in the same pane.

Any ideas how I can read in properties if my requests are arriving like this???

Any help is greatly appreciated!!

-Tim

5 Replies

  • M_McDonald's avatar
    M_McDonald
    Super Contributor
    I put it all in a Groovy script and it seems to work:

    def xml = '''<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:s="http://www.w3.org/2001/XMLSchema">
      <SOAP-ENV:Body>
      <RunScript xmlns="http://tempuri.org/">
            <optionObject>
                <EntityID>5</EntityID>
                <Facility>98</Facility>
    </optionObject>   
        </RunScript>
    </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>'''

    def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
    def holder = groovyUtils.getXmlHolder( xml )
    holder.declareNamespace( 'ns', 'http://tempuri.org/')

    log.info holder.getNodeValue( "//ns:Facility")
    log.info holder.getNodeValue( "//ns:EntityID")


    returns

    [tt:23s6pby9]Tue Dec 08 15:01:48 EST 2009:INFO:98
    Tue Dec 08 15:01:48 EST 2009:INFO:5[/tt:23s6pby9]
  • Hi,

    A below code can alos help.


    groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
    responseHolder = groovyUtils.getXmlHolder( xml )
    FacilityValue = responseHolder.getNodeValue("//*:Facility")


    We are allowing wildcards here.

    Thanks
    Rohit Borse
  • tpowers's avatar
    tpowers
    Occasional Contributor
    Well; I think my issue is with the declaration of a default namespace, rather than a prefix for each individual tag.


    http://www.w3schools.com/XML/xml_namespaces.asp
    scroll down to default namespaces



    Again, a sample below of the request being read in...

    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:s="http://www.w3.org/2001/XMLSchema">
       <SOAP-ENV:Body>
       <RunScript xmlns="http://tempuri.org/">
             <optionObject>
                <EntityID>5</EntityID>
                <Facility>98</Facility>
                <Forms>
                   <FormObject....     //more
                 </Forms>
        </RunScript>



    Can holder.getNodeValue work here without a ns prefix???

    It seems strange that it wouldn't just pick it up. I can see the entire request when write out the xmlObject to the log.

    I have already tried to include the 'path' (wrong term I know) within the xml such as...
    context.EntityID = holder.getNodeValue( "//RunScript/optionObject/EntityID")

    ...and every combination of the proceeding I can find, but still not able to read in node value(s).

    I also have tried declaring the default ns in the script it in various ways but I am just guessing because I have not seen any examples without a prefix. But that didn't seem logical anyway because i wasn't using any prefixes, which I think is the point when declaring in the script.

    Is this a bug?

    Thanks again.
    -Tim
  • M_McDonald's avatar
    M_McDonald
    Super Contributor
    Have you tried declaring the namespace like this?

    holder.declareNamespace( 'ns', 'http://tempuri.org/')
    context.EntityID = holder.getNodeValue( "//ns:EntityID")
  • tpowers's avatar
    tpowers
    Occasional Contributor
    Excellent!
    That seemed to work!

    I had tried various forms of...
    //holder.namespaces ["ns"] = "http://tempuri.org"

    Thanks once again for your help.