## Apache Synapse

## Sample 450: Introduction to the URL Rewrite Mediator

<definitions xmlns="http://ws.apache.org/ns/synapse"> <sequence name="main"> <in> <rewrite> <rule> <action type="replace" regex="soap" value="services" fragment="path"/> </rule> </rewrite> <send/> </in> <out> <send/> </out> </sequence> </definitions>

### Objective

Demonstrate the basic functions of the URL rewrite mediator

### Pre-requisites

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

### Executing the Client

URL rewrite mediator can be used to modify the 'To' header of a request based on one or more user defined URL rewrite rules. A rewrite rule could be a plain rewrite instruction or a conditional instruction. In this sample we use a plain, unconidtional rewrite rule which simply replaces the string 'soap' with 'services' in the 'To' header.

Invoke the sample client as follows to try this out.

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

Note that the address URL of the client request contains the context 'soap'. But in the Axis2 server all the services are deployed under a context named 'services' by default. Synapse will rewrite the To header of the request by replacing the 'soap' context with 'services. Hence the request will be delivered to the Axis2 server and the Axis2 client will receive a valid response.

Back to Catalog