【问题标题】:How would i transform the message Dynamically In WSO2ESB我将如何在 WSO2ESB 中动态转换消息
【发布时间】:2014-05-15 05:39:47
【问题描述】:

我正在使用 wso2esb4.8.0 我希望使用 wso2esb 转换消息。Actaulle 需要将 Complex Element 添加到 Payload
我将如何做到这一点。 我的客户要求是

<?xml version="1.0" encoding="UTF-8"?>

但是我的适配器端点将允许这种格式的请求。如果是针对一个操作,我可能会跟随有效负载调解器来发出我的请求但这些都是一堆请求 所以端点允许请求是

只需提取 Operation_Name 并将其添加为复杂元素但我无法做到这一点我在这样的代理中尝试

代理是

<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
       name="SamplePOC7"
       transports="https,http"
       statistics="disable"
       trace="disable"
       startOnLoad="true">
   <target>
      <inSequence>
         <property xmlns:open="http://www.openuri.org/"
                   xmlns:ns="http://org.apache.synapse/xsd"
                   xmlns:env="http://eai.mmn.mm/Envelope"
                   xmlns:poin="http://eai.mm.mm/gg"
                   name="Operation_Name"
                   expression="//poin:Operation_Name/text()"
                   scope="default"
                   type="STRING"/>
         <property xmlns:open="http://www.openuri.org/"
                   xmlns:ns="http://org.apache.synapse/xsd"
                   xmlns:env="http://eai.mmn.xxxx/Envelope"
                   name="AddElement"
                   expression="concat('open:',get-property('Operation_Name'))"
                   scope="default"
                   type="STRING"/>
         <enrich>
            <source xmlns:env="http://eai.mmn.mm/Envelope"
                    clone="true"
                    xpath="//env:Payload/*"/>
            <target xmlns:poin="http://eai.mm.XXX/gg"
                    xpath="concat('open:',//poin:Operation_Name/text())"/>
         </enrich>
         <log level="full">
            <property name="Message" expression="get-property('AddElement')"/>
         </log>
      </inSequence>
      <outSequence/>
   </target>
   <description/>
</proxy>

但它给出的错误如下我的错误日志是

[2014-05-15 10:53:48,167]  INFO - ProxyService Successfully created the Axis2 se
rvice for Proxy service : SamplePOC7
[2014-05-15 10:53:53,089] ERROR - EnrichMediator Invalid Target object to be enr
ich.
[2014-05-15 10:54:19,160]  INFO - ProxyService Building Axis service for Proxy s

如果您知道粘贴配置或提供任何示例,请按照我的意愿使用哪个调解器提取此请求

提前致谢

【问题讨论】:

    标签: xslt xpath wso2 xquery wso2esb


    【解决方案1】:

    您可以使用 XSLT 中介或 JavaScript

    使用 javascript 做你想做的事的示例代理:

    <?xml version="1.0" encoding="UTF-8"?>
    <proxy xmlns="http://ws.apache.org/ns/synapse"
           name="TestSOF"
           transports="http"
           startOnLoad="true"
           trace="disable">
       <description/>
       <target>
          <inSequence>
             <property name="FORCE_SC_ACCEPTED" value="true" scope="axis2"/>
             <property xmlns:open="http://www.openuri.org/"
                       xmlns:ns="http://org.apache.synapse/xsd"
                       xmlns:poin="http://eai.mtn.iran/PointOfSales"
                       name="Operation_Name"
                       expression="//poin:Operation_Name/text()"
                       scope="default"
                       type="STRING"/>
             <property xmlns:ns="http://org.apache.synapse/xsd"
                       xmlns:poin="http://eai.mtn.iran/PointOfSales"
                       name="PointOfSales"
                       expression="//poin:PointOfSales"
                       scope="default"
                       type="STRING"/>
             <script language="js"><![CDATA[
                    mc.setPayloadXML(<open:{mc.getProperty("Operation_Name")} xmlns:open="http://www.openuri.org/">
                                       {new XML(mc.getProperty("PointOfSales"))}
                                     </open:{mc.getProperty("Operation_Name")}>);
          ]]></script>
             <log level="full"/>
          </inSequence>
       </target>
    </proxy>
    

    使用 XSLT 的示例:

    <?xml version="1.0" encoding="UTF-8"?>
    <localEntry xmlns="http://ws.apache.org/ns/synapse" key="SOFXSL">
        <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                               xmlns:xs="http://www.w3.org/2001/XMLSchema"
                               xmlns:fo="http://www.w3.org/1999/XSL/Format"
                               xmlns:fn="http://www.w3.org/2005/xpath-functions"
                               xmlns:open="http://openuri.org/"
                               xmlns:env="http://eai.mtnn.iran/Envelope"
                               xmlns:poin="http://eai.mtn.iran/PointOfSales"
                               version="2.0">
            <xsl:output method="xml" encoding="utf-8" indent="yes" omit-xml-declaration="no"/>
            <xsl:param name="operationname"/>
            <xsl:template match="/">
                <xsl:element name="open:{$operationname}">
                    <xsl:apply-templates select="//poin:PointOfSales"/>
                </xsl:element>
            </xsl:template>
            <xsl:template match="@*|*|comment()">
                <xsl:copy>
                    <xsl:apply-templates select="@*|*|text()|comment()|processing-instruction()"/>
                </xsl:copy>
            </xsl:template>
        </xsl:stylesheet>
       <description/>
    </localEntry>
    
    
    <?xml version="1.0" encoding="UTF-8"?>
    <proxy xmlns="http://ws.apache.org/ns/synapse"
           name="TestSOF"
           transports="http"
           startOnLoad="true"
           trace="disable">
       <description/>
       <target>
          <inSequence>
             <property name="FORCE_SC_ACCEPTED" value="true" scope="axis2"/>
             <property xmlns:open="http://www.openuri.org/"
                       xmlns:ns="http://org.apache.synapse/xsd"
                       xmlns:poin="http://eai.mtn.iran/PointOfSales"
                       name="Operation_Name"
                       expression="//poin:Operation_Name/text()"
                       scope="default"
                       type="STRING"/>
             <xslt key="SOFXSL">
                <property name="operationname" expression="get-property('Operation_Name')"/>
             </xslt>
             <log level="full"/>
          </inSequence>
       </target>
    </proxy>
    

    【讨论】:

    • 我们如何在 XSLT 中做到这一点我正在尝试这样 w3.org/1999/XSL/Transform" xmlns:open="openuri.org" xmlns:env="eai.mtnn.iran/Envelope " xmlns:poin="eai.mtn.iran/PointOfSales" version="1.0"> 并通过2 个属性的
    • 但又报错
    • 我在答案中添加了一个带有 XSLT 的示例
    猜你喜欢
    • 2013-05-10
    • 2011-07-27
    • 2018-09-05
    • 2013-08-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-17
    • 1970-01-01
    相关资源
    最近更新 更多