Raging Llama
Raging Llama

Reputation: 99

Preserve the original payload when calling a web service

I am struggling to figure out how to preserve a payload so that it is available after calling a web service within a sequence.

For example in the following sequence, after the “call” mediator fires the payload changes to what has been returned by the web service.

What I am looking to do is to enrich the original payload with the data that has been returned from the web service call.

All help is very much appreciated.

<log level="full"/>
<payloadFactory media-type="xml">
  <format>
    <Flight xmlns="">
      <location_id>$1</location_id>
      <FlightDistance/>
      <Aircraft>
        <AircraftAbbr/>
        <LandingDistance/>
        <TakeoffDistance/>
        <AircraftRange/>
        <AirframeHours/>
      </Aircraft>
      <Runways>
        <Airport/>
      </Runways>
    </Flight>
  </format>
  <args>
    <arg evaluator="xml" expression="get-property('OriginAirport')"/>
  </args>
</payloadFactory>
<log level="full">
  <property expression="get-property('OriginalPayload')" name="OriginalPayload"/>
</log>
<call blocking="true" description="">
  <endpoint key="GetRunways"/>
</call>
<foreach expression="//d:Entries/d:Entry" id="feid" xmlns:d="http://ws.wso2.org/dataservice">
  <sequence>
    <log description="" level="full">
      <property name="marker" value="marker"/>
    </log>
    <property expression="$body/Entry/runway_length" name="RunwayLength" scope="default" type="STRING"/>
    <enrich>
      <source clone="true" property="RunwayLength" type="property"/>
      <target action="child" property="RunwayLength" type="property"/>
    </enrich>
    <log>
      <property expression="get-property('RunwayLength')" name="PropertyValue"/>
    </log>
  </sequence>
</foreach>

Upvotes: 1

Views: 1029

Answers (2)

Julien GRESSE
Julien GRESSE

Reputation: 354

To complete @Jenananthan answer:

  1. Store original payload in a property
  2. Call the webservice
  3. Restore the original payload to body:

<enrich>
    <source clone="false" type="property" property="ORIGINAL_PAYLOAD"/>
    <target action="replace" type="body"/>
</enrich>

Upvotes: 1

Jenananthan
Jenananthan

Reputation: 1401

use enrich mediator and store the payload in to property

<enrich>
    <source type="body"/>
    <target type="property" property="REQUEST_PAYLOAD"/>
 </enrich>

https://docs.wso2.com/display/ESB481/Enrich+Mediator

Upvotes: 3

Related Questions