Sample 451: Conditional URL Rewriting

<definitions xmlns=""> <sequence name="main"> <in> <rewrite> <rule> <condition> <and> <equal type="url" source="host" value="localhost"/> <not> <equal type="url" source="protocol" value="https"/> </not> </and> </condition> <action fragment="protocol" value="https"/> <action fragment="port" value="9002"/> </rule> </rewrite> <send/> </in> <out> <send/> </out> </sequence> </definitions>


Demonstrate the ability of the URL rewrite mediator to evaluate conditions on messages and perform rewrites based on the results


  • Deploy the SimpleStockQuoteService in the sample Axis2 server and start Axis2
  • Start Synapse using the configuration numbered 451 (repository/conf/sample/synapse_sample_451.xml)
    Unix/Linux: sh -sample 451
    Windows: synapse.bat -sample 451

Executing the Client

Invoke the Axis2 client and send some requests to Synapse with different address URL values. If the address URL value contains 'localhost' as the hostname and 'https' as the protocol prefix, Synapse will route the message as it is. But if the hostname is 'localhost' and the protocol is not https, Synapse will rewrite the URL by setting 'https' as the protocol. The port number will also be set to the HTTPS port of the Axis2 server.

If you invoke the client as follows, Synapse will rewrite the 'To' header and forward the message to Axis2 over HTTPS.

ant stockquote -Daddurl=http://localhost:9000/services/SimpleStockQuoteService -Dtrpurl=http://localhost:8280/

The condition evaluation feature is provided by the Synapse evaluator framework. Currently one can evaluate expressions on URL values, query parameters, transport headers, properties and SOAP envelope content using this framework. Hence URL rewriting can be done based on any of these aspects.

Back to Catalog