2
votes

I need to set soap envelope to the xml body using enrich mediator. I created XML body inside the payload factory mediator. I get that body to property value. property

<property expression="$body/*[1]" name="INPUT_MESSAGE" scope="default" type="OM" xmlns:ns="http://org.apache.synapse/xsd"/>

Body is like this

<bas:setMOAttributes xmlns:bas="http://www.3gpp.org/ftp/Specs/archive/32_series/32607/schema/32607-700/BasicCMIRPData">
<queryXpathExp>
    <soap:baseObjectInstance xmlns:soap="http:   //Here is only few lines

Now I need to add soap envelop.I used enrich mediator after INPUT_MESSAGE property

<enrich>
        <source clone="true" type="inline">
            <soapenv:Envelope xmlns:bas="http://www.3gpp.org/ftp/Specs/archive/32_series/32607/schema/32607-700/BasicCMIRPData" xmlns:soap="http://www.alcatel-lucent.com/soap_cm" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
                <soapenv:Header/>
                <soapenv:Body>
                    <list xmlns=""/>
                </soapenv:Body>
            </soapenv:Envelope>
        </source>
        <target type="envelope"/>
    </enrich>
    <enrich>
        <source clone="true" property="INPUT_MESSAGE" type="property"/>
        <target type="body"/>
    </enrich>

But I couldn't get xml body with soap envelop. What is the way to do this

3

3 Answers

3
votes

Try this it will work

Request with body like this

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://services.samples">
  <soapenv:Header/>
    <soapenv:Body>
      <bas:setMOAttributes xmlns:bas="http://www.3gpp.org/ftp/Specs/archive/32_series/32607/schema/32607-700/BasicCMIRPData">
        <queryXpathExp>
          <soap:baseObjectInstance xmlns:soap="http://www.alcatel-lucent.com/soap_cm">
            hello
          </soap:baseObjectInstance>
        </queryXpathExp>
     </bas:setMOAttributes>
   </soapenv:Body>
</soapenv:Envelope>

Proxy with Enrich mediator like this

<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
       name="test2"
       startOnLoad="true"
       statistics="disable"
       trace="disable"
       transports="http,https">
    <target>
      <inSequence>
         <property expression="$body/*[1]"
                   name="INPUT_MESSAGE"
                   scope="default"
                   type="STRING"/>
         <enrich>
            <source clone="true" type="inline">
               <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
                  <soapenv:Header/>
                  <soapenv:Body>
                     <list xmlns=""/>
                  </soapenv:Body>
               </soapenv:Envelope>
            </source>
            <target type="envelope"/>
         </enrich>
         <enrich>
            <source clone="true" property="INPUT_MESSAGE" type="property"/>
            <target type="body"/>
         </enrich>
         <respond/>
      </inSequence>
   </target>
   <description/>
</proxy>

Output like this

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Header/>
   <soapenv:Body>
      <list><![CDATA[<bas:setMOAttributes xmlns:bas="http://www.3gpp.org/ftp/Specs/archive/32_series/32607/schema/32607-700/BasicCMIRPData">
       <queryXpathExp>
         <soap:baseObjectInstance xmlns:soap="http://www.alcatel-lucent.com/soap_cm">
          hello
         </soap:baseObjectInstance>
       </queryXpathExp>
     </bas:setMOAttributes>]]></list>
   </soapenv:Body>
</soapenv:Envelope>
1
votes

What about using payload factory for this ?

<payloadFactory description="Add Soap Envelop" media-type="xml">
    <format>
        <soapenv:Envelope xmlns:bas="http://www.3gpp.org/ftp/Specs/archive/32_series/32607/schema/32607-700/BasicCMIRPData" xmlns:soap="http://www.alcatel-lucent.com/soap_cm" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
            <soapenv:Header/>
            <soapenv:Body>
                $1
            </soapenv:Body>
        </soapenv:Envelope>
    </format>
    <args>
        <arg evaluator="xml" expression="get-property('INPUT_MESSAGE')"/>
    </args>
</payloadFactory>

Look at example 5 here in payload factory documentation

0
votes

Using payload factory will give you a clean solution. If you want to use enrich mediator to set the envelope, you need to save it in a property first and then use property in enrich mediator. Same as you have done for saving the body in a property first and then using it in a enrich mediator. Hope that helps.