我能够成功记录有效soap请求(通过wsimport生成的类)的请求和响应,但是在引发异常时(当请求中的节点填充了无效数据时)无法捕获xml内容。我可以获得响应的详细信息,但我只想捕获原始响应的 xml 部分。我已经尝试过 SOAPFaultException,但它只给出了异常消息,而不是带有响应正文的完整信封。如何在抛出的异常/错误中只捕获 xml 内容的异常。
注意:我知道我可以解析错误(原始响应)并提取 xml 内容,但我想知道是否有简单的方法/方法来获取 xml 内容,如下所示。内容应该看起来像(从 Soap UI 工具捕获的响应)
<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" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing">
<env:Header xmlns:env="http://www.w3.org/2003/05/soap-envelope">
<wsa:Action>http://schemas.xmlsoap.org/ws/2004/08/addressing/fault</wsa:Action>
<wsa:MessageID>urn:uuid:xyz</wsa:MessageID>
<wsa:RelatesTo>urn:uuid:xyz</wsa:RelatesTo>
<wsa:To>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:To>
</env:Header>
<soap:Body>
<soap:Fault>
<soap:Code>
<soap:Value>soap:Sender</soap:Value>
</soap:Code>
<soap:Reason>
<soap:Text xml:lang="en">The 'http://www.fakexyz.com/schemas/xyz:xyz' element is invalid - The value '123' is invalid according to its datatype 'String' - The Pattern constraint failed.
Please revise your data fields and make sure that message is correctly formatted.</soap:Text>
</soap:Reason>
<detail>
<faulttype>Schema</faulttype>
</detail>
</soap:Fault>
</soap:Body>
</soap:Envelope>