在SOAP请求中搜索XPATH

时间:2014-08-11 20:45:44

标签: xml soap xpath groovy soapui

我试图使用groovy脚本在SoapUI中的testCase下更改请求,如下所示:

def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )  

// get XmlHolder for request message def 
holderRequest = groovyUtils.getXmlHolder( "createUser#Request" )

holderRequest["//IName"] = "TEST"

holderRequest.updateProperty()
context.requestContent = holderRequest.xml

通常它可以工作但不能使用特定的SOAP请求,因为从未找到XPATH,我尝试使用此工具http://www.xpathtester.com/xpath进行搜索,并确认无法找到该节点,可能是此特定请求导致此行为的原因?

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tws="http://www.safelayer.com/TWS">
   <soapenv:Header>
      <wsse:Security soapenv:actor="http://schemas.xmlsoap.org/soap/actor/next" soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
         <wsse:UsernameToken>
            <wsse:Username>RegOff</wsse:Username>
            <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">RegOff</wsse:Password>
         </wsse:UsernameToken>
      </wsse:Security>
   </soapenv:Header>
   <soapenv:Body>
      <tws:InsertRequest xpath="/TWS/EP/PU" xmlns="http://www.safelayer.com/TWS">
           <tws:data>
            <User dname="CN=Prueba de firma 25, OU=Tecnologia, O=Certicamara S.A">
            <Description>TX_ARCH_TEST_1</Description>
            <IName>0</IName>
            <Language>0</Language>
            <CName>
                    <Title>Sr.</Title>
                    <FName>Ususario</FName>
                    <Surname>de Firma</Surname>
            </CName>
            <OName>
                    <Title>Administrador de Infraestructura</Title>
                    <OU>Tecnologia</OU>
                    <O>Certicamara S.A</O>
            </OName>
            <SName>
                    <UID>TX_ARCH_TEST_1</UID>
                    <Passwd>{x-sha256}bkS45P9iX2mASGwFZWN7GtJ6NzDae3wYdRScSUu9epo=</Passwd>
            </SName>
            <Contacts>
                    <Work>
                    <Mail>trustedx@certicamara.com</Mail>
                    <Phone>+34 93 508 80 90</Phone>
                    </Work>
                    <Home/>
            </Contacts>
            <Certificates/>
        </User>
         </tws:data>
      </tws:InsertRequest>
   </soapenv:Body>
</soapenv:Envelope>

1 个答案:

答案 0 :(得分:1)

xmlns="http://www.safelayer.com/TWS"元素上的tws:InsertRequest表示您要查找的IName元素位于该命名空间中。您需要在holderRequest上使用前缀声明命名空间,并在XPath中使用前缀

holderRequest.namespaces["tws"] = "http://www.safelayer.com/TWS"
holderRequest["//tws:IName"] = "TEST"