0

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

  1. Input Non-xml. PCTM-ODS-MTRF-WRSP-RSP PCTM-ODS-MTRF-WRSP-RSP 0200000298111 00000000ODS00000000000000834978953 00LIQ055003241NYYNYNNY 10000020130823Y000000000018765-000000000018765-000000000018765-010000100000000000000000000000-000000000000000-000000000000000-

  2. 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,'&#x22;&#x20;:&#x20;&#x22;','&#x22;:&#x22;')"/>
        </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,'&#x20;','')"/>
        </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. &lt; 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>
  1. 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]+&lt;)</maskPattern>
        </logpoint>
    </masking>
</logConfig>
zx485
  • 28,498
  • 28
  • 50
  • 59
  • If the input is not XML, you should consider not using XSLT at all. In XSLT 2.0, `unparsed-text()` can read in text without markup - but sometimes, it's easier to use another language like a shellscript, Perl, Python, PHP etc. – Mathias Müller Mar 08 '16 at 09:08
  • Hi Mathias, thanks for your suggetsion, but my requirement is to use eXSLT regexp function to mask the non xml data mentioned above. any help would be great. – AK.DataPower Mar 08 '16 at 09:20
  • @AK.DataPower If your input is not an XML file, then XSLT 1.0 cannot read it at all. Perhaps you may pass it to the stylesheet in another way (e.g. as a parameter). – michael.hor257k Mar 08 '16 at 10:19
  • One method to manipulate non-XML data is to wrap the document with XML tags to produce well-formed pseudo-XML usinf flat file descriptor and then the resulting document can be processed further using XSLT. check below link for in details http://www-01.ibm.com/support/docview.wss?uid=swg21321379 – sreevathsa a May 13 '16 at 07:01

1 Answers1

-1

Perhaps you could use this technote to wrap the non-xml in XML and then use your XSLT http://www-01.ibm.com/support/docview.wss?uid=swg21321379

Relevant portion:

Transforming raw text to pseudo-XML:

This example will take the following text as input:

some text here and here is some more and some more

and some more

and wait, some more here

Steps to Create:

1.Create a Transform action in the service that will be receiving non-XML requests.

2.Select "Use XSLT specified in this action on a non-XML message" to specify that this is a Binary Transform.

3.Upload the following style sheet as the Processing Control File.

4.Click Done, and Apply all windows.

    <?xml version="1.0" encoding="utf-8"?>
    <xsl:stylesheet
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:dp="http://www.datapower.com/extensions"
    version="1.0">

    <dp:input-mapping href="sample.ffd" type="ffd"/>

    <!-- This stylesheet copies the input to the output -->
    <xsl:output method="xml"/>

    <xsl:template match="/">
    <xsl:value-of select="sampleFile/sampleTag" disable-output-escaping="yes" />
    </xsl:template>
    </xsl:stylesheet>
  1. Upload the following FFD file into the local://sample.ffd directory from the File Manager.

    <File name="sampleFile">
    <!-- capture all data into this tag -->
    <Field name="sampleTag" />
    </File>
    

Sending the sample input above will result in the following output

    <?xml version="1.0" encoding="utf-8"?>
    <sampleFile>
    <sampleTag>
    some text here
    and here is some more
    and some more


    and some more

    and wait, some

    </sampleTag>
    </sampleFile> 
jimb
  • 11
  • 3