I am able to successfully log request and response for a valid soap request(class generated through wsimport) but couldn't capture the xml content when an exception is thrown(when a node in the request is filled with invalid data). I could get the details of response but I want to capture only the xml part of the raw response. I have tried SOAPFaultException but that gives only the exception message rather than the full envelope with body of the response.How do I capture the exception with only the xml content in the exception/error thrown.
Note: I know I can parse the error(raw response) and pull the xml content but I am wondering if there is simple way/method to get the xml content like below. The content should look like(response captured from Soap UI tool)
<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>
After exploring more and trying, I found that we need to have a class which should implement SoapHandler interface, this gives you pretty much what was needed. I overrode handleFault method as below.
This gave me error info in formatted xml as well as with http headers.