1

My WSO2 ESB Proxy Service receives the following request:

  <ReadFormRequest>
     <formID>1470</formID>
     <name>ConstructionForm</name>
  </ReadFormRequest>

I need to change ReadFormRequest to GetFormRequest and send it to the endpoint.

Here is my PayloadFactory code that is supposed to do the job:

<payloadFactory media-type="xml">
    <format>
        <GetFormRequest>
            $1
        </GetFormRequest>
    </format>
    <args>
        <arg evaluator="xml" expression="$body/ReadFormRequest/*"/>
    </args>
</payloadFactory>

The problem is that my XPath expression "$body/ReadFormRequest/*" returns values of the child elements instead of the actual elements. Thus I am getting the following result:

<GetFormRequest>
 1470ConstructionForm
</GetFormRequest>

According to XPath documentation this query should return the elements, but it seems like WSO2 retrieves element values instead.

Community
  • 1
  • 1
Alex Yakimovich
  • 259
  • 1
  • 4
  • 17

2 Answers2

1

I've spent a little bit of time trying to do this via xpath and I don't think it's possible. I either get the same as you, or

<GetFormRequest>
  <ReadFormRequest>
     <formID>1470</formID>
     <name>ConstructionForm</name>
  </ReadFormRequest>
</GetFormRequest>

Have you considered the XSLT mediator?

PLivesey
  • 196
  • 10
0

You can retrieve the entire xml element if you had a root element wrapping those.

ex:

<ReadFormRequest>
     <a>
        <formID>1470</formID>
        <name>ConstructionForm</name>
     </a>
</ReadFormRequest>

So you can either use XSLT mediator or use Payload Factory mediator by setting each child element through arguments.

 <payloadFactory>
    <format>
       <GetFormRequest xmlns="">
          <formID>$1</formID>
          <name>$2</name>
       </GetFormRequest>
    </format>
    <args>
       <arg expression="$body/ReadFormRequest/formID"/>
       <arg expression="$body/ReadFormRequest/name"/>
    </args>
 </payloadFactory>