For SOAP WebServices using spring-ws I used the lib:
<groupId>com.github.spartatech</groupId>
<artifactId>spring-ws-utils</artifactId>
To use this you should configure an interceptor that will mask the fields. Thje masking is done using XSLT. The way it works is (This example is using spring XML coinfiguration, but you can configure using Java-Based configuration as well):
Configure a spring-ws interceptor:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:sws="http://www.springframework.org/schema/web-services"
xsi:schemaLocation="
http://www.springframework.org/schema/web-services http://www.springframework.org/schema/web-services/web-services-2.0.xsd
>
...
<sws:interceptors>
<bean class="org.sparta.springwsutils.PayloadTransformedLoggingInterceptor">
<property name="xslt" value="classpath:xslt/maskInput.xslt"/>
</bean>
</sws:interceptors>
Then create the file: src/main/resources/xslt/maskInput.xslt
This file will contain all XML transformations to mask your fields:
Example:
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:typ="http://your/schema_name"
version="1.0">
<!-- copy all document -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<!-- mask cerditCard -->
<xsl:template match="typ:creditCard">
<xsl:copy>
<!-- Mask beginning of the Field -->
<xsl:value-of select="substring('*****************************************', 1, string-length(.)-4)"/>
<xsl:value-of select="substring(.,string-length(.)-3,string-length(.)+1)" />
</xsl:copy>
</xsl:template>
Then in your log configuration file make sure you disable MessageTracing log and enable PayloadTransformedLoggingInterceptor logging.
Example for logback:
<logger name="org.springframework.ws.client.MessageTracing" level="ERROR"/>
<logger name="org.sparta.springwsutils.PayloadTransformedLoggingInterceptor" level="INFO" />