It's probably all over StackOverflow, but lately I had to log the XML content of SOAP messages for debugging. I did it this way:
publicvoid connect() { Service service = ... List<Handler> handlerList = Arrays.asList(new LoggerHandler()); service.setHandlerResolver(portInfo -> handlerList); }class LoggerHandler implements SOAPHandler<SOAPMessageContext> { @Overridepublicboolean handleMessage(SOAPMessageContext context) { SOAPMessage msg = context.getMessage();if (msg != null) { ByteArrayOutputStream baos = new ByteArrayOutputStream();try { msg.writeTo(baos); } catch (SOAPException | IOException e) { LOGGER.debug("Cannot parse message", e); } LOGGER.debug(baos.toString())); } else LOGGER.debug("null message");return true; } @Overridepublicboolean handleFault(SOAPMessageContext context) {return false; } @Overridepublicvoid close(MessageContext context) {} @Overridepublic Set<QName> getHeaders() {returnnew TreeSet<>(); } }