2013-05-13 62 views
0

我试图解析来自Web服务的SOAP响应。我使用httpbuilder来执行请求。这里是我的代码:解析SOAP响应时出错

def String WSDL_URL = 'http://ws.webgains.com/aws.php' 
    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> 
     <getFullUpdatedEarnings xmlns="http://ws.webgains.com/aws.php"> 
      <startDate>2013</startDate> 
      <endDate>2013</endDate> 
      <username>username</username> 
      <password>pass</password> 

     </getFullUpdatedEarnings> 
     </soap12:Body> 
    </soap12:Envelope>""" 


      http.request(Method.POST, ContentType.XML) { 
       body = soapEnvelope 

       response.success = { resp, xml -> 
        println "XML was ${xml.Body.getFullUpdatedEarningsResponse.return.text()}" 

        def territories = new XmlSlurper().parseText(
         xml.Body.getFullUpdatedEarningsResponse.return.text() 
        ) 

       } 

       response.failure = { resp, xml -> 
        xml 
       } 
      } 

当我试图分析我得到一个org.xml.sax.SAXParseException内容不会在序言中所允许的响应。

下面是我从网络服务获得的输出:

3936713759987www.tikcode.com1367552013-05-13T15:04:482013-05-13T15:04:48Miniinthebox -  US46119566172850.060.8confirmednotcleared2013-05-13T14:58:33http%3A%2F%2Fwww.lightinthebox.com%2Fes%2F%3Flitb_from%3Daffiliate_webgainsEShttp%3A%2F%2Flocalhost%3A8080%2Fcom.publidirecta.widget%2Fpromocion%2FverPromocion%3Fpromocion%3D 

如果我使用ContenTyp.TEXT我得到的XML是

[<?xml version="1.0" encoding="UTF-8"?>, <env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:ns1="urn:http://ws.webgains.com/aws.php" xmlns:enc="http://www.w3.org/2003/05/soap-encoding" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><env:Body xmlns:rpc="http://www.w3.org/2003/05/soap-rpc"><ns1:getFullUpdatedEarningsResponse env:encodingStyle="http://www.w3.org/2003/05/soap-encoding"><rpc:result>return</rpc:result><return enc:itemType="ns1:fullLinesArray" enc:arraySize="1" xsi:type="ns1:fullReportArray"><item xsi:type="ns1:fullLinesArray"><transactionID xsi:type="xsd:int">39367137</transactionID><affiliateID xsi:type="xsd:int">59987</affiliateID><campaignName xsi:type="xsd:string">www.tikcode.com</campaignName><campaignID xsi:type="xsd:int">136755</campaignID><date xsi:type="xsd:dateTime">2013-05-13T15:04:48</date><validationDate xsi:type="xsd:dateTime">2013-05-13T15:04:48</validationDate><delayedUntilDate xsi:type="xsd:string"></delayedUntilDate><programName xsi:type="xsd:string">Miniinthebox - US</programName><programID xsi:type="xsd:int">4611</programID><linkID xsi:type="xsd:string">95661</linkID><eventID xsi:type="xsd:int">7285</eventID><commission xsi:type="xsd:float">0.06</commission><saleValue xsi:type="xsd:float">0.8</saleValue><status xsi:type="xsd:string">confirmed</status><paymentStatus xsi:type="xsd:string">notcleared</paymentStatus><changeReason xsi:nil="true"/><clickRef xsi:nil="true"/><clickthroughTime xsi:type="xsd:dateTime">2013-05-13T14:58:33</clickthroughTime><landingPage xsi:type="xsd:string">http%3A%2F%2Fwww.lightinthebox.com%2Fes%2F%3Flitb_from%3Daffiliate_webgains</landingPage><country xsi:type="xsd:string">ES</country><referrer xsi:type="xsd:string">http%3A%2F%2Flocalhost%3A8080%2Fcom.publidirecta.widget%2Fpromocion%2FverPromocion%3Fpromocion%3D</referrer></item></return></ns1:getFullUpdatedEarningsResponse></env:Body></env:Envelope>] 

我是相当新的网络服务,所以如果任何人有任何想法,我真的很感激任何帮助

编辑:也尝试用ws lite与相同的结果

+0

所以,他曾经让Web服务认为在XML标签之间抛出一个“,”非常有趣。删除了“,”,一切工作正常 – user1485182 2013-05-14 11:05:06

回答

0

它看起来像你第二次解析响应。为什么使用XmlSlurper解析return标签的文本? return下的元素已被解析并可直接访问。