ESB 代理 XML 请求在 SOAP 请求中的 CDATA 标记内

ESB Proxy XML Request inside CDATA tag in SOAP request

我是 Apache Synapse 的新手。我需要对 SOAP 服务进行基于内容的路由和代理。但是,实际请求是 SOAP 请求正文中 CDATA 标记内的 XML 文档。基于此文档的内容进行路由后,我需要使用 XQuery 中介来转换文档并调用代理服务。我无法更改此请求的 WSDL。是否可以对 CDATA 标签内的文档进行路由和转换?当我从 Synapse 中记录请求时,我看到 CDATA 中的 XML 已被转义。我看过一些描述保留 CDATA 的帖子,但我不确定在这两种情况下我能用它做什么。

请求如下所示。我需要根据 TypeOfRequest 属性路由消息:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:svc="http://integration.myservice.com">
   <soapenv:Header/>
   <soapenv:Body>
      <svc:Execute>
         <svc:myservice>
             <![CDATA[
             <?xml version="1.0" encoding="UTF-8"?>
            <myservice xmlns="http://integration.myservice.com">
                <Request TypeOfRequest="type1" RequestID="1" Echo="false">
                    <Message>
                        <Tag1510>
                            <TypeCode>10</TypeCode>
                            <SubTypeCode>00</SubTypeCode>
                        </Tag1510>
                        <Tag2000>
                            <Amount>
                                <Amount>1.00</Amount>
                            </Amount>
                        </Tag2000>
                    </Message>
                </Request>
            </myservice>
            ]]>
        </svc:myservice>
      </svc:Execute>
   </soapenv:Body>
</soapenv:Envelope> 

通常您可以使用xslt 来删除CDATA 块。在这种情况下,<?xml ..?> 会造成麻烦,但我想我设法使用 substring 解决了这个问题,但无法对此进行测试(编辑:但它根据下面的反馈工作) https://xsltfiddle.liberty-development.net/pPqsHUz/1

另一种方法是使用脚本中介在 javascript 中执行一些 stringmagic 以提取 myservice 和 /myservice

之间的部分

编辑:我在下面添加了 XSLT,以防 xsltfiddle link 停止工作:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="2.0" xmlns:svc="http://integration.myservice.com"
    xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">

  <!-- match all elements that are not 'svc:myservice' and ignore -->
  <xsl:template match="@* | node()">
        <xsl:apply-templates select="@* | node()"/>
  </xsl:template>

  <!-- match svc:myservice and copy the entire CDATA string after the ?xml line -->
  <xsl:template match="svc:myservice">
     <xsl:copy>
       <xsl:value-of select="substring-after(., '?>')" disable-output-escaping="yes"/>
     </xsl:copy>
  </xsl:template>
</xsl:stylesheet>