我基本上是試圖通過檢查響應對象 我有一個SOAP服務的響應,我期待它在服務檢查失敗如下: 以下是輸入流創建XML文檔[來源兩個輸入流]
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<S:Envelope xmlns:S="http://www.w3.org/2003/05/soap-envelope">
<S:Body>
<S:Fault xmlns:ns4="http://schemas.xmlsoap.org/soap/envelope/">
<S:Code>
<S:Value>S:Receiver</S:Value>
</S:Code>
<S:Reason>
<S:Text xml:lang="en">org.xml.sax.SAXParseException; cvc-complex-type.2.4.b: The content of element 'ns2:MYREQ' is not complete. One of '{"urn:SOMETHINGELSE}' is expected.</S:Text>
</S:Reason>
</S:Fault>
</S:Body>
</S:Envelope>
。 當我使用下面的代碼,將其轉換爲SOAP消息的文檔:
SOAPMessage message = MessageFactory.newInstance("SOAP 1.2 Protocol").createMessage(null, response);
Document responseDocument = message.getSOAPBody().extractContentAsDocument();
肥皂enevelope修剪和我只
<S:Fault xmlns:ns4="http://schemas.xmlsoap.org/soap/envelope/">
<S:Code>
<S:Value>S:Receiver</S:Value>
</S:Code>
<S:Reason>
<S:Text xml:lang="en">org.xml.sax.SAXParseException; cvc-complex-type.2.4.b: The content of element 'ns2:MYREQ' is not complete. One of '{"urn:SOMETHINGELSE}' is expected.</S:Text>
</S:Reason>
</S:Fault>
但是,當我使用文檔構建這樣來做,我得到正確的輸出
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document responseDocument = builder.parse(response);
請讓我知道爲什麼它,當我InputStream的轉換爲SOAP消息,然後向文件中,enevelope和身體不見了。
嗯,這聽起來好像'getSOAPBody()'and'extractContentAsDocument()'他們說的去做。如果你想看到完整的消息,那麼使用'writeTo'。 –