groovy 第139章:一个女人无法解析类XmlParser

oxcyiej7  于 2022-11-01  发布在  其他
关注(0)|答案(1)|浏览(144)

尝试从Jenkins运行groovy脚本时,出现以下错误

C:\Jenkins\workspace\Load-Test-for-container-HimaM13\hudson16255048887172875424.groovy: 139: unable to resolve class XmlParser @ line 139, column 14.
            def root = new XmlParser().parseText(response)
            ^

使用的Groovy版本groovy-4.0.0-rc-2
程式码片段

try {
        String response = sendSoap(request, "getSamlArtifact")
        def soapNS = new groovy.xml.Namespace("http://schemas.xmlsoap.org/soap/envelope/", "SOAP")
        def samlProtocolNS = new groovy.xml.Namespace("urn:oasis:names:tc:SAML:1.0:protocol", "samlp")
        def root = new XmlParser().parseText(response)
        def assertionArtifact = root[soapNS.Body][samlProtocolNS.Response][samlProtocolNS.AssertionArtifact]

        if (null == assertionArtifact[0]){
            //printString("value1-"+assertionArtifact[0])
            return null
        }
        else
            return assertionArtifact[0].text();
    } catch (IOException e) {
        return null
    }
tez616oj

tez616oj1#

在尝试了

def root = new groovy.xml.XmlParser().parseText(response)

而不是

def root = new XmlParser().parseText(response)

相关问题