blob: eba4a1c1a93286bfa4c6fdf91bb099cddbb45728 [file]
<?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 451</title>
</properties>
<body>
<section name="Sample 451: Conditional URL Rewriting">
<div class="xmlConf">&lt;definitions xmlns="http://ws.apache.org/ns/synapse"&gt;
&lt;sequence name="main"&gt;
&lt;in&gt;
&lt;rewrite&gt;
&lt;rule&gt;
&lt;condition&gt;
&lt;and&gt;
&lt;equal type="url" source="host" value="localhost"/&gt;
&lt;not&gt;
&lt;equal type="url" source="protocol" value="https"/&gt;
&lt;/not&gt;
&lt;/and&gt;
&lt;/condition&gt;
&lt;action fragment="protocol" value="https"/&gt;
&lt;action fragment="port" value="9002"/&gt;
&lt;/rule&gt;
&lt;/rewrite&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 evaluate conditions on
messages and perform rewrites based on the results
</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 451 (repository/conf/sample/synapse_sample_451.xml)
<div class="command">
Unix/Linux: sh synapse.sh -sample 451<br/>
Windows: synapse.bat -sample 451
</div>
</li>
</ul>
</p>
</subsection>
<subsection name="Executing the Client">
<p>
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.
</p>
<p>
If you invoke the client as follows, Synapse will rewrite the 'To' header and
forward the message to Axis2 over HTTPS.
</p>
<div class="command">ant stockquote -Daddurl=http://localhost:9000/services/SimpleStockQuoteService -Dtrpurl=http://localhost:8280/</div>
<p>
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.
</p>
</subsection>
</section>
<p><a href="../samples.html">Back to Catalog</a></p>
</body>
</document>