Can anyone please help me on masking of non-XML input in Datapower.
I am logging the input first in Datapower log store and taking that input to mask, I have written a piece of code which works for XML but not for non-XML,
attaching my input non-XML and code for the reference.
Attached masking file.xsl
has two templates, one for non-XML and another for XML. XML is working fine for numeric values and not masking the characters.
Non-XML template is called but not doing masking.(I can see in system logs it is being called)
The control given to masking template is given by a different log.xml
file attached.
Quick response is appreciated. Thanks, Anuj
Input Non-xml. PCTM-ODS-MTRF-WRSP-RSP PCTM-ODS-MTRF-WRSP-RSP 0200000298111 00000000ODS00000000000000834978953 00LIQ055003241NYYNYNNY 10000020130823Y000000000018765-000000000018765-000000000018765-010000100000000000000000000000-000000000000000-000000000000000-
My Code: In the below maskFldName is called from the log.xml file.
<xsl:template name="NONXMLmaskingTemplate">
<xsl:param name="maskFldName"/>
<xsl:param name="Input"/>
<xsl:variable name="maskchars" select="'******************************'"/>
<xsl:message>maskFldName:<xsl:copy-of select="$maskFldName"/>
</xsl:message>
<xsl:variable name="logInput">
<!--<dp:serialize select="$Input" omit-xml-decl="yes"/>-->
<xsl:copy-of select="translate($Input,'" : "','":"')"/>
</xsl:variable>
<xsl:message>MaskInputMessage:<xsl:copy-of select="$logInput"/>
</xsl:message>
<dp:set-local-variable name="'var://local/input'" value="$logInput"/>
<xsl:message>!!!!
<xsl:copy-of select="translate($Input,' ','')"/>
</xsl:message>
<xsl:for-each select="$maskFldName">
<xsl:variable name="startPosition" select="./@startPosition"/>
<xsl:variable name="noOfChars" select="./@numOfChars"/>
<xsl:message>startPosition:<xsl:value-of select="$startPosition"/>
</xsl:message>
<xsl:message>noOfChars:<xsl:value-of select="$noOfChars"/>
</xsl:message>
<xsl:variable name="maskString" select="substring($maskchars,1,$noOfChars)"/>
<xsl:message>Matches:<xsl:copy-of select="regexp:match($logInput,.,'g')"/>
</xsl:message>
<xsl:message>InputMessage1:<xsl:copy-of select="$Input"/>
</xsl:message>
<xsl:for-each select="regexp:match($logInput,.,'g')">
<xsl:message>InputMessage:<xsl:copy-of select="$logInput"/>
</xsl:message>
<xsl:message>ValueX:<xsl:copy-of select="."/>
</xsl:message>
<xsl:variable name="strToReplace" select="substring(.,$startPosition,$noOfChars)"/>
<xsl:variable name="strToReplace2" select="regexp:replace(.,$strToReplace,'g',$maskString)"/>
<xsl:message>strToReplace:<xsl:copy-of select="$strToReplace"/>
</xsl:message>
<xsl:message>strToReplace2:<xsl:value-of select="$strToReplace2"/>
</xsl:message>
<dp:set-local-variable name="'var://local/input'" value="regexp:replace(dp:local-variable('var://local/input'),.,'g',$strToReplace2)"/>
</xsl:for-each>
</xsl:for-each>
<xsl:copy-of select="dp:local-variable('var://local/input')"/>
<!--
If message to be proper xml i.e. < needs to be output as < then the following code to be used
<xsl:copy-of select="dp:transform('detailLog.xsl',dp:parse(dp:local-variable('var://local/input')))"/>
<xsl:message>MaskOutputMessage:<xsl:copy-of select="dp:local-variable('var://local/input')"/> </xsl:message>
-->
</xsl:template>
</xsl:stylesheet>
- log.xml
<?xml version="1.0" encoding="UTF-8"?>
<logConfig>
<!-- ALL/NONE/FRONT/BACK -->
<log-enabled value="ALL"/>
<!-- Y/N -->
<detail-log-enabled value="Y"/>
<!-- Y/N -->
<slim-log-enabled value="N"/>
<masking isMaskRequire="Y">
<logpoint id="service_req_entry">
<contentType>NONXML</contentType>
<maskPattern attribute="detail" startPosition="50" numOfChars="4">(PCTM[\w])</maskPattern>
</logpoint>
<logpoint id="SCRq-out">
<contentType>XML</contentType>
<maskPattern attribute="detail" startPosition="11" numOfChars="4">(Severity>[\w]+<)</maskPattern>
</logpoint>
</masking>
</logConfig>