谁能帮我屏蔽数据电源中的非XML输入。
我首先在 Datapower 日志存储中记录输入并将该输入用于掩码,我编写了一段适用于 XML 但不适用于非 XML 的代码,
附加我的输入非XML和代码以供参考。附加掩码file.xsl
有两个模板,一个用于非 XML,另一个用于 XML。XML 适用于数值,并且不会屏蔽字符。调用非 XML 模板,但不执行掩码。(我可以在系统日志中看到它正在被调用)
提供给屏蔽模板的控件由附加的不同log.xml
文件提供。
感谢快速响应。 谢谢 阿努吉
- 0200000298111 00000000ODS00000000000000834978953 00LIQ055003241NYYNNYNY 10000020130823Y00000000018765-000000000018765-000000000018765-010000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
输入非 xml。 PCTM-ODS-MTRF-WRSP-RSP PCTM-ODS-MTRF-WRSP-RSP
我的代码:在下面的掩码FldName是从log.xml文件中调用的。
<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>
- 日志.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>
也许您可以使用此技术说明将非 xml 包装为 XML,然后使用您的 XSLThttp://www-01.ibm.com/support/docview.wss?uid=swg21321379
相关部分:
将原始文本转换为伪 XML:
此示例将以下文本作为输入:
这里有一些文字这里还有一些等等
等等
等等,这里还有更多
创建步骤:
1.在将接收非 XML 请求的服务中创建转换操作。
2.选择"对非 XML 邮件使用此操作中指定的 XSLT"以指定这是二进制转换。
3.上传以下样式表作为处理控制文件。
4.单击完成,然后应用所有窗口。
<?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>
将以下 FFD 文件从文件管理器上传到 local://sample.ffd 目录中。
<File name="sampleFile"> <!-- capture all data into this tag --> <Field name="sampleTag" /> </File>
发送上面的示例输入将产生以下输出
<?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>