使用WSO2 ESB进行邮件内容过滤
每個集成架構(gòu)師或開發(fā)人員都應(yīng)該熟悉Gregor Hohpe和Bobby Woolf所描述的企業(yè)集成模式(EIP) 。 模式之一是“內(nèi)容消息過濾器” (不要與消息過濾器模式混淆)。
使用不同的Mediator在WSO2中有多種方法可以實(shí)現(xiàn)此目的。 一種方法是使用XSLT介體 ,您可以在其中簡單地使用XSLT進(jìn)行過濾。 另一個(根據(jù)名稱不那么明顯)是Enrich Mediator 。
這是一個如何使用Enrich Mediator的示例。 想象一下原始消息是:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tmp="http://www.pascalalma.net/order"><soapenv:Header/><soapenv:Body><tmp:message><tmp:document><tmp:order><tmp:id>123</tmp:id></tmp:order></tmp:document></tmp:message></soapenv:Body> </soapenv:Envelope>我們真正想要的是一條僅以“ order”元素為有效載荷的Soap消息。 我們可以使用具有以下配置的Enrich介體來完成此操作:
<enrich xmlns:tmp="http://www.pascalalma.net/order"><source clone="false" type="custom" xpath="//tmp:document/*" /><target action="replace" type="body" /> </enrich>因此,通過這種配置,我們告訴中介者它應(yīng)該將'document'元素的內(nèi)容作為源,并將此內(nèi)容放入傳入的SOAP消息的正文中。
當(dāng)您選擇使用XSLT介體時,這里有一個示例XSLT,可用于從XML文檔中刪除某些元素。 您可以在以下XML消息上使用它:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tmp="http://www.pascalalma.net/order"><soapenv:Header/><soapenv:Body><tmp:message><tmp:document><tmp:order><tmp:id>123</tmp:id><tmp:type>backorder</tmp:type><tmp:status>open</tmp:status><tmp:description>open</tmp:description></tmp:order></tmp:document></tmp:message></soapenv:Body> </soapenv:Envelope>如果我們想要這個相同的XML文檔,但是沒有元素'tmp:type'和'tmp:description',我們可以這樣定義XSLT介體:
<xslt key="xslt/remove-elements-v1.xslt" description="remove unwanted elements"><property name="removeElementsNamed" value="type,description" /> </xslt>使這項(xiàng)工作有效的XSLT代碼(我在stackoverflow網(wǎng)站上找到了它):
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:output omit-xml-declaration="no" indent="yes" encoding="UTF-8"/><xsl:strip-space elements="*"/><xsl:param name="removeElementsNamed" /><xsl:template match="node()|@*"><xsl:copy><xsl:apply-templates select="node()|@*"/></xsl:copy></xsl:template><xsl:template match="*[local-name()=tokenize($removeElementsNamed,'[\|, \t]')]"/> </xsl:stylesheet>請注意,此XSLT不考慮名稱空間,只是刪除所有本地名稱與提供的名稱匹配的元素!
翻譯自: https://www.javacodegeeks.com/2015/03/message-content-filtering-with-wso2-esb.html
總結(jié)
以上是生活随笔為你收集整理的使用WSO2 ESB进行邮件内容过滤的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 关于单元测试脚手架的几点思考
- 下一篇: 编写干净的测试–天堂中的麻烦