You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@synapse.apache.org by ka...@apache.org on 2011/12/23 12:55:09 UTC
svn commit: r1222651 [9/14] - in /synapse/branches/2.1: ./
modules/distribution/ modules/distribution/src/main/assembly/
modules/documentation/ modules/documentation/src/
modules/documentation/src/site/ modules/documentation/src/site/resources/
modules...
Added: synapse/branches/2.1/modules/documentation/src/site/xdoc/userguide/samples/sample353.xml
URL: http://svn.apache.org/viewvc/synapse/branches/2.1/modules/documentation/src/site/xdoc/userguide/samples/sample353.xml?rev=1222651&view=auto
==============================================================================
--- synapse/branches/2.1/modules/documentation/src/site/xdoc/userguide/samples/sample353.xml (added)
+++ synapse/branches/2.1/modules/documentation/src/site/xdoc/userguide/samples/sample353.xml Fri Dec 23 11:55:05 2011
@@ -0,0 +1,124 @@
+<?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 353</title>
+ </properties>
+ <body>
+ <section name="Sample 353: Using Ruby Scripts for Mediation">
+ <div class="xmlConf"><definitions xmlns="http://ws.apache.org/ns/synapse">
+
+ <localEntry key="stockquoteScript"
+ src="file:repository/conf/sample/resources/script/stockquoteTransform.rb"/>
+
+ <sequence name="main">
+ <in>
+ <!-- transform the custom quote request into a standard quote request expected by the service -->
+ <script language="rb" key="stockquoteScript" function="transformRequest"/>
+
+ <!-- send message to real endpoint referenced by name "stockquote" and stop -->
+ <send>
+ <endpoint name="stockquote">
+ <address uri="http://localhost:9000/services/SimpleStockQuoteService"/>
+ </endpoint>
+ </send>
+ </in>
+ <out>
+ <!-- transform the standard response back into the custom format the client expects -->
+ <script language="rb" key="stockquoteScript" function="transformResponse"/>
+ <send/>
+ </out>
+ </sequence>
+
+</definitions></div>
+ <p>
+ The external script referenced by the configuration contains the following Ruby
+ scriplet.
+ </p>
+ <div class="xmlConf"><x><![CDATA[
+require 'rexml/document'
+include REXML
+
+def transformRequest(mc)
+ newRequest= Document.new '<m:getQuote xmlns:m="http://services.samples">'<<
+ '<m:request><m:symbol></m:symbol></m:request></m:getQuote>'
+ newRequest.root.elements[1].elements[1].text = mc.getPayloadXML().root.elements[1].get_text
+ mc.setPayloadXML(newRequest)
+end
+
+def transformResponse(mc)
+ newResponse = Document.new '<m:CheckPriceResponse xmlns:m="http://www.apache-synapse.org/test"><m:Code>' <<
+ '</m:Code><m:Price></m:Price></m:CheckPriceResponse>'
+ newResponse.root.elements[1].text = mc.getPayloadXML().root.elements[1].elements[1].get_text
+ newResponse.root.elements[2].text = mc.getPayloadXML().root.elements[1].elements[2].get_text
+ mc.setPayloadXML(newResponse)
+end
+]]></x></div>
+ <subsection name="Objective">
+ <p>
+ The script mediator of Synapse can be programmed using any BSF compatible
+ programming language. <a href="sample250.html">Sample 250</a> shows how to
+ configure it using JavaScript. This sample shows how to configure the script
+ mediator with Ruby.
+ </p>
+ </subsection>
+ <subsection name="Pre-requisites">
+ <p>
+ <ul>
+ <li>
+ This sample uses Ruby so first setup support for this in Synapse as described at
+ <a href="setup/script.html#ruby">Configuring JRuby</a>
+ <br />
+ </li>
+ <li>
+ Deploy the SimpleStockQuoteService in the sample Axis2 server and start Axis2
+ </li>
+ <li>
+ Synapse does not ship with a Ruby engine by default. Therefore you should
+ download the Ruby engine from JRuby site and copy the downloaded jar file
+ to the 'lib' directory of Synapse.
+ </li>
+ <li>
+ Start Synapse using the configuration numbered 353 (repository/conf/sample/synapse_sample_353.xml)
+ <div class="command">
+ Unix/Linux: sh synapse.sh -sample 353<br/>
+ Windows: synapse.bat -sample 353
+ </div>
+ </li>
+ </ul>
+ </p>
+ </subsection>
+ <subsection name="Executing the Client">
+ <p>
+ This sample is identical to <a href="sample350.html">sample 350</a> with the
+ only difference being the use of Ruby instead of JavaScript. Use the stock
+ quote client to send a custom quote request as follows.
+ </p>
+ <div class="command">ant stockquote -Daddurl=http://localhost:9000/services/SimpleStockQuoteService -Dtrpurl=http://localhost:8280/ -Dmode=customquote</div>
+ <p>
+ The Ruby scriplets will transform the requests and responses as they flow through
+ the service bus.
+ </p>
+ </subsection>
+ </section>
+ <p><a href="../samples.html">Back to Catalog</a></p>
+ </body>
+</document>
\ No newline at end of file
Added: synapse/branches/2.1/modules/documentation/src/site/xdoc/userguide/samples/sample354.xml
URL: http://svn.apache.org/viewvc/synapse/branches/2.1/modules/documentation/src/site/xdoc/userguide/samples/sample354.xml?rev=1222651&view=auto
==============================================================================
--- synapse/branches/2.1/modules/documentation/src/site/xdoc/userguide/samples/sample354.xml (added)
+++ synapse/branches/2.1/modules/documentation/src/site/xdoc/userguide/samples/sample354.xml Fri Dec 23 11:55:05 2011
@@ -0,0 +1,108 @@
+<?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 354</title>
+ </properties>
+ <body>
+ <section name="Sample 354: Using Inline Ruby Scripts for Mediation">
+ <div class="xmlConf"><definitions xmlns="http://ws.apache.org/ns/synapse">
+
+ <sequence name="main">
+ <in>
+ <script language="rb">
+
+ require 'rexml/document'
+ include REXML
+ newRequest= Document.new '<m:getQuote xmlns:m="http://services.samples"><m:request><m:symbol>...test...</m:symbol></m:request></m:getQuote>'
+ newRequest.root.elements[1].elements[1].text =
+ $mc.getPayloadXML().root.elements[1].get_text
+ $mc.setPayloadXML(newRequest)
+
+ </script>
+ <send>
+ <endpoint>
+ <address uri="http://localhost:9000/services/SimpleStockQuoteService"/>
+ </endpoint>
+ </send>
+ </in>
+ <out>
+ <script language="rb">
+
+ require 'rexml/document'
+ include REXML
+ newResponse = Document.new '<m:CheckPriceResponse
+ xmlns:m="http://services.samples/xsd"><m:Code></m:Code><m:Price></m:Price></m:CheckPriceResponse>'
+ newResponse.root.elements[1].text =
+ $mc.getPayloadXML().root.elements[1].elements[1].get_text
+ newResponse.root.elements[2].text =
+ $mc.getPayloadXML().root.elements[1].elements[2].get_text
+ $mc.setPayloadXML(newResponse)
+
+ </script>
+ <send/>
+ </out>
+ </sequence>
+
+</definitions></div>
+ <subsection name="Objective">
+ <p>
+ Shows how to embed Ruby scripts in the Synapse configuration itself.
+ </p>
+ </subsection>
+ <subsection name="Pre-requisites">
+ <p>
+ <ul>
+ <li>
+ This sample uses Ruby, so first setup support for this in Synapse as described at
+ <a href="setup/script.html#ruby">Configuring JRuby</a>
+ </li>
+ <li>
+ Deploy the SimpleStockQuoteService in the sample Axis2 server and start Axis2
+ </li>
+ <li>
+ Synapse does not ship with a Ruby engine by default. Therefore you should
+ download the Ruby engine from JRuby site and copy the downloaded jar file
+ to the 'lib' directory of Synapse.
+ </li>
+ <li>
+ Start Synapse using the configuration numbered 354 (repository/conf/sample/synapse_sample_354.xml)
+ <div class="command">
+ Unix/Linux: sh synapse.sh -sample 354<br/>
+ Windows: synapse.bat -sample 354
+ </div>
+ </li>
+ </ul>
+ </p>
+ </subsection>
+ <subsection name="Executing the Client">
+ <p>
+ Run the sample client as follows.
+ </p>
+ <div class="command">ant stockquote -Daddurl=http://localhost:9000/services/SimpleStockQuoteService -Dtrpurl=http://localhost:8280/ -Dmode=customquote</div>
+ <p>
+ The inline Ruby scripts will transform the requests and responses.
+ </p>
+ </subsection>
+ </section>
+ <p><a href="../samples.html">Back to Catalog</a></p>
+ </body>
+</document>
\ No newline at end of file
Added: synapse/branches/2.1/modules/documentation/src/site/xdoc/userguide/samples/sample360.xml
URL: http://svn.apache.org/viewvc/synapse/branches/2.1/modules/documentation/src/site/xdoc/userguide/samples/sample360.xml?rev=1222651&view=auto
==============================================================================
--- synapse/branches/2.1/modules/documentation/src/site/xdoc/userguide/samples/sample360.xml (added)
+++ synapse/branches/2.1/modules/documentation/src/site/xdoc/userguide/samples/sample360.xml Fri Dec 23 11:55:05 2011
@@ -0,0 +1,191 @@
+<?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 360</title>
+ </properties>
+ <body>
+ <section name="Sample 360: Introduction to DBLookup Mediator">
+ <div class="xmlConf"><definitions xmlns="http://ws.apache.org/ns/synapse">
+
+ <sequence name="myFaultHandler">
+ <makefault response="true">
+ <code xmlns:tns="http://www.w3.org/2003/05/soap-envelope" value="tns:Receiver"/>
+ <reason expression="get-property('ERROR_MESSAGE')"/>
+ </makefault>
+ <send/>
+ <drop/>
+ </sequence>
+
+ <sequence name="main" onError="myFaultHandler">
+ <in>
+ <log level="custom">
+ <property name="text" value="** Looking up from the Database **"/>
+ </log>
+ <dblookup>
+ <connection>
+ <pool>
+ <driver>org.apache.derby.jdbc.ClientDriver</driver>
+ <url>jdbc:derby://localhost:1527/synapsedb;create=false</url>
+ <user>synapse</user>
+ <password>synapse</password>
+ </pool>
+ </connection>
+ <statement>
+ <sql>select * from company where name =?</sql>
+ <parameter xmlns:m0="http://services.samples"
+ expression="//m0:getQuote/m0:request/m0:symbol" type="VARCHAR"/>
+ <result name="company_id" column="id"/>
+ </statement>
+ </dblookup>
+
+ <switch source="get-property('company_id')">
+ <case regex="c1">
+ <log level="custom">
+ <property name="text"
+ expression="fn:concat('Company ID - ',get-property('company_id'))"/>
+ </log>
+ <send>
+ <endpoint>
+ <address uri="http://localhost:9000/services/SimpleStockQuoteService"/>
+ </endpoint>
+ </send>
+ </case>
+ <case regex="c2">
+ <log level="custom">
+ <property name="text"
+ expression="fn:concat('Company ID - ',get-property('company_id'))"/>
+ </log>
+ <send>
+ <endpoint>
+ <address uri="http://localhost:9000/services/SimpleStockQuoteService"/>
+ </endpoint>
+ </send>
+ </case>
+ <case regex="c3">
+ <log level="custom">
+ <property name="text"
+ expression="fn:concat('Company ID - ',get-property('company_id'))"/>
+ </log>
+ <send>
+ <endpoint>
+ <address uri="http://localhost:9000/services/SimpleStockQuoteService"/>
+ </endpoint>
+ </send>
+ </case>
+ <default>
+ <log level="custom">
+ <property name="text" value="** Unrecognized Company ID **"/>
+ </log>
+ <makefault response="true">
+ <code xmlns:tns="http://www.w3.org/2003/05/soap-envelope"
+ value="tns:Receiver"/>
+ <reason value="** Unrecognized Company ID **"/>
+ </makefault>
+ <send/>
+ <drop/>
+ </default>
+ </switch>
+ <drop/>
+ </in>
+
+ <out>
+ <send/>
+ </out>
+
+ </sequence>
+
+</definitions></div>
+ <subsection name="Objective">
+ <p>
+ Demonstrating how to perform database lookups during mediation using the dblookup
+ mediator
+ </p>
+ </subsection>
+ <subsection name="Pre-requisites">
+ <p>
+ <ul>
+ <li>
+ Setup a Derby database as described in the <a href="setup/db.html">database setup guide</a>
+ </li>
+ <li>
+ Deploy the SimpleStockQuoteService in the sample Axis2 server and start Axis2
+ </li>
+ <li>
+ Start Synapse using the configuration numbered 360 (repository/conf/sample/synapse_sample_360.xml)
+ <div class="command">
+ Unix/Linux: sh synapse.sh -sample 360<br/>
+ Windows: synapse.bat -sample 360
+ </div>
+ </li>
+ </ul>
+ </p>
+ </subsection>
+ <subsection name="Executing the Client">
+ <p>
+ This sample demonstrates simple database read operations through Synapse. When a
+ message arrives at dblookup mediator, it opens a connection to the database and
+ executes the given SQL query. The SQL query uses '?' character for attributes that
+ will be filled at runtime. The parameters define how to calculate the value of
+ those attributes at runtime. In this sample a dblookup mediator has been used to
+ extract 'id' of the company from the company database using the symbol which is
+ extracted from the SOAP envelope by evaluating an XPath. Then 'id' bases switching
+ will be done by a switch mediator.
+ </p>
+ <p>
+ To try this out, first request a stock quote for the symbol 'IBM' as follows.
+ </p>
+ <div class="command">ant stockquote -Daddurl=http://localhost:9000/services/SimpleStockQuoteService -Dtrpurl=http://localhost:8280/ -Dsymbol=IBM</div>
+ <p>
+ Synapse console will display the following message.
+ </p>
+ <div class="consoleOutput">INFO LogMediator text = ** Looking up from the Database **
+ INFO LogMediator text = Company ID – c1</div>
+ <p>
+ Now request a quote for the symbol 'SUN'.
+ </p>
+ <div class="command">ant stockquote -Daddurl=http://localhost:9000/services/SimpleStockQuoteService -Dtrpurl=http://localhost:8280/ -Dsymbol=SUN</div>
+ <p>
+ Synapse will display the following output.
+ </p>
+ <div class="consoleOutput">INFO LogMediator text = ** Looking up from the Database **
+INFO LogMediator text = Company ID – c2</div>
+ <p>
+ Finally send a stock quote request for the symbol 'MSFT'.
+ </p>
+ <div class="command">ant stockquote -Daddurl=http://localhost:9000/services/SimpleStockQuoteService -Dtrpurl=http://localhost:8280/ -Dsymbol=MSFT</div>
+ <p>
+ In this case Synapse will display the following output.
+ </p>
+ <div class="consoleOutput">INFO LogMediator text = ** Looking up from the Database **
+INFO LogMediator text = Company ID – c2</div>
+ <p>
+ If you send any requests with different symbols, dblookup mediator will return
+ an empty result set, since those symbols are not stored in the Derby database.
+ So as a result Synapse will not be able to determine the company ID, which will
+ result in the following log entry (from the default case in the switch mediator).
+ </p>
+ <div class="consoleOutput">INFO LogMediator text = ** Unrecognized Company ID **</div>
+ </subsection>
+ </section>
+ <p><a href="../samples.html">Back to Catalog</a></p>
+ </body>
+</document>
\ No newline at end of file
Added: synapse/branches/2.1/modules/documentation/src/site/xdoc/userguide/samples/sample361.xml
URL: http://svn.apache.org/viewvc/synapse/branches/2.1/modules/documentation/src/site/xdoc/userguide/samples/sample361.xml?rev=1222651&view=auto
==============================================================================
--- synapse/branches/2.1/modules/documentation/src/site/xdoc/userguide/samples/sample361.xml (added)
+++ synapse/branches/2.1/modules/documentation/src/site/xdoc/userguide/samples/sample361.xml Fri Dec 23 11:55:05 2011
@@ -0,0 +1,121 @@
+<?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 361</title>
+ </properties>
+ <body>
+ <section name="Sample 361: Introduction to DBReport Mediator">
+ <div class="xmlConf"><definitions xmlns="http://ws.apache.org/ns/synapse">
+
+ <sequence name="main">
+ <in>
+ <send>
+ <endpoint>
+ <address uri="http://localhost:9000/services/SimpleStockQuoteService"/>
+ </endpoint>
+ </send>
+ </in>
+
+ <out>
+ <log level="custom">
+ <property name="text" value="** Reporting to the Database **"/>
+ </log>
+ <dbreport>
+ <connection>
+ <pool>
+ <driver>org.apache.derby.jdbc.ClientDriver</driver>
+ <url>jdbc:derby://localhost:1527/synapsedb;create=false</url>
+ <user>synapse</user>
+ <password>synapse</password>
+ </pool>
+ </connection>
+ <statement>
+ <sql>update company set price=? where name =?</sql>
+ <parameter xmlns:m1="http://services.samples/xsd"
+ xmlns:m0="http://services.samples"
+ expression="//m0:return/m1:last/child::text()" type="DOUBLE"/>
+ <parameter xmlns:m1="http://services.samples/xsd"
+ xmlns:m0="http://services.samples"
+ expression="//m0:return/m1:symbol/child::text()" type="VARCHAR"/>
+ </statement>
+ </dbreport>
+ <send/>
+ </out>
+ </sequence>
+
+</definitions></div>
+ <subsection name="Objective">
+ <p>
+ <a href="sample360.html">Sample 360</a> shows how to perform database lookups
+ in Synapse. This sample illustrates how to write to a given database from
+ Synapse using the dbreport mediator.
+ </p>
+ </subsection>
+ <subsection name="Pre-requisites">
+ <p>
+ <ul>
+ <li>
+ Setup a Derby database as described in the <a href="setup/db.html">database setup guide</a>
+ </li>
+ <li>
+ Deploy the SimpleStockQuoteService in the sample Axis2 server and start Axis2
+ </li>
+ <li>
+ Start Synapse using the configuration numbered 361 (repository/conf/sample/synapse_sample_361.xml)
+ <div class="command">
+ Unix/Linux: sh synapse.sh -sample 361<br/>
+ Windows: synapse.bat -sample 361
+ </div>
+ </li>
+ </ul>
+ </p>
+ </subsection>
+ <subsection name="Executing the Client">
+ <p>
+ This sample demonstrates how to perform simple database write operations in
+ Synapse. The dbreport mediator writes (i.e. inserts one row) to a table using the
+ details available in messages. It works the same way as the dblookup mediator.
+ In this sample, dbreport mediator is used for updating the stock price of the
+ company using the last quote value which is calculated by evaluating an XPath
+ against the response message. After running this sample, user can check the
+ company table using the Derby client tool. It will show the value inserted by the
+ dbreport mediator.
+ </p>
+ <p>
+ To try this out run the sample client as follows.
+ </p>
+ <div class="command">ant stockquote -Daddurl=http://localhost:9000/services/SimpleStockQuoteService -Dtrpurl=http://localhost:8280/ -Dsymbol=IBM</div>
+ <p>
+ Now execute the following SQL query against the Derby database using the Derby
+ client tool.
+ </p>
+ <div class="command">select price from company where name='IBM';</div>
+ <p>
+ This operation will return the stock quote value returned earlier by Axis2. You
+ can compare the output of the sample Axis2 client with the output of the Derby
+ client tool for confirmation.
+ </p>
+ </subsection>
+ </section>
+ <p><a href="../samples.html">Back to Catalog</a></p>
+ </body>
+</document>
\ No newline at end of file
Added: synapse/branches/2.1/modules/documentation/src/site/xdoc/userguide/samples/sample362.xml
URL: http://svn.apache.org/viewvc/synapse/branches/2.1/modules/documentation/src/site/xdoc/userguide/samples/sample362.xml?rev=1222651&view=auto
==============================================================================
--- synapse/branches/2.1/modules/documentation/src/site/xdoc/userguide/samples/sample362.xml (added)
+++ synapse/branches/2.1/modules/documentation/src/site/xdoc/userguide/samples/sample362.xml Fri Dec 23 11:55:05 2011
@@ -0,0 +1,143 @@
+<?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 362</title>
+ </properties>
+ <body>
+ <section name="Sample 362: Perform Database Lookups and Updates in the Same Mediation Sequence">
+ <div class="xmlConf"><definitions xmlns="http://ws.apache.org/ns/synapse">
+
+ <sequence name="main">
+ <in>
+ <send>
+ <endpoint>
+ <address uri="http://localhost:9000/services/SimpleStockQuoteService"/>
+ </endpoint>
+ </send>
+ </in>
+
+ <out>
+ <log level="custom">
+ <property name="text" value="** Reporting to the Database **"/>
+ </log>
+
+ <dbreport>
+ <connection>
+ <pool>
+ <driver>org.apache.derby.jdbc.ClientDriver</driver>
+ <url>jdbc:derby://localhost:1527/synapsedb;create=false</url>
+ <user>synapse</user>
+ <password>synapse</password>
+ </pool>
+ </connection>
+ <statement>
+ <sql>update company set price=? where name =?</sql>
+ <parameter xmlns:m1="http://services.samples/xsd"
+ xmlns:m0="http://services.samples"
+ expression="//m0:return/m1:last/child::text()" type="DOUBLE"/>
+ <parameter xmlns:m1="http://services.samples/xsd"
+ xmlns:m0="http://services.samples"
+ expression="//m0:return/m1:symbol/child::text()" type="VARCHAR"/>
+ </statement>
+ </dbreport>
+ <log level="custom">
+ <property name="text" value="** Looking up from the Database **"/>
+ </log>
+ <dblookup>
+ <connection>
+ <pool>
+ <driver>org.apache.derby.jdbc.ClientDriver</driver>
+ <url>jdbc:derby://localhost:1527/synapsedb;create=false</url>
+ <user>synapse</user>
+ <password>synapse</password>
+ </pool>
+ </connection>
+ <statement>
+ <sql>select * from company where name =?</sql>
+ <parameter xmlns:m1="http://services.samples/xsd"
+ xmlns:m0="http://services.samples"
+ expression="//m0:return/m1:symbol/child::text()" type="VARCHAR"/>
+ <result name="stock_price" column="price"/>
+ </statement>
+ </dblookup>
+ <log level="custom">
+ <property name="text"
+ expression="fn:concat('Stock price - ',get-property('stock_price'))"/>
+ </log>
+ <send/>
+ </out>
+ </sequence>
+
+</definitions></div>
+ <subsection name="Objective">
+ <p>
+ <a href="sample360.html">Sample 360</a> and <a href="sample361.html">sample 361</a>
+ shows how to use the dblookup mediator and dbreport mediator separately. This sample
+ combines them in a single mediation sequence to perform both database lookup and
+ update operations.
+ </p>
+ </subsection>
+ <subsection name="Pre-requisites">
+ <p>
+ <ul>
+ <li>
+ Setup a Derby database as described in the <a href="setup/db.html">database setup guide</a>
+ </li>
+ <li>
+ Deploy the SimpleStockQuoteService in the sample Axis2 server and start Axis2
+ </li>
+ <li>
+ Start Synapse using the configuration numbered 362 (repository/conf/sample/synapse_sample_362.xml)
+ <div class="command">
+ Unix/Linux: sh synapse.sh -sample 362<br/>
+ Windows: synapse.bat -sample 362
+ </div>
+ </li>
+ </ul>
+ </p>
+ </subsection>
+ <subsection name="Executing the Client">
+ <p>
+ In this sample, the dbreport mediator works the same way as in
+ <a href="sample361.html">sample 361</a>. It updates the price for the given company
+ using the response messages content. Then the dblookup mediator reads the last
+ updated value from the company database and logs it to the console.
+ </p>
+ <p>
+ Run the sample client as follows.
+ </p>
+ <div class="command">ant stockquote -Daddurl=http://localhost:9000/services/SimpleStockQuoteService -Dtrpurl=http://localhost:8280/ -Dsymbol=IBM</div>
+ <p>
+ Synapse will update the database using the stock quote value available in the
+ response sent by Axis2. Then the same value will be retrieved from the database
+ and logged as follows.
+ </p>
+ <div class="consoleOutput">INFO LogMediator text = ** Reporting to the Database **
+...
+INFO LogMediator text = ** Looking up from the Database **
+...
+INFO LogMediator text = Stock price - 153.47886496064808</div>
+ </subsection>
+ </section>
+ <p><a href="../samples.html">Back to Catalog</a></p>
+ </body>
+</document>
\ No newline at end of file
Added: synapse/branches/2.1/modules/documentation/src/site/xdoc/userguide/samples/sample363.xml
URL: http://svn.apache.org/viewvc/synapse/branches/2.1/modules/documentation/src/site/xdoc/userguide/samples/sample363.xml?rev=1222651&view=auto
==============================================================================
--- synapse/branches/2.1/modules/documentation/src/site/xdoc/userguide/samples/sample363.xml (added)
+++ synapse/branches/2.1/modules/documentation/src/site/xdoc/userguide/samples/sample363.xml Fri Dec 23 11:55:05 2011
@@ -0,0 +1,205 @@
+<?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 363</title>
+ </properties>
+ <body>
+ <section name="Sample 363: Reusable Database Connection Pools">
+ <div class="xmlConf"><definitions xmlns="http://ws.apache.org/ns/synapse">
+
+ <sequence name="myFaultHandler">
+ <makefault response="true">
+ <code xmlns:tns="http://www.w3.org/2003/05/soap-envelope" value="tns:Receiver"/>
+ <reason expression="get-property('ERROR_MESSAGE')"/>
+ </makefault>
+ <send/>
+ <drop/>
+ </sequence>
+
+ <sequence name="main" onError="myFaultHandler">
+ <in>
+ <log level="custom">
+ <property name="text" value="** Looking up from the Database **"/>
+ </log>
+ <dblookup>
+ <connection>
+ <pool>
+ <dsName>lookupdb</dsName>
+ </pool>
+ </connection>
+ <statement>
+ <sql>select * from company where name =?</sql>
+ <parameter xmlns:m0="http://services.samples"
+ expression="//m0:getQuote/m0:request/m0:symbol" type="VARCHAR"/>
+ <result name="company_id" column="id"/>
+ </statement>
+ </dblookup>
+
+ <switch source="get-property('company_id')">
+ <case regex="c1">
+ <log level="custom">
+ <property name="text"
+ expression="fn:concat('Company ID - ',get-property('company_id'))"/>
+ </log>
+ <send>
+ <endpoint>
+ <address uri="http://localhost:9000/services/SimpleStockQuoteService"/>
+ </endpoint>
+ </send>
+ </case>
+ <case regex="c2">
+ <log level="custom">
+ <property name="text"
+ expression="fn:concat('Company ID - ',get-property('company_id'))"/>
+ </log>
+ <send>
+ <endpoint>
+ <address uri="http://localhost:9000/services/SimpleStockQuoteService"/>
+ </endpoint>
+ </send>
+ </case>
+ <case regex="c3">
+ <log level="custom">
+ <property name="text"
+ expression="fn:concat('Company ID - ',get-property('company_id'))"/>
+ </log>
+ <send>
+ <endpoint>
+ <address uri="http://localhost:9000/services/SimpleStockQuoteService"/>
+ </endpoint>
+ </send>
+ </case>
+ <default>
+ <log level="custom">
+ <property name="text" value="** Unrecognized Company ID **"/>
+ </log>
+ <makefault response="true">
+ <code xmlns:tns="http://www.w3.org/2003/05/soap-envelope"
+ value="tns:Receiver"/>
+ <reason value="** Unrecognized Company ID **"/>
+ </makefault>
+ <send/>
+ <drop/>
+ </default>
+ </switch>
+ <drop/>
+ </in>
+
+ <out>
+ <log level="custom">
+ <property name="text" value="** Reporting to the Database **"/>
+ </log>
+ <dbreport>
+ <connection>
+ <pool>
+ <dsName>reportdb</dsName>
+ </pool>
+ </connection>
+ <statement>
+ <sql>update company set price=? where name =?</sql>
+ <parameter xmlns:m0="http://services.samples"
+ xmlns:m1="http://services.samples/xsd"
+ expression="//m0:return/m1:last/child::text()" type="DOUBLE"/>
+ <parameter xmlns:m0="http://services.samples"
+ xmlns:m1="http://services.samples/xsd"
+ expression="//m0:return/m1:symbol/child::text()" type="VARCHAR"/>
+ </statement>
+ </dbreport>
+ <log level="custom">
+ <property name="text" value="** Looking up from the Database **"/>
+ </log>
+ <dblookup>
+ <connection>
+ <pool>
+ <dsName>reportdb</dsName>
+ </pool>
+ </connection>
+ <statement>
+ <sql>select * from company where name =?</sql>
+ <parameter xmlns:m0="http://services.samples"
+ xmlns:m1="http://services.samples/xsd"
+ expression="//m0:return/m1:symbol/child::text()" type="VARCHAR"/>
+ <result name="stock_price" column="price"/>
+ </statement>
+ </dblookup>
+ <log level="custom">
+ <property name="text"
+ expression="fn:concat('Stock price - ',get-property('stock_price'))"/>
+ </log>
+ <send/>
+
+ </out>
+
+ </sequence>
+
+</definitions></div>
+ <subsection name="Objective">
+ <p>
+ Demonstrate how to setup reusable connection pools for the dblookup and dbreport
+ mediators
+ </p>
+ </subsection>
+ <subsection name="Pre-requisites">
+ <p>
+ <ul>
+ <li>
+ Setup a Derby database and the Synapse data sources as described in the
+ <a href="setup/db.html">database setup guide</a>
+ </li>
+ <li>
+ Deploy the SimpleStockQuoteService in the sample Axis2 server and start Axis2
+ </li>
+ <li>
+ Start Synapse using the configuration numbered 363 (repository/conf/sample/synapse_sample_363.xml)
+ <div class="command">
+ Unix/Linux: sh synapse.sh -sample 363<br/>
+ Windows: synapse.bat -sample 363
+ </div>
+ </li>
+ </ul>
+ </p>
+ </subsection>
+ <subsection name="Executing the Client">
+ <p>
+ This sample employs two instances of the dblookup mediator and a single instance
+ of the dbreport mediator. The two dblookup mediators are sharing the same database
+ connection pool named 'lookupdb'. The dbreport mediator makes use of a different
+ connection pool named 'dbreport'. Synapse uses Apache DBCP to create and manage
+ the corresponding data sources and connection pools.
+ </p>
+ <p>
+ Run this sample by invoking the client as follows.
+ </p>
+ <div class="command">ant stockquote -Daddurl=http://localhost:9000/services/SimpleStockQuoteService -Dtrpurl=http://localhost:8280/ -Dsymbol=IBM</div>
+ <p>
+ Synapse will log the following output as it reads from and writes to the database.
+ </p>
+ <div class="consoleOutput">INFO LogMediator text = ** Looking up from the Database ** ...
+INFO LogMediator text = Company ID - c1 ...
+INFO LogMediator text = ** Reporting to the Database ** ...
+INFO LogMediator text = ** Looking up from the Database ** ...
+INFO LogMediator text = Stock price - 183.3635460215262</div>
+ </subsection>
+ </section>
+ <p><a href="../samples.html">Back to Catalog</a></p>
+ </body>
+</document>
\ No newline at end of file
Added: synapse/branches/2.1/modules/documentation/src/site/xdoc/userguide/samples/sample364.xml
URL: http://svn.apache.org/viewvc/synapse/branches/2.1/modules/documentation/src/site/xdoc/userguide/samples/sample364.xml?rev=1222651&view=auto
==============================================================================
--- synapse/branches/2.1/modules/documentation/src/site/xdoc/userguide/samples/sample364.xml (added)
+++ synapse/branches/2.1/modules/documentation/src/site/xdoc/userguide/samples/sample364.xml Fri Dec 23 11:55:05 2011
@@ -0,0 +1,142 @@
+<?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 364</title>
+ </properties>
+ <body>
+ <section name="Sample 364: Executing Database Stored Procedures">
+ <div class="xmlConf"><definitions xmlns="http://ws.apache.org/ns/synapse">
+
+ <sequence name="main">
+ <in>
+ <send>
+ <endpoint>
+ <address uri="http://localhost:9000/services/SimpleStockQuoteService"/>
+ </endpoint>
+ </send>
+ </in>
+
+ <out>
+ <log level="custom">
+ <property name="text" value="** Reporting to the Database **"/>
+ </log>
+
+ <dbreport>
+ <connection>
+ <pool>
+ <driver>com.mysql.jdbc.Driver</driver>
+ <url>jdbc:mysql://localhost:3306/synapsedb</url>
+ <user>user</user>
+ <password>password</password>
+ </pool>
+ </connection>
+ <statement>
+ <sql>call updateCompany(?,?)</sql>
+ <parameter xmlns:m0="http://services.samples"
+ xmlns:m1="http://services.samples/xsd"
+ expression="//m0:return/m1:last/child::text()" type="DOUBLE"/>
+ <parameter xmlns:m0="http://services.samples"
+ xmlns:m1="http://services.samples/xsd"
+ expression="//m0:return/m1:symbol/child::text()" type="VARCHAR"/>
+ </statement>
+ </dbreport>
+ <log level="custom">
+ <property name="text" value="** Looking up from the Database **"/>
+ </log>
+ <dblookup>
+ <connection>
+ <pool>
+ <driver>com.mysql.jdbc.Driver</driver>
+ <url>jdbc:mysql://localhost:3306/synapsedb</url>
+ <user>user</user>
+ <password>password</password>
+ </pool>
+ </connection>
+ <statement>
+ <sql>call getCompany(?)</sql>
+ <parameter xmlns:m0="http://services.samples"
+ xmlns:m1="http://services.samples/xsd"
+ expression="//m0:return/m1:symbol/child::text()" type="VARCHAR"/>
+ <result name="stock_prize" column="price"/>
+ </statement>
+ </dblookup>
+ <log level="custom">
+ <property name="text"
+ expression="fn:concat('Stock Prize - ',get-property('stock_prize'))"/>
+ </log>
+ <send/>
+ </out>
+ </sequence>
+
+</definitions></div>
+ <subsection name="Objective">
+ <p>
+ Demonstrate how to invoke a database stored procedure from Synapse
+ </p>
+ </subsection>
+ <subsection name="Pre-requisites">
+ <p>
+ <ul>
+ <li>
+ Setup a MySQL database as described in the <a href="setup/db.html#mysql">database setup guide</a>
+ </li>
+ <li>
+ Deploy the SimpleStockQuoteService in the sample Axis2 server and start Axis2
+ </li>
+ <li>
+ Open the repository/conf/sample/synapse_sample_364.xml file and change the
+ database username, password credentials accordingly
+ </li>
+ <li>
+ Start Synapse using the configuration numbered 364 (repository/conf/sample/synapse_sample_364.xml)
+ <div class="command">
+ Unix/Linux: sh synapse.sh -sample 364<br/>
+ Windows: synapse.bat -sample 364
+ </div>
+ </li>
+ </ul>
+ </p>
+ </subsection>
+ <subsection name="Executing the Client">
+ <p>
+ This scenario is very similar to <a href="sample363.html">sample 363</a>, but makes
+ use of stored procedures to lookup and update the database instead of simple
+ SQL queries. Note that we are still using the dblookup and dbreport mediators
+ to access the database but the statements are simply calling a stored procedure in
+ MySQL (the syntax to call a stored procedue is database engine specific).
+ </p>
+ <p>
+ To try this sample out, invoke the sample client as follows.
+ </p>
+ <div class="command">ant stockquote -Daddurl=http://localhost:9000/services/SimpleStockQuoteService -Dtrpurl=http://localhost:8280/ -Dsymbol=IBM</div>
+ <p>
+ Synapse will invoke the two stored procedures as the response is mediated back
+ to the client. You will see the following output on the Synapse console.
+ </p>
+ <div class="consoleOutput">INFO LogMediator text = ** Looking up from the Database ** ...
+INFO LogMediator text = Company ID - c1 ...
+INFO LogMediator text = Stock price - 183.3635460215262</div>
+ </subsection>
+ </section>
+ <p><a href="../samples.html">Back to Catalog</a></p>
+ </body>
+</document>
\ No newline at end of file
Added: synapse/branches/2.1/modules/documentation/src/site/xdoc/userguide/samples/sample370.xml
URL: http://svn.apache.org/viewvc/synapse/branches/2.1/modules/documentation/src/site/xdoc/userguide/samples/sample370.xml?rev=1222651&view=auto
==============================================================================
--- synapse/branches/2.1/modules/documentation/src/site/xdoc/userguide/samples/sample370.xml (added)
+++ synapse/branches/2.1/modules/documentation/src/site/xdoc/userguide/samples/sample370.xml Fri Dec 23 11:55:05 2011
@@ -0,0 +1,116 @@
+<?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 370</title>
+ </properties>
+ <body>
+ <section name="Sample 370: Introduction to Throttle Mediator and Concurrency Throttling">
+ <div class="xmlConf"><definitions xmlns="http://ws.apache.org/ns/synapse">
+
+ <sequence name="main">
+ <in>
+ <throttle id="A">
+ <policy>
+ <!-- define throttle policy -->
+ <wsp:Policy xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"
+ xmlns:throttle="http://www.wso2.org/products/wso2commons/throttle">
+ <throttle:ThrottleAssertion>
+ <throttle:MaximumConcurrentAccess>10</throttle:MaximumConcurrentAccess>
+ </throttle:ThrottleAssertion>
+ </wsp:Policy>
+ </policy>
+ <onAccept>
+ <log level="custom">
+ <property name="text" value="**Access Accept**"/>
+ </log>
+ <send>
+ <endpoint>
+ <address uri="http://localhost:9000/services/SimpleStockQuoteService"/>
+ </endpoint>
+ </send>
+ </onAccept>
+ <onReject>
+ <log level="custom">
+ <property name="text" value="**Access Denied**"/>
+ </log>
+ <makefault response="true">
+ <code xmlns:tns="http://www.w3.org/2003/05/soap-envelope"
+ value="tns:Receiver"/>
+ <reason value="**Access Denied**"/>
+ </makefault>
+ <send/>
+ <drop/>
+ </onReject>
+ </throttle>
+ </in>
+ <out>
+ <throttle id="A"/>
+ <send/>
+ </out>
+ </sequence>
+
+</definitions></div>
+ <subsection name="Objective">
+ <p>
+ Showcase the ability of Synapse to throttle incoming requests based on the
+ concurrency level
+ </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 370 (repository/conf/sample/synapse_sample_370.xml)
+ <div class="command">
+ Unix/Linux: sh synapse.sh -sample 370<br/>
+ Windows: synapse.bat -sample 370
+ </div>
+ </li>
+ </ul>
+ </p>
+ </subsection>
+ <subsection name="Executing the Client">
+ <p>
+ Above configuration specifies a throttle mediator inside the in mediator.
+ Therefore, all request messages directed to the main sequence will be subjected
+ to throttling. Throttle mediator has 'policy', 'onAccept' and 'onReject' tags at
+ top level. The 'policy' tag specifies the throttling policy for throttling messages.
+ This sample policy only contains a component called 'MaximumConcurrentAccess'.
+ This indicates the maximum number of concurrent requests that can pass through
+ Synapse on a single unit of time. To test concurrency throttling, it is required
+ to send concurrent requests to Synapse. With this configuration if Synapse receives
+ 20 requests concurrently from clients, then approximately half of those will succeed
+ while the others being throttled. The client command to try this is as follows.
+ </p>
+ <div class="command">ant stockquote -Dsymbol=IBM -Dmode=quote -Daddurl=http://localhost:8280/</div>
+ <p>
+ It's not that easy to try this sample out using the sample Axis2 client. For
+ better results, consider using a load testing tool like Apache Bench or Java Bench.
+ </p>
+ </subsection>
+ </section>
+ <p><a href="../samples.html">Back to Catalog</a></p>
+ </body>
+</document>
\ No newline at end of file
Added: synapse/branches/2.1/modules/documentation/src/site/xdoc/userguide/samples/sample371.xml
URL: http://svn.apache.org/viewvc/synapse/branches/2.1/modules/documentation/src/site/xdoc/userguide/samples/sample371.xml?rev=1222651&view=auto
==============================================================================
--- synapse/branches/2.1/modules/documentation/src/site/xdoc/userguide/samples/sample371.xml (added)
+++ synapse/branches/2.1/modules/documentation/src/site/xdoc/userguide/samples/sample371.xml Fri Dec 23 11:55:05 2011
@@ -0,0 +1,176 @@
+<?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 371</title>
+ </properties>
+ <body>
+ <section name="Sample 371: Restricting Requests Based on Policies">
+ <div class="xmlConf"><definitions xmlns="http://ws.apache.org/ns/synapse">
+
+ <sequence name="main">
+ <in>
+ <throttle id="A">
+ <policy>
+ <!-- define throttle policy -->
+ <wsp:Policy xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"
+ xmlns:throttle="http://www.wso2.org/products/wso2commons/throttle">
+ <throttle:ThrottleAssertion>
+ <wsp:All>
+ <throttle:ID throttle:type="IP">other</throttle:ID>
+ <wsp:ExactlyOne>
+ <wsp:All>
+ <throttle:MaximumCount>4</throttle:MaximumCount>
+ <throttle:UnitTime>800000</throttle:UnitTime>
+ <throttle:ProhibitTimePeriod wsp:Optional="true">10000
+ </throttle:ProhibitTimePeriod>
+ </wsp:All>
+ <throttle:IsAllow>true</throttle:IsAllow>
+ </wsp:ExactlyOne>
+ </wsp:All>
+ <wsp:All>
+ <throttle:ID throttle:type="IP">192.168.8.200-192.168.8.222
+ </throttle:ID>
+ <wsp:ExactlyOne>
+ <wsp:All>
+ <throttle:MaximumCount>8</throttle:MaximumCount>
+ <throttle:UnitTime>800000</throttle:UnitTime>
+ <throttle:ProhibitTimePeriod wsp:Optional="true">10
+ </throttle:ProhibitTimePeriod>
+ </wsp:All>
+ <throttle:IsAllow>true</throttle:IsAllow>
+ </wsp:ExactlyOne>
+ </wsp:All>
+ <wsp:All>
+ <throttle:ID throttle:type="IP">192.168.8.201</throttle:ID>
+ <wsp:ExactlyOne>
+ <wsp:All>
+ <throttle:MaximumCount>200</throttle:MaximumCount>
+ <throttle:UnitTime>600000</throttle:UnitTime>
+ <throttle:ProhibitTimePeriod wsp:Optional="true"/>
+ </wsp:All>
+ <throttle:IsAllow>true</throttle:IsAllow>
+ </wsp:ExactlyOne>
+ </wsp:All>
+ <wsp:All>
+ <throttle:ID throttle:type="IP">192.168.8.198</throttle:ID>
+ <wsp:ExactlyOne>
+ <wsp:All>
+ <throttle:MaximumCount>50</throttle:MaximumCount>
+ <throttle:UnitTime>500000</throttle:UnitTime>
+ <throttle:ProhibitTimePeriod wsp:Optional="true"/>
+ </wsp:All>
+ <throttle:IsAllow>true</throttle:IsAllow>
+ </wsp:ExactlyOne>
+ </wsp:All>
+ </throttle:ThrottleAssertion>
+ </wsp:Policy>
+ </policy>
+ <onAccept>
+ <log level="custom">
+ <property name="text" value="**Access Accept**"/>
+ </log>
+ <send>
+ <endpoint>
+ <address uri="http://localhost:9000/services/SimpleStockQuoteService"/>
+ </endpoint>
+ </send>
+ </onAccept>
+ <onReject>
+ <log level="custom">
+ <property name="text" value="**Access Denied**"/>
+ </log>
+ <makefault response="true">
+ <code xmlns:tns="http://www.w3.org/2003/05/soap-envelope"
+ value="tns:Receiver"/>
+ <reason value="**Access Denied**"/>
+ </makefault>
+ <send/>
+ <drop/>
+ </onReject>
+ </throttle>
+ </in>
+ <out>
+ <throttle id="A"/>
+ <send/>
+ </out>
+ </sequence>
+
+</definitions></div>
+ <subsection name="Objective">
+ <p>
+ Demonstrate how to throttle incoming requests based on complex policies
+ </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 371 (repository/conf/sample/synapse_sample_371.xml)
+ <div class="command">
+ Unix/Linux: sh synapse.sh -sample 371<br/>
+ Windows: synapse.bat -sample 371
+ </div>
+ </li>
+ </ul>
+ </p>
+ </subsection>
+ <subsection name="Executing the Client">
+ <p>
+ Above configuration specifies a throttle mediator inside the in mediator.
+ Therefore, all request messages directed to the main sequence will be subjected
+ to throttling. Throttle mediator has policy, onAccept and onReject tags at the
+ top level. Policy tag specifies the throttling policy against which all messages
+ will be evaluated. It contains some IP address ranges and the maximum number of
+ messages to be allowed for those ranges within a time period given in 'UnitTime'
+ tag. 'ProhibitTimePeriod' tag specifies the time period to prohibit further
+ requests after the received request count exceeds the specified time. Now run the
+ client 5 times repetitively using the following command to see how throttling works.
+ </p>
+ <div class="command">ant stockquote -Dsymbol=IBM -Dmode=quote -Daddurl=http://localhost:8280/</div>
+ <p>
+ For the first four requests you will get the quote prices for IBM as follows.
+ </p>
+ <div class="consoleOutput">[java] Standard :: Stock price = $177.20143371883802</div>
+ <p>
+ Fifth request will not be sent to the Axis2 server and the client will receive
+ the following fault.
+ </p>
+ <div class="consoleOutput">[java] org.apache.axis2.AxisFault: **Access Denied**</div>
+ <p>
+ Maximum number of requests within 800000 milliseconds is specified as 4 for any
+ server (including localhost) other than the explicitly specified ones. Therefore,
+ our fifth request is denied by the throttle mediator. You can verify this by looking
+ at the Synapse console.
+ </p>
+ <div class="consoleOutput">[HttpServerWorker-1] INFO LogMediator - text = **Access Accept**
+[HttpServerWorker-2] INFO LogMediator - text = **Access Accept**
+[HttpServerWorker-3] INFO LogMediator - text = **Access Accept**
+[HttpServerWorker-4] INFO LogMediator - text = **Access Accept**
+[HttpServerWorker-5] INFO LogMediator - text = **Access Denied**</div>
+ </subsection>
+ </section>
+ <p><a href="../samples.html">Back to Catalog</a></p>
+ </body>
+</document>
\ No newline at end of file
Added: synapse/branches/2.1/modules/documentation/src/site/xdoc/userguide/samples/sample372.xml
URL: http://svn.apache.org/viewvc/synapse/branches/2.1/modules/documentation/src/site/xdoc/userguide/samples/sample372.xml?rev=1222651&view=auto
==============================================================================
--- synapse/branches/2.1/modules/documentation/src/site/xdoc/userguide/samples/sample372.xml (added)
+++ synapse/branches/2.1/modules/documentation/src/site/xdoc/userguide/samples/sample372.xml Fri Dec 23 11:55:05 2011
@@ -0,0 +1,119 @@
+<?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 372</title>
+ </properties>
+ <body>
+ <section name="Sample 372: Use of Concurrency Throttling and Request Rate Based Throttling">
+ <div class="xmlConf"><definitions xmlns="http://ws.apache.org/ns/synapse">
+
+ <registry provider="org.apache.synapse.registry.url.SimpleURLRegistry">
+ <!-- the root property of the simple URL registry helps resolve a resource URL as root + key -->
+ <parameter name="root">file:repository/</parameter>
+ <!-- all resources loaded from the URL registry would be cached for this number of milli seconds -->
+ <parameter name="cachableDuration">150000</parameter>
+ </registry>
+
+ <sequence name="onAcceptSequence">
+ <log level="custom">
+ <property name="text" value="**Access Accept**"/>
+ </log>
+ <send>
+ <endpoint>
+ <address uri="http://localhost:9000/services/SimpleStockQuoteService"/>
+ </endpoint>
+ </send>
+ </sequence>
+
+ <sequence name="onRejectSequence" trace="enable">
+ <log level="custom">
+ <property name="text" value="**Access Denied**"/>
+ </log>
+ <makefault response="true">
+ <code xmlns:tns="http://www.w3.org/2003/05/soap-envelope" value="tns:Receiver"/>
+ <reason value="**Access Denied**"/>
+ </makefault>
+ <send/>
+ <drop/>
+ </sequence>
+
+ <proxy name="StockQuoteProxy">
+ <target>
+ <inSequence>
+ <throttle onReject="onRejectSequence" onAccept="onAcceptSequence" id="A">
+ <policy key="conf/sample/resources/policy/throttle_policy.xml"/>
+ </throttle>
+ </inSequence>
+ <outSequence>
+ <throttle id="A"/>
+ <send/>
+ </outSequence>
+ </target>
+ <publishWSDL uri="file:repository/conf/sample/resources/proxy/sample_proxy_1.wsdl"/>
+ </proxy>
+
+</definitions></div>
+ <subsection name="Objective">
+ <p>
+ Showcase how to use the concurrency throttling in conjunction with request rate
+ throttling
+ </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 372 (repository/conf/sample/synapse_sample_372.xml)
+ <div class="command">
+ Unix/Linux: sh synapse.sh -sample 372<br/>
+ Windows: synapse.bat -sample 372
+ </div>
+ </li>
+ </ul>
+ </p>
+ </subsection>
+ <subsection name="Executing the Client">
+ <p>
+ This is a combination of <a href="sample370.html">sample 370</a> and
+ <a href="sample371.html">sample 371</a>. In this case the throttle policy is loaded
+ from the 'throttle_policy.xml' file which is fetched from the registry. To verify
+ the functionality, it requires running a load test. The all enabled request from
+ the concurrency throttling will be controlled by the access rate base throttling
+ according to the policy.
+ </p>
+ <p>
+ Run the client as follows.
+ </p>
+ <div class="command">ant stockquote -Daddurl=http://localhost:8280/services/StockQuoteProxy</div>
+ <p>
+ You will get same results as in <a href="sample371.html">sample 371</a>. If you
+ run the load test, results will be different due to the effect of concurrency
+ throttling.
+ </p>
+ </subsection>
+ </section>
+ <p><a href="../samples.html">Back to Catalog</a></p>
+ </body>
+</document>
\ No newline at end of file
Added: synapse/branches/2.1/modules/documentation/src/site/xdoc/userguide/samples/sample380.xml
URL: http://svn.apache.org/viewvc/synapse/branches/2.1/modules/documentation/src/site/xdoc/userguide/samples/sample380.xml?rev=1222651&view=auto
==============================================================================
--- synapse/branches/2.1/modules/documentation/src/site/xdoc/userguide/samples/sample380.xml (added)
+++ synapse/branches/2.1/modules/documentation/src/site/xdoc/userguide/samples/sample380.xml Fri Dec 23 11:55:05 2011
@@ -0,0 +1,204 @@
+<?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 380</title>
+ </properties>
+ <body>
+ <section name="Sample 380: Writing Custom Mediation Logic in Java">
+ <div class="xmlConf"><definitions xmlns="http://ws.apache.org/ns/synapse">
+
+ <sequence name="fault">
+ <makefault>
+ <code xmlns:tns="http://www.w3.org/2003/05/soap-envelope" value="tns:Receiver"/>
+ <reason value="Mediation failed."/>
+ </makefault>
+ <send/>
+ </sequence>
+
+ <sequence name="main" onError="fault">
+ <in>
+ <send>
+ <endpoint name="stockquote">
+ <address uri="http://localhost:9000/services/SimpleStockQuoteService"/>
+ </endpoint>
+ </send>
+ </in>
+ <out>
+ <class name="samples.mediators.DiscountQuoteMediator">
+ <property name="discountFactor" value="10"/>
+ <property name="bonusFor" value="5"/>
+ </class>
+ <send/>
+ </out>
+ </sequence>
+
+</definitions></div>
+ <subsection name="Objective">
+ <p>
+ Demonstrate the use of class mediator to extend the mediation functionality of
+ Synapse
+ </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 380 (repository/conf/sample/synapse_sample_380.xml)
+ <div class="command">
+ Unix/Linux: sh synapse.sh -sample 380<br/>
+ Windows: synapse.bat -sample 380
+ </div>
+ </li>
+ </ul>
+ </p>
+ </subsection>
+ <subsection name="Executing the Client">
+ <p>
+ In this configuration, Synapse hands over the request message to the specified
+ endpoint, which sends it to the Axis2 server running on port 9000. But the response
+ message is passed through the class mediator before sending it back to the client.
+ Class mediator in turns hands over the message to the specified Java class for
+ further processing. In that regard, the class mediator acts as a delegating
+ mediator which delegates the message to a custom Java class for processing.
+ Two parameters named 'discountFactor' and 'bonusFor' are passed to the mediator
+ implementation class (i.e. samples.mediators.DiscountQuoteMediator) before each
+ invocation. Source of the mediator implementation class is shown below.
+ </p>
+ <div class="consoleOutput">package samples.mediators;
+
+import org.apache.synapse.MessageContext;
+import org.apache.synapse.Mediator;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.soap.SOAPFactory;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.xml.namespace.QName;
+
+public class DiscountQuoteMediator implements Mediator {
+
+ private static final Log log = LogFactory.getLog(DiscountQuoteMediator.class);
+
+ private String discountFactor="10";
+
+ private String bonusFor="10";
+
+ private int bonusCount=0;
+
+ public DiscountQuoteMediator(){}
+
+ public boolean mediate(MessageContext mc) {
+
+ String price= mc.getEnvelope().getBody().getFirstElement().getFirstElement().
+ getFirstChildWithName(new QName("http://services.samples/xsd","last")).getText();
+
+ //converting String properties into integers
+ int discount=Integer.parseInt(discountFactor);
+ int bonusNo=Integer.parseInt(bonusFor);
+ double currentPrice=Double.parseDouble(price);
+
+ //discounting factor is deducted from current price form every response
+ Double lastPrice = new Double(currentPrice - currentPrice * discount / 100);
+
+ //Special discount of 5% offers for the first responses as set in the bonusFor property
+ if (bonusCount <= bonusNo) {
+ lastPrice = new Double(lastPrice.doubleValue() - lastPrice.doubleValue() * 0.05);
+ bonusCount++;
+ }
+
+ String discountedPrice = lastPrice.toString();
+
+ mc.getEnvelope().getBody().getFirstElement().getFirstElement().getFirstChildWithName
+ (new QName("http://services.samples/xsd","last")).setText(discountedPrice);
+
+ System.out.println("Quote value discounted.");
+ System.out.println("Original price: " + price);
+ System.out.println("Discounted price: " + discountedPrice);
+
+ return true;
+ }
+
+ public String getType() {
+ return null;
+ }
+
+ public void setTraceState(int traceState) {
+ traceState = 0;
+ }
+
+ public int getTraceState() {
+ return 0;
+ }
+
+ public void setDiscountFactor(String discount) {
+ discountFactor=discount;
+ }
+
+ public String getDiscountFactor() {
+ return discountFactor;
+ }
+
+ public void setBonusFor(String bonus){
+ bonusFor=bonus;
+ }
+
+ public String getBonusFor(){
+ return bonusFor;
+ }
+}</div>
+ <p>
+ All classes developed for the class mediator should implement the 'Mediator'
+ interface, which contains the mediate(...) method. The mediate(...) method of the
+ above class is invoked for each response message mediated through the main
+ sequence, with the message context of the current message as the parameter. All
+ details of the message including the SOAP headers, SOAP body and properties of
+ the context hierarchy can be accessed from the message context. In this sample,
+ the body of the message is retrieved and the discount percentage is subtracted
+ from the quote price. If the quote request number is less than the number specified
+ in the 'bonusFor' property in the configuration, a special discount is given.
+ </p>
+ <p>
+ To test the custom code and the class mediator, invoke the test client as
+ follows.
+ </p>
+ <div class="command">ant stockquote -Dsymbol=IBM -Dmode=quote -Daddurl=http://localhost:8280</div>
+ <p>
+ You will see the below output in the client console with the discounted quote value.
+ </p>
+ <div class="consoleOutput">Standard :: Stock price = $95.26454380258552</div>
+ <p>
+ If you check the Synapse console, you will notice the messages printed by the
+ custom mediator during mediation.
+ </p>
+ <div class="consoleOutput">Quote value discounted.
+Original price: 162.30945327447262
+Discounted price: 138.77458254967408</div>
+ </subsection>
+ </section>
+ <p><a href="../samples.html">Back to Catalog</a></p>
+ </body>
+</document>
\ No newline at end of file