wso2_使用WSO2 ESB进行邮件内容过滤

wso2

wso2

内容过滤器
每个集成架构师或开发人员都应该熟悉Gregor Hohpe和Bobby Woolf所描述的企业集成模式(EIP) 。 模式之一是“内容消息过滤器” (不要与消息过滤器模式混淆)。 使用不同的MediatorWSO2中有多种方法可以实现此目的。 一种方法是使用XSLT介体,您可以在其中简单地使用XSLT进行过滤。 另一个(根据其名称不太明显)是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>

因此,通过这种配置,我们告诉中介者应将'document'元素的内容作为源,并将此内容放入传入的SOAP消息的正文中。

当您选择使用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>

使这项工作有效的XSLT代码(我在stackoverflow网站上找到了它):

<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

wso2

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值