Search code examples
esbwso2-esb

How to convert property value to tag name of message in WSOESB proxy service


I have very simple request to proxy

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
    <soapenv:Body>
         <operation>GetAllCustomers</operation>     
    </soapenv:Body>
</soapenv:Envelope>

I have to convert it to

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
      <soapenv:Body>
            <sr:GetAllCustomers />
      </soapenv:Body>
</soapenv:Envelope>

It possible to implement logic using one of mediators in list xslt, payload or script and I have solved problem using payload mediator, but I am still curious, if there is a way to do it using enrich mediator?

There are my thoughts, I have to extract name of operation and set property with value of operation name, and then inject it into message as the element. Actually i have or replace operation tag with new one or delete operation tag from original message and append child element with name of property value of operation name.

This way i try to set property type to "OM".

<property name="operation" expresstion="//operation" type="OM" />
<enrich>
    <source clone="true" xpath="get-property('operation')" />
   <target type="body" />
</enrich> 

It cause parsing error since type="OM" can be assigned only to property with tag. For example

 <property name="operation" expression="//operation" type="OM">
     <result />
 </property>

Or i can try to inject usual property using enrich mediator and there are several ways of syntax to implement it

<enrich>
    <source clone="true" type="property" property="operation" />
    <target type="body" action="child" />
</enrich>

<enrich>
    <source clone="true" xpath="$ctx:operation" />
    <target type="body" action="child" />
</enrich>

In this case i get error "Invalid object type".

Any suggestions appreciated.


Solution

  • IMO if you resolved the problem using payloadFatory you are done. and that is the way to go. you can use script mediator too. but payloadFactory better than that. payload factory is content aware mediator. is it will help to build the message too.