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 2011/12/19 09:31:36 UTC
svn commit: r1220648 - in /synapse/branches/2.1:
repository/conf/sample/synapse_sample_17.xml
src/site/xdoc/Synapse_Configuration_Language.xml
src/site/xdoc/Synapse_Samples.xml
Author: hiranya
Date: Mon Dec 19 08:31:36 2011
New Revision: 1220648
URL: http://svn.apache.org/viewvc?rev=1220648&view=rev
Log:
Payload factory sample - SYNAPSE-821
Added:
synapse/branches/2.1/repository/conf/sample/synapse_sample_17.xml
Modified:
synapse/branches/2.1/src/site/xdoc/Synapse_Configuration_Language.xml
synapse/branches/2.1/src/site/xdoc/Synapse_Samples.xml
Added: synapse/branches/2.1/repository/conf/sample/synapse_sample_17.xml
URL: http://svn.apache.org/viewvc/synapse/branches/2.1/repository/conf/sample/synapse_sample_17.xml?rev=1220648&view=auto
==============================================================================
--- synapse/branches/2.1/repository/conf/sample/synapse_sample_17.xml (added)
+++ synapse/branches/2.1/repository/conf/sample/synapse_sample_17.xml Mon Dec 19 08:31:36 2011
@@ -0,0 +1,58 @@
+<?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.
+-->
+
+<!-- Introduction to the payloadFactory mediator -->
+<definitions xmlns="http://ws.apache.org/ns/synapse">
+
+ <sequence name="main">
+ <in>
+ <!-- using payloadFactory mediator to transform the request message -->
+ <payloadFactory>
+ <format>
+ <m:getQuote xmlns:m="http://services.samples">
+ <m:request>
+ <m:symbol>$1</m:symbol>
+ </m:request>
+ </m:getQuote>
+ </format>
+ <args>
+ <arg xmlns:m0="http://services.samples" expression="//m0:Code"/>
+ </args>
+ </payloadFactory>
+ </in>
+ <out>
+ <!-- using payloadFactory mediator to transform the response message -->
+ <payloadFactory>
+ <format>
+ <m:CheckPriceResponse xmlns:m="http://services.samples/xsd">
+ <m:Code>$1</m:Code>
+ <m:Price>$2</m:Price>
+ </m:CheckPriceResponse>
+ </format>
+ <args>
+ <arg xmlns:m0="http://services.samples/xsd" expression="//m0:symbol"/>
+ <arg xmlns:m0="http://services.samples/xsd" expression="//m0:last"/>
+ </args>
+ </payloadFactory>
+ </out>
+ <send/>
+ </sequence>
+
+</definitions>
Modified: synapse/branches/2.1/src/site/xdoc/Synapse_Configuration_Language.xml
URL: http://svn.apache.org/viewvc/synapse/branches/2.1/src/site/xdoc/Synapse_Configuration_Language.xml?rev=1220648&r1=1220647&r2=1220648&view=diff
==============================================================================
--- synapse/branches/2.1/src/site/xdoc/Synapse_Configuration_Language.xml (original)
+++ synapse/branches/2.1/src/site/xdoc/Synapse_Configuration_Language.xml Mon Dec 19 08:31:36 2011
@@ -1072,7 +1072,7 @@ where "sequence/dynamic_seq_1.xml" refer
A mediator token refers to any of the following tokens:
</p>
<pre xml:space="preserve">
- <a href="#send">send</a> | <a href="#drop">drop</a> | <a href="#log">log</a> | <a href="#property">property</a> | <a href="#sequence_ref">sequence</a> | <a href="#validate">validate</a> | <a href="#Callout">Callout</a> | <a href="#makefault">makefault</a> | <a href="#xslt">xslt</a> | <a href="#xquery">xquery</a> | <a href="#rewrite">rewrite</a> | <a href="#header">header</a> | <a href="#filter">filter</a> | <a href="#switch">switch</a> | <a href="#in">in</a> | <a href="#out">out</a>
+ <a href="#send">send</a> | <a href="#drop">drop</a> | <a href="#log">log</a> | <a href="#property">property</a> | <a href="#sequence_ref">sequence</a> | <a href="#validate">validate</a> | <a href="#Callout">Callout</a> | <a href="#makefault">makefault</a> | <a href="#xslt">xslt</a> | <a href="#xquery">xquery</a> | <a href="#rewrite">rewrite</a> | <a href="#header">header</a> | <a href="#payloadfactory">payloadFactory</a> | <a href="#filter">filter</a> | <a href="#switch">switch</a> | <a href="#in">in</a> | <a href="#out">out</a>
| <a href="#dblookup">dblookup</a> | <a href="#dbreport">dbreport</a> | <a href="#throttle">throttle</a> | <a href="#cache">cache</a> | <a href="#clone">clone</a> | <a href="#iterate">iterate</a> | <a href="#aggregate">aggregate</a> | <a href="#class">class</a> | <a href="#pojoCommand">pojoCommand</a> | <a href="#spring">spring</a> | <a href="#script">script</a> | <a href="#RMSequence">RMSequence</a> | <a href="#eventPublisher">eventPublisher</a> | <a href="#transaction">transaction</a>
</pre>
@@ -1666,6 +1666,25 @@ where "sequence/dynamic_seq_1.xml" refer
<li>RelatesTo</li>
</ul>
<p/>
+ <h4>
+ <a name="payloadfactory" id="payloadfactory">Payload-factory</a>
+ </h4>
+<pre xml:space="preserve"><payloadFactory>
+ <format>"xmlstring"</format>
+ <args>
+ <arg (value="literal" | expression="xpath")/>*
+ </args>
+</payloadFactory></pre>
+ <p>
+ The Payload-factory mediator creates a new SOAP payload for the message, replacing the
+ existing one. printf() style formatting is used to configure the transformation
+ performed by the mediator.
+ </p>
+ <p>
+ Each argument in the mediator configuration could be a static value or an XPath expression.
+ When an expression is used, argument value is fetched at runtime by evaluating the provided
+ XPath expression against the existing SOAP message/message context.
+ </p>
<h3>
Selection Mediators
</h3>
Modified: synapse/branches/2.1/src/site/xdoc/Synapse_Samples.xml
URL: http://svn.apache.org/viewvc/synapse/branches/2.1/src/site/xdoc/Synapse_Samples.xml?rev=1220648&r1=1220647&r2=1220648&view=diff
==============================================================================
--- synapse/branches/2.1/src/site/xdoc/Synapse_Samples.xml (original)
+++ synapse/branches/2.1/src/site/xdoc/Synapse_Samples.xml Mon Dec 19 08:31:36 2011
@@ -144,6 +144,8 @@
<a href="#Sample13">Sample 15: Message Enrichment through Synapse</a></li>
<li>
<a href="#Sample16">Sample 16: Introduction to dynamic and static keys</a></li>
+<li>
+<a href="#Sample17">Sample 17: Transforming / replacing message content with Payload-factory mediator</a></li>
</ul></li>
<li>
@@ -1014,6 +1016,77 @@ Standard dual channel :: Stock price = $
<p>Execute the custom quote client as 'ant stockquote -Dmode=customquote â¦' and analys the output which is similar to the Sample 8. </p>
<pre xml:space="preserve">ant stockquote -Daddurl=http://localhost:9000/services/SimpleStockQuoteService -Dtrpurl=http://localhost:8280/ -Dmode=customquote</pre>
+<h2>
+<a name="Sample17" id="Sample17">Sample 17: Transforming / replacing message content with Payload-factory mediator</a></h2>
+<pre xml:space="preserve">
+<definitions xmlns="http://ws.apache.org/ns/synapse">
+
+ <sequence name="main">
+ <in>
+ <!-- using payloadFactory mediator to transform the request message -->
+ <payloadFactory>
+ <format>
+ <m:getQuote xmlns:m="http://services.samples">
+ <m:request>
+ <m:symbol>$1</m:symbol>
+ </m:request>
+ </m:getQuote>
+ </format>
+ <args>
+ <arg xmlns:m0="http://services.samples" expression="//m0:Code"/>
+ </args>
+ </payloadFactory>
+ </in>
+ <out>
+ <!-- using payloadFactory mediator to transform the response message -->
+ <payloadFactory>
+ <format>
+ <m:CheckPriceResponse xmlns:m="http://services.samples/xsd">
+ <m:Code>$1</m:Code>
+ <m:Price>$2</m:Price>
+ </m:CheckPriceResponse>
+ </format>
+ <args>
+ <arg xmlns:m0="http://services.samples/xsd" expression="//m0:symbol"/>
+ <arg xmlns:m0="http://services.samples/xsd" expression="//m0:last"/>
+ </args>
+ </payloadFactory>
+ </out>
+ <send/>
+ </sequence>
+
+</definitions>
+</pre>
+
+<p>
+<strong>Objective: Introducing Payload-factory mediator</strong> </p>
+<p>
+<strong>Prerequisites:</strong>
+<br/> Start the Axis2 server and deploy the SimpleStockQuoteService (Refer steps above)
+<br/> Start the Synapse configuration numbered 17: i.e. synapse -sample 17</p>
+
+
+<p>
+This sample uses Payload-factory mediator to perform transformations as an alternative
+to XSLT mediator (Sample 8). In this sample, Synapse implements Message Translator EIP and acts
+an a translator between the client and the backend server.
+</p>
+
+<p>Execute the custom quote client as 'ant stockquote -Dmode=customquote ...'
+and analyze Synapse debug log output </p>
+<pre xml:space="preserve">ant stockquote -Daddurl=http://localhost:9000/services/SimpleStockQuoteService -Dtrpurl=http://localhost:8280/ -Dmode=customquote</pre>
+
+<p>Incoming message is transformed by the Payload-factory mediator into a standard stock quote
+request as expected by the SimpleStockQuoteService deployed on the Axis2 server.
+<code>printf()</code> style formatting is used to configure the transformation performed by
+the mediator. Each argument in the mediator configuration could be a static value or an
+XPath expression. When an expression is used, argument value is fetched at runtime by evaluating
+the provided XPath expression against the existing SOAP message. </p>
+
+<p>The response from the SimpleStockQuoteService is converted back into the custom format as
+expected by the client during the out message processing, once again using Payload-factory
+mediator.</p>
+
<h1>
<a name="Endpoints" id="Endpoints">Advanced mediations with endpoints</a> </h1>
<h2>