| <?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"><definitions xmlns="http://ws.apache.org/ns/synapse"> |
| |
| <sequence name="main"> |
| <in> |
| <property name="http.port" value="9000"/> |
| <property name="https.port" value="9002"/> |
| <rewrite> |
| <rule> |
| <action fragment="host" value="localhost"/> |
| <action fragment="path" type="prepend" value="/services"/> |
| </rule> |
| <rule> |
| <condition> |
| <equal type="url" source="protocol" value="http"/> |
| </condition> |
| <action fragment="port" xpath="get-property('http.port')"/> |
| </rule> |
| <rule> |
| <condition> |
| <equal type="url" source="protocol" value="https"/> |
| </condition> |
| <action fragment="port" xpath="get-property('https.port')"/> |
| </rule> |
| </rewrite> |
| <log level="full"/> |
| <send/> |
| </in> |
| <out> |
| <send/> |
| </out> |
| </sequence> |
| |
| </definitions></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> |