Author: ruwan
Date: Mon Nov 5 22:58:21 2007
New Revision: 592314
URL: http://svn.apache.org/viewvc?rev=592314&view=rev
Log:
Samples guide in progress
Modified:
webservices/synapse/branches/1.1/src/site/resources/Synapse_Samples.html
Modified:
webservices/synapse/branches/1.1/src/site/resources/Synapse_Samples.html
URL:
http://svn.apache.org/viewvc/webservices/synapse/branches/1.1/src/site/resources/Synapse_Samples.html?rev=592314&r1=592313&r2=592314&view=diff
==============================================================================
--- webservices/synapse/branches/1.1/src/site/resources/Synapse_Samples.html
(original)
+++ webservices/synapse/branches/1.1/src/site/resources/Synapse_Samples.html
Mon Nov 5 22:58:21 2007
@@ -253,7 +253,7 @@
<li><a href="#Sample370">Sample 370: Introduction to throttle
mediator and concurrency throttling</a></li>
<li><a href="#Sample371">Sample 371: Restricting requests based on
- policies </a></li>
+ policies</a></li>
<li><a href="#Sample372">Sample 372: TODO: Find the topic</a></li>
</ul>
</li>
@@ -3489,199 +3489,11 @@
<p></p>
-<h2><a name="ClassMediator">Extension mediators</a></h2>
+<h2><a name="Throttle">Throtteling messages (Throttle Mediator)</a></h2>
+<!-- TODO: any text to go in here??? -->
-<p>Synapse supports Mediators implemented in a variety of scripting languages
-such as JavaScript, Python or Ruby. Implementing a Mediator with a script
-language can have advantages over using the built in Synapse Mediator types
-or implementing a custom Java class Mediator. Script Mediators have all the
-flexibility of a class Mediator with access to the Synapse MessageContext and
-SynapseEnvironment APIs, and the ease of use and dynamic nature of scripting
-languages allows rapid development and prototyping of custom mediators. An
-additional benefit of some scripting languages is that they have very simple
-and elegant XML manipulation capabilities, for example JavaScript E4X or Ruby
-REXML, so this makes them well suited for use in the Synapse mediation
-environment.</p>
-
-<p></p>
-
-<h2><a name="Sample510">Sample 510</a></h2>
-
-<p></p>
-<pre><!-- Demonstrate the use of class mediator -->
-<definitions xmlns="http://ws.apache.org/ns/synapse">
-
- <sequence name="fault">
- <makefault>
- <code value="tns:Receiver"
xmlns:tns="http://www.w3.org/2003/05/soap-envelope"/>
- <reason value="Mediation failed."/>
- </makefault>
- <send/>
- </sequence>
-
- <sequence name="main" onError="fault">
- <in>
- <send>
- <endpoint name="stockquote">
- <address
uri="http://localhost:9000/soap/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></pre>
-
-<p></p>
-
-<p><strong>Objective: Demonstrate the use of Class mediator to extend the
-mediation functionality</strong></p>
-
-<p><strong>Prerequisites:</strong></p>
-
-<p>Make sure the synapse-samples-1.0.jar is in your class path (by default
-this jar is placed in the lib directory when installing Synapse).</p>
-
-<p>Start Synapse with the sample configuration 510 (i.e. synapse -sample
-510)</p>
-
-<p>Start the sample Axis2 server and deploy the SimpleStockQuoteService.</p>
-
-<p></p>
-
-<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.</p>
-
-<p>But the response message is passed through the class mediator before
-sending it back to the client. Two parameters named "discountFactor"</p>
-
-<p>and "bonusFor" are passed to the instance mediator implementation class
-(i.e. samples.mediators.DiscountQuoteMediator) before each</p>
-
-<p>invocation. Code of the mediator implementation class is shown below.</p>
-<pre>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;
- }
-}</pre>
-
-<p>All classes developed for class mediation should implement the Mediator
-interface, which contains the mediate(...) method. 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 the 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 substracted 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></p>
-
-<p>Now run the client using the following command.</p>
-<pre>ant stockquote -Dsymbol=IBM -Dmode=quote
-Daddurl=http://localhost:8080</pre>
-
-<p>You will see the below output in the client console with the discounted
-quote value.</p>
-<pre>[java] Standard :: Stock price = $138.77458254967408</pre>
-
-<p>Now check the console running Synapse. You will see the original value and
-the discounted value for the requested quote as follows.</p>
-<pre>Quote value discounted.
-Original price: 162.30945327447262
-Discounted price: 138.77458254967408</pre>
-
-<h1><a name="AdvancedMediations">Advanced mediations</a></h1>
-
-<h2>Sample 600</h2>
-
-<p></p>
+<h2><a name="Sample370">Sample 370: Introduction to throttle
+mediator and concurrency throttling</a></h2>
<pre><definitions xmlns="http://ws.apache.org/ns/synapse">
<sequence name="main">
<in>
@@ -3691,7 +3503,7 @@
<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:MaximumConcurrentAccess>10</throttle:MaximumConcurrentAccess>
</throttle:ThrottleAssertion>
</wsp:Policy>
</policy>
@@ -3723,16 +3535,10 @@
</in>
<out>
<throttle id="A"/>
- <send/>
-
-
-
-
-
-
-</out>
+ <send/>
+ </out>
</sequence>
-</definitions>
finitions></pre>
+</definitions></pre>
<p><b>Objective: Demonstrate the use of throttle mediator for concurrency
throttling </b></p>
@@ -3758,7 +3564,7 @@
synapse. For synapse with above configuration ,if client send 20 request
concurrently ,then approximately half of those will success..</p>
-<h2><a name="Sample600">Sample 601</a></h2>
+<h2><a name="Sample371">Sample 371: Restricting requests based on policies
</a></h2>
<pre><definitions xmlns="http://ws.apache.org/ns/synapse">
<sequence name="main">
<in>
@@ -3890,6 +3696,229 @@
[HttpServerWorker-3] INFO LogMediator - text = **Access Accept**
[HttpServerWorker-4] INFO LogMediator - text = **Access Accept**
[HttpServerWorker-5] INFO LogMediator - text = **Access Denied** </pre>
+
+<h2><a name="Sample372">Sample 372: TODO: Find the topic</a></h2>
+
+<!-- TODO: what goes here -->
+
+<h2><a name="Class">Extending the mediation in java (Class Mediator)</a></h2>
+
+<!-- TODO: Is there anything tpo go in here??? -->
+
+<h2><a name="Sample380">Sample 380: Writting your own custom mediation in
Java</a></h2>
+<pre><definitions xmlns="http://ws.apache.org/ns/synapse">
+
+ <sequence name="fault">
+ <makefault>
+ <code value="tns:Receiver"
xmlns:tns="http://www.w3.org/2003/05/soap-envelope"/>
+ <reason value="Mediation failed."/>
+ </makefault>
+ <send/>
+ </sequence>
+
+ <sequence name="main" onError="fault">
+ <in>
+ <send>
+ <endpoint name="stockquote">
+ <address
uri="http://localhost:9000/soap/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></pre>
+
+<p></p>
+
+<p><strong>Objective: Demonstrate the use of Class mediator to extend the
+mediation functionality</strong></p>
+
+<p><strong>Prerequisites:</strong></p>
+
+<p>Make sure the synapse-samples-1.0.jar is in your class path (by default
+this jar is placed in the lib directory when installing Synapse).</p>
+
+<p>Start Synapse with the sample configuration 510 (i.e. synapse -sample
+510)</p>
+
+<p>Start the sample Axis2 server and deploy the SimpleStockQuoteService.</p>
+
+<p></p>
+
+<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.</p>
+
+<p>But the response message is passed through the class mediator before
+sending it back to the client. Two parameters named "discountFactor"</p>
+
+<p>and "bonusFor" are passed to the instance mediator implementation class
+(i.e. samples.mediators.DiscountQuoteMediator) before each</p>
+
+<p>invocation. Code of the mediator implementation class is shown below.</p>
+<pre>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;
+ }
+}</pre>
+
+<p>All classes developed for class mediation should implement the Mediator
+interface, which contains the mediate(...) method. 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 the 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 substracted 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></p>
+
+<p>Now run the client using the following command.</p>
+<pre>ant stockquote -Dsymbol=IBM -Dmode=quote
-Daddurl=http://localhost:8080</pre>
+
+<p>You will see the below output in the client console with the discounted
+quote value.</p>
+<pre>[java] Standard :: Stock price = $138.77458254967408</pre>
+
+<p>Now check the console running Synapse. You will see the original value and
+the discounted value for the requested quote as follows.</p>
+<pre>Quote value discounted.
+Original price: 162.30945327447262
+Discounted price: 138.77458254967408</pre>
+
+
+<p></p>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
<h2>Sample 700</h2>
<pre><definitions xmlns="http://ws.apache.org/ns/synapse">
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]