blob: 9d830a2cb2902cc5bb4b2294ddff14cad5887c9e [file] [log] [blame]
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!--
~ Licensed to the Apache Software Foundation (ASF) under one
~ or more contributor license agreements. See the NOTICE file
~ distributed with this work for additional information
~ regarding copyright ownership. The ASF licenses this file
~ to you under the Apache License, Version 2.0 (the
~ "License"); you may not use this file except in compliance
~ with the License. You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing,
~ software distributed under the License is distributed on an
~ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
~ KIND, either express or implied. See the License for the
~ specific language governing permissions and limitations
~ under the License.
-->
<document>
<properties>
<title>Apache Synapse - Sample 452</title>
</properties>
<body>
<section name="Sample 452: Conditional URL Rewriting with Multiple Rules">
<div class="xmlConf">&lt;definitions xmlns="http://ws.apache.org/ns/synapse"&gt;
&lt;sequence name="main"&gt;
&lt;in&gt;
&lt;property name="http.port" value="9000"/&gt;
&lt;property name="https.port" value="9002"/&gt;
&lt;rewrite&gt;
&lt;rule&gt;
&lt;action fragment="host" value="localhost"/&gt;
&lt;action fragment="path" type="prepend" value="/services"/&gt;
&lt;/rule&gt;
&lt;rule&gt;
&lt;condition&gt;
&lt;equal type="url" source="protocol" value="http"/&gt;
&lt;/condition&gt;
&lt;action fragment="port" xpath="get-property('http.port')"/&gt;
&lt;/rule&gt;
&lt;rule&gt;
&lt;condition&gt;
&lt;equal type="url" source="protocol" value="https"/&gt;
&lt;/condition&gt;
&lt;action fragment="port" xpath="get-property('https.port')"/&gt;
&lt;/rule&gt;
&lt;/rewrite&gt;
&lt;log level="full"/&gt;
&lt;send/&gt;
&lt;/in&gt;
&lt;out&gt;
&lt;send/&gt;
&lt;/out&gt;
&lt;/sequence&gt;
&lt;/definitions&gt;</div>
<subsection name="Objective">
<p>
Demonstrate the ability of the URL rewrite mediator to perform rewrites based
on multiple rules
</p>
</subsection>
<subsection name="Pre-requisites">
<p>
<ul>
<li>
Deploy the SimpleStockQuoteService in the sample Axis2 server and start Axis2
</li>
<li>
Start Synapse using the configuration numbered 452 (repository/conf/sample/synapse_sample_452.xml)
<div class="command">
Unix/Linux: sh synapse.sh -sample 452<br/>
Windows: synapse.bat -sample 452
</div>
</li>
</ul>
</p>
</subsection>
<subsection name="Executing the Client">
<p>
One may specify multiple rewrite rules for a URL rewrite mediator instance. In
that case Synapse will execute all the rules on each message, in the order they
appear. This particular sample lists 3 rewrite rules. To try it out, invoke the
client as follows.
</p>
<div class="command">ant stockquote -Dtrpurl=http://localhost:8280 -Daddurl=http://test.com/SimpleStockQuoteService</div>
<p>
The provided address URL does not contain a port number and the context. The URL
rewrite mediator will replace the hostname (test.com) with 'localhost' and add the
context '/services' to the path. Then it will add the appropriate port number to
the URL by looking at the protocol prefix. Ultimately the service request will be
routed the sample Axis2 server and the client will receive a valid response.
</p>
<p>
Another important aspect shown by this sample is the ability of the URL rewirte
mediator to obtain the necessary values by executing XPath expressions. The port
numbers are calculated by executing an XPath on the messages.
</p>
</subsection>
</section>
<p><a href="../samples.html">Back to Catalog</a></p>
</body>
</document>