Sample 355: Using Python Scripts for Mediation
<definitions xmlns="http://ws.apache.org/ns/synapse">
<registry provider="org.apache.synapse.registry.url.SimpleURLRegistry">
<!-- the root property of the simple URL registry helps resolve a resource URL as root + key -->
<parameter name="root">file:repository/conf/sample/resources/</parameter>
<!-- all resources loaded from the URL registry would be cached for this number of milli seconds -->
<parameter name="cachableDuration">15000</parameter>
</registry>
<localEntry key="stockquoteScript"
src="file:repository/conf/sample/resources/script/stockquoteTransformRequest.py"/>
<sequence name="main">
<in>
<!-- transform the custom quote request into a standard quote request expected by the service -->
<script language="py" key="stockquoteScript" function="transformRequest"/>
<send>
<endpoint>
<address uri="http://localhost:9000/services/SimpleStockQuoteService"/>
</endpoint>
</send>
</in>
<out>
<!-- transform the standard response back into the custom format the client expects -->
<script language="py" key="script/stockquoteTransformResponse.py"
function="transformResponse"/>
<send/>
</out>
</sequence>
</definitions>
Objective
Shows how to embed Python scripts in the Synapse configuration itself.
Executing the Client
Run the sample client as follows.
ant stockquote -Daddurl=http://localhost:9000/services/SimpleStockQuoteService -Dtrpurl=http://localhost:8280/ -Dmode=customquote
The Python scripts will transform the requests and responses.
Back to Catalog