We are consuming a JAX-WS
webservice through our web application running on TomEE Plus. It uses Apache CXF
implementation to interact with the webservice.
We wanted to log the requests and response XMLs that are sent and received as part of the webservice calls. There are numerous examples of that which helps us to log the complete request and response why we use Apache CXF
.
However, we have a situation where the complete request XML should not be logged since there are some sensitive information in that. We are modifying the SOAPEnvelope
to remove the sensitive information in the SOAPHandler
that takes care of logging them.
To do the printing, are there any libraries available that help us to print the complete XML data?
In IBM WebSphere, the JAX-WS implementation (not sure which one it was) could print the SOAPEnvelope
just by using the toString()
method. Where as the CXF returns null
while trying the toString()
of SOAPEnvelope
.
SOAPMessage message = messageContext.getMessage();
StringWriter sw = new StringWriter();
Transformer transformer = transformerFactory.newInstance().newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
transformer.transform(new DOMSource(message.getSOAPPart()), new StreamResult(sw));
logger.info(sw.toString());
Based on the answers from this post