You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@synapse.apache.org by hi...@apache.org on 2010/09/13 10:47:16 UTC
svn commit: r996452 - in /synapse/trunk/java:
repository/conf/sample/synapse_sample_450.xml
repository/conf/sample/synapse_sample_451.xml
repository/conf/sample/synapse_sample_452.xml
src/site/xdoc/Synapse_Samples.xml
Author: hiranya
Date: Mon Sep 13 08:47:16 2010
New Revision: 996452
URL: http://svn.apache.org/viewvc?rev=996452&view=rev
Log:
Documentation for the new URL rewrite mediator (SYNAPSE-681). Adding 3 new samples. Will add more samples in the near future.
Added:
synapse/trunk/java/repository/conf/sample/synapse_sample_450.xml
synapse/trunk/java/repository/conf/sample/synapse_sample_451.xml
synapse/trunk/java/repository/conf/sample/synapse_sample_452.xml
Modified:
synapse/trunk/java/src/site/xdoc/Synapse_Samples.xml
Added: synapse/trunk/java/repository/conf/sample/synapse_sample_450.xml
URL: http://svn.apache.org/viewvc/synapse/trunk/java/repository/conf/sample/synapse_sample_450.xml?rev=996452&view=auto
==============================================================================
--- synapse/trunk/java/repository/conf/sample/synapse_sample_450.xml (added)
+++ synapse/trunk/java/repository/conf/sample/synapse_sample_450.xml Mon Sep 13 08:47:16 2010
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+
+<!-- Replacing the context (path) of the URL -->
+<definitions xmlns="http://synapse.apache.org/ns/2010/04/configuration">
+
+ <sequence name="main">
+ <in>
+ <rewrite>
+ <rule>
+ <action type="replace" regex="soap" value="services" fragment="path"/>
+ </rule>
+ </rewrite>
+ <send/>
+ </in>
+ <out>
+ <send/>
+ </out>
+ </sequence>
+
+</definitions>
Added: synapse/trunk/java/repository/conf/sample/synapse_sample_451.xml
URL: http://svn.apache.org/viewvc/synapse/trunk/java/repository/conf/sample/synapse_sample_451.xml?rev=996452&view=auto
==============================================================================
--- synapse/trunk/java/repository/conf/sample/synapse_sample_451.xml (added)
+++ synapse/trunk/java/repository/conf/sample/synapse_sample_451.xml Mon Sep 13 08:47:16 2010
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+
+<!-- Changing the protocol and the port of the URL -->
+<definitions xmlns="http://synapse.apache.org/ns/2010/04/configuration">
+
+ <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>
Added: synapse/trunk/java/repository/conf/sample/synapse_sample_452.xml
URL: http://svn.apache.org/viewvc/synapse/trunk/java/repository/conf/sample/synapse_sample_452.xml?rev=996452&view=auto
==============================================================================
--- synapse/trunk/java/repository/conf/sample/synapse_sample_452.xml (added)
+++ synapse/trunk/java/repository/conf/sample/synapse_sample_452.xml Mon Sep 13 08:47:16 2010
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+
+<!-- URL rewriting with multiple rules -->
+<definitions xmlns="http://synapse.apache.org/ns/2010/04/configuration">
+
+ <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>
Modified: synapse/trunk/java/src/site/xdoc/Synapse_Samples.xml
URL: http://svn.apache.org/viewvc/synapse/trunk/java/src/site/xdoc/Synapse_Samples.xml?rev=996452&r1=996451&r2=996452&view=diff
==============================================================================
--- synapse/trunk/java/src/site/xdoc/Synapse_Samples.xml (original)
+++ synapse/trunk/java/src/site/xdoc/Synapse_Samples.xml Mon Sep 13 08:47:16 2010
@@ -302,6 +302,12 @@
<a href="#Sample430">Sample 430: Simple Callout Mediator for synchronize web service invocation</a></li>
<li>
<a href="#Sample440">Sample 440: Exposing a SOAP service over JSON</a></li>
+<li>
+<a href="#Sample450">Sample 450: Introduction to the URL Rewrite mediator</a></li>
+<li>
+<a href="#Sample451">Sample 451: Conditional URL rewriting</a></li>
+<li>
+<a href="#Sample452">Sample 452: Conditional URL rewriting with multiple rules</a></li>
</ul></li></ul></li>
<li>
<a href="#Task">Introduction to Eventing</a>
@@ -4457,6 +4463,132 @@ will be converted into a JSON message an
<pre>{"getQuote":{"request":{"symbol":"IBM"}}}</pre>
<pre>{"getQuoteResponse":{"return":{"change":3.853593376681722,"earnings":12.802850763714854,"high":67.92488310190126,"last":66.14619264746406,"lastTradeTimestamp":"Mon Aug 23 16:48:40 IST 2010","low":-66.04000424423522,"marketCap":-9334516.42324327,"name":"IBM Company","open":-64.61950137150009,"peRatio":-19.78600441437058,"percentageChange":5.411779328273005,"prevClose":71.2075112994578,"symbol":"IBM","volume":16842}}}</pre>
</div>
+
+<h2>
+ <a name="Sample450" id="Sample450">Sample 450: Introduction to the URL Rewrite Mediator</a>
+</h2>
+<pre xml:space="preserve"><definitions xmlns="http://synapse.apache.org/ns/2010/04/configuration">
+ <sequence xmlns="http://synapse.apache.org/ns/2010/04/configuration" name="main">
+ <in>
+ <rewrite>
+ <rule>
+ <action type="replace" regex="soap" value="services" fragment="path"/>
+ </rule>
+ </rewrite>
+ <send/>
+ </in>
+ <out>
+ <send/>
+ </out>
+ </sequence>
+</definitions></pre>
+<div>
+<p>
+<strong>Objective:</strong> Demonstrate the basic functions of the URL rewrite mediator</p>
+<p>
+<strong>Prerequisites:</strong> Deploy the SimpleStockQuoteService in sample Axis2 server and start it on port 9000.</p>
+<p>Start Synapse with the sample configuration 450 (i.e. synapse -sample 450). </p>
+<p>Invoke the Axis2 client as follows. </p>
+<pre xml:space="preserve">ant stockquote -Dtrpurl=http://localhost:8280 -Daddurl=http://localhost:9000/soap/SimpleStockQuoteService</pre>
+<p>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.</p>
+</div>
+<h2>
+ <a name="Sample451" id="Sample451">Sample 451: Conditional URL Rewriting</a>
+</h2>
+<pre xml:space="preserve"><definitions xmlns="http://synapse.apache.org/ns/2010/04/configuration">
+ <sequence xmlns="http://synapse.apache.org/ns/2010/04/configuration" 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>
+ <log level="full"/>
+ <send/>
+ </in>
+ <out>
+ <send/>
+ </out>
+ </sequence>
+</definitions></pre>
+<div>
+<p>
+<strong>Objective:</strong> Demonstrate the ability of the URL rewrite mediator to evaluate conditions on messages and
+perform rewrites based on the results.</p>
+<p>
+<strong>Prerequisites:</strong> Deploy the SimpleStockQuoteService in sample Axis2 server and start it on port 9000.</p>
+<p>Start Synapse with the sample configuration 451 (i.e. synapse -sample 451). </p>
+<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>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>
+</div>
+
+<h2>
+ <a name="Sample452" id="Sample452">Sample 452: Conditional URL Rewriting with Multiple Rules</a>
+</h2>
+<pre xml:space="preserve"><definitions xmlns="http://synapse.apache.org/ns/2010/04/configuration">
+ <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></pre>
+<div>
+<p>
+<strong>Objective:</strong> Demonstrate the ability of the URL rewrite mediator to perform rewrites based
+on multiple rules.</p>
+<p>
+<strong>Prerequisites:</strong> Deploy the SimpleStockQuoteService in sample Axis2 server and start it on port 9000.</p>
+<p>Start Synapse with the sample configuration 452 (i.e. synapse -sample 452). </p>
+<p>Invoke the Axis2 client as follows. </p>
+<pre xml:space="preserve">ant stockquote -Dtrpurl=http://localhost:8280 -Daddurl=http://test.com/SimpleStockQuoteService</pre>
+<p>The provided address URL does not contain a port number and the context. The URL rewrite mediator will replace
+the hostname to be '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>
+</div>
<h2>
<a name="Sample500" id="Sample500">Sample 500: Simple Eventing Sample</a>
</h2>