Domanda

I am using wso2esb4.8.0 I wish to transform the message using wso2esb .Actaulle need to add Complex Element to Payload
How would i achive this. my Client request is

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

But my Adapter endpoint will allow the request in this format.If it is for one operation i may follow payload mediator to make my request But those are bumch of requests so Endpoint allowing request is

Just extract the Operation_Name and adding it as Complex Element But I am unable to do it I am trying in Proxy like this

Proxy is

<?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>

But its giving errors like the below my error log is

[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

With which mediator i can extract this request as per my desire way please if you know paste configuration or else provide any example

Thanks in advance

È stato utile?

Soluzione

You can use XSLT mediator or JavaScript

A sample proxy with javascript doing what you want :

<?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>

A sample using 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>
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top