XmlSlurper가 분명히 결과에서 작동하지 않는 이유를 모르겠습니다.Groovy HTTPBuilder SOAP 응답이 제대로 구문 분석되지 않습니다.
import groovyx.net.http.*
import static groovyx.net.http.ContentType.*
import static groovyx.net.http.Method.*
def String WSDL_URL = ...
def http = new HTTPBuilder(WSDL_URL , ContentType.XML)
String soapEnvelope =
"""<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<GetTerritories xmlns="...">
<State>AZ</State>
<ZipCode>85203</ZipCode>
</GetTerritories>
</soap12:Body>
</soap12:Envelope>"""
http.request(POST, XML) {
headers."Content-Type" = "application/soap+xml; charset=utf-8"
headers."Accept" = "application/soap+xml; charset=utf-8"
body = soapEnvelope
response.success = { resp, xml ->
println "XML was ${xml}"
println "Territories were ${xml.Territories}"
println "State were ${xml.Territories.State}"
println "City was ${xml.Territories.Territory.City}"
println "County was ${xml.Territories.Territory.County}"
}
response.failure = { resp, xml ->
xml
}
}
는
XML was <Territories><State>AZ</State><ZipCode>85203</ZipCode><Territory><City>Mesa</City><County>Maricopa</County>...</Territory></Territories>
Territories were
State were
City was
County was
UPDATE로 연결 : 감사 존 Wagenleitner의 통찰력에, 나는 좀 더 파고했다. 그래서 보이는
XML was <?xml version="1.0" encoding="utf-8"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<GetTerritoriesResponse xmlns="...">
<GetTerritoriesResult><Territories><State>AZ</State><ZipCode>85203</ZipCode><Territory><City>Mesa</City><County>Maricopa</County>...</Territory></Territories>
</GetTerritoriesResult>
</GetTerritoriesResponse>
</soap:Body>
</soap:Envelope>
...
을 : 계시 POST, XML
에서 POST, TEXT
에 요청 매개 변수를 변경
assert "Territories" == xml.name()
| | |
| | Envelope
| <Territories><State>AZ</State><ZipCode>85203</ZipCode</Territories>
false
: 나는 주장을 추가하면
, 내가 문제를 참조 변수가 인쇄 될 때 XmlSlurper와 같이 SOAP 물건을 버리고 내부 탐색 노드()를 평가하는 동안 실제로 탐색하지 않습니다. 그 노드. 이 예상되는 동작입니까?더 완벽하고 현대적인 SOAP 호출을 찾을 수 없었고 httpBuilder를 사용하여 구문 분석을 수행 했으므로 XML을 올바른 콘텐츠 형식으로 간주했습니다. 그러나 나는 텍스트를 받아 들여 절름발이로 해석해야하는 것처럼 보입니다. httpBuilder로 SOAP 응답을 처리하는 더 좋은 방법이 있습니까?
내가 응답의 원시 텍스트 인쇄 추천 할 것입니다
감사합니다.이 의견은 도움이되었습니다. Scott Davis의 Groovy Recipes에 대한 기사에서 Text()는 XmlSlurper가 아니라 XmlParser를위한 도구라고 생각했습니다. 나는 $ {xml}과 $ {xml.name()}의 인쇄본 사이의 불일치로 인해 곤란을 겪었다. 왜 그 일을하는지 알아? –
xml GPathResult를 인쇄하면 태그가 표시되지 않고 텍스트 내용 만 표시되므로 사용자가 본 결과가 표시됩니다. –
GPathResult에서 text()를 호출하면 해당 요소의 텍스트 내용이있는 문자열이 반환됩니다. println과 같은 일을 할 때는 GPathResult의 toString() 메서드가 요소의 텍스트 내용을 인쇄하기 때문에 대개 꼭 필요한 것은 아닙니다. –