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/08/23 13:48:29 UTC

svn commit: r988090 - in /synapse/trunk/java: modules/samples/src/main/java/samples/userguide/JSONClient.java repository/conf/sample/synapse_sample_440.xml src/site/xdoc/Synapse_Samples.xml src/site/xdoc/Synapse_Samples_Setup.xml

Author: hiranya
Date: Mon Aug 23 11:48:29 2010
New Revision: 988090

URL: http://svn.apache.org/viewvc?rev=988090&view=rev
Log:
Completing the JSON sample (sample 440)

Related to SYNAPSE-678


Modified:
    synapse/trunk/java/modules/samples/src/main/java/samples/userguide/JSONClient.java
    synapse/trunk/java/repository/conf/sample/synapse_sample_440.xml
    synapse/trunk/java/src/site/xdoc/Synapse_Samples.xml
    synapse/trunk/java/src/site/xdoc/Synapse_Samples_Setup.xml

Modified: synapse/trunk/java/modules/samples/src/main/java/samples/userguide/JSONClient.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/samples/src/main/java/samples/userguide/JSONClient.java?rev=988090&r1=988089&r2=988090&view=diff
==============================================================================
--- synapse/trunk/java/modules/samples/src/main/java/samples/userguide/JSONClient.java (original)
+++ synapse/trunk/java/modules/samples/src/main/java/samples/userguide/JSONClient.java Mon Aug 23 11:48:29 2010
@@ -61,7 +61,7 @@ public class JSONClient {
         String trpUrl = getProperty("trpurl", null);
         String prxUrl = getProperty("prxurl", null);
         String repo = getProperty("repository", "client_repo");
-        String symbol = getProperty("symbol", "WSO2");
+        String symbol = getProperty("symbol", "IBM");
 
         if (repo != null && !"null".equals(repo)) {
             configContext =

Modified: synapse/trunk/java/repository/conf/sample/synapse_sample_440.xml
URL: http://svn.apache.org/viewvc/synapse/trunk/java/repository/conf/sample/synapse_sample_440.xml?rev=988090&r1=988089&r2=988090&view=diff
==============================================================================
--- synapse/trunk/java/repository/conf/sample/synapse_sample_440.xml (original)
+++ synapse/trunk/java/repository/conf/sample/synapse_sample_440.xml Mon Aug 23 11:48:29 2010
@@ -28,10 +28,12 @@
             <inSequence>
                 <log level="full"/>
                 <xslt key="in_transform"/>
+                <property name="messageType" scope="axis2" value="text/xml"/>
             </inSequence>
             <outSequence>
                 <log level="full"/>
                 <xslt key="out_transform"/>
+                <property name="messageType" scope="axis2" value="application/json"/>
                 <send/>
             </outSequence>
         </target>
@@ -43,7 +45,7 @@
                         xmlns:m0="http://services.samples" version="2.0" exclude-result-prefixes="m0 fn">
             <xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>
             <xsl:template match="*">
-                <xsl:element name="{local-name()}" namespace="http://tools.carbon.wso2.org">
+                <xsl:element name="{local-name()}" namespace="http://services.samples">
                     <xsl:copy-of select="attribute::*"/>
                     <xsl:apply-templates/>
                 </xsl:element>

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=988090&r1=988089&r2=988090&view=diff
==============================================================================
--- synapse/trunk/java/src/site/xdoc/Synapse_Samples.xml (original)
+++ synapse/trunk/java/src/site/xdoc/Synapse_Samples.xml Mon Aug 23 11:48:29 2010
@@ -299,7 +299,10 @@
 <a href="#Callout">Synchronize web service invocation with Callout mediator</a>
 <ul>
 <li>
-<a href="#Sample430">Sample 430: Simple Callout Mediator for synchronize web service invocation</a></li></ul></li></ul></li>
+<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>
+</ul></li></ul></li>
         <li>
           <a href="#Task">Introduction to Eventing</a>
           <ul>
@@ -4386,6 +4389,74 @@ Discounted price: 138.77458254967408</pr
 <p>In this sample, the callout mediator does the direct service invocation to the StockQuoteService using the client request, gets the response and sets it as the first child of the SOAP message body. Then using the send mediator, the message is sent back to the client. </p>
 <p>Invoke the client as follows. </p>
 <pre xml:space="preserve">ant stockquote -Daddurl=http://localhost:9000/services/SimpleStockQuoteService -Dtrpurl=http://localhost:8280/</pre></div>
+<h2>
+    <a name="Sample440" id="Sample440">Sample 440: Exposing a SOAP Service Over JSON</a>
+</h2>
+<pre xml:space="preserve">&lt;definitions xmlns="http://synapse.apache.org/ns/2010/04/configuration"&gt;
+
+    &lt;proxy name="JSONProxy" transports="http https"&gt;
+        &lt;target&gt;
+            &lt;endpoint&gt;
+                &lt;address uri="http://localhost:9000/services/SimpleStockQuoteService"/&gt;
+            &lt;/endpoint&gt;
+            &lt;inSequence&gt;
+                &lt;log level="full"/&gt;
+                &lt;xslt key="in_transform"/&gt;
+                &lt;property name="messageType" scope="axis2" value="text/xml"/&gt;
+            &lt;/inSequence&gt;
+            &lt;outSequence&gt;
+                &lt;log level="full"/&gt;
+                &lt;xslt key="out_transform"/&gt;
+                &lt;property name="messageType" scope="axis2" value="application/json"/&gt;
+                &lt;send/&gt;
+            &lt;/outSequence&gt;
+        &lt;/target&gt;
+    &lt;/proxy&gt;
+
+    &lt;localEntry key="in_transform"&gt;
+        &lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+                        xmlns:fn="http://www.w3.org/2005/02/xpath-functions"
+                        xmlns:m0="http://services.samples" version="2.0" exclude-result-prefixes="m0 fn"&gt;
+            &lt;xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/&gt;
+            &lt;xsl:template match="*"&gt;
+                &lt;xsl:element name="{local-name()}" namespace="http://services.samples"&gt;
+                    &lt;xsl:copy-of select="attribute::*"/&gt;
+                    &lt;xsl:apply-templates/&gt;
+                &lt;/xsl:element&gt;
+            &lt;/xsl:template&gt;
+        &lt;/xsl:stylesheet&gt;
+    &lt;/localEntry&gt;
+
+    &lt;localEntry key="out_transform"&gt;
+        &lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"&gt;
+            &lt;xsl:output method="xml" version="1.0" encoding="UTF-8"/&gt;
+            &lt;xsl:template match="*"&gt;
+                &lt;xsl:element name="{local-name()}"&gt;
+                    &lt;xsl:apply-templates/&gt;
+                &lt;/xsl:element&gt;
+            &lt;/xsl:template&gt;
+        &lt;/xsl:stylesheet&gt;
+    &lt;/localEntry&gt;
+
+&lt;/definitions&gt;</pre>
+<div>
+<p>
+<strong>Objective:</strong> Demonstrate the ability to switch between JSON and XML/SOAP content interchange formats</p>
+<p>
+<strong>Prerequisites:</strong> Deploy the SimpleStockQuoteService in sample Axis2 server and start it on port 9000.</p>
+<p>Setup Synapse and the sample Axis2 client for JSON (Refer <a href="Synapse_Samples_Setup.html#json">Synapse Samples Setup Guide</a>
+for details)</p>
+<p>Start Synapse with the sample configuration 440 (i.e. synapse -sample 440). </p>
+<p>Invoke the JSON client as follows. </p>
+<pre xml:space="preserve">ant jsonclient -Daddurl=http://localhost:9000/services/SimpleStockQuoteService -Dtrpurl=http://localhost:8280/services/JSONProxy</pre>
+<p>JSON client will send a stockquote request to Synapse using the JSON content interchange format. Synapse
+will trnasform it into a SOAP request and forward to the Axis2 server. The SOAP response from the Axis2 server
+will be converted into a JSON message and sent back to the JSON client.</p>
+<p>You may use a tool like TCPMon to monitor the JSON requests sent over the wire. A sample JSON request and response
+ is shown below:</p>
+<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="Sample500" id="Sample500">Sample 500: Simple Eventing Sample</a>
     </h2>

Modified: synapse/trunk/java/src/site/xdoc/Synapse_Samples_Setup.xml
URL: http://svn.apache.org/viewvc/synapse/trunk/java/src/site/xdoc/Synapse_Samples_Setup.xml?rev=988090&r1=988089&r2=988090&view=diff
==============================================================================
--- synapse/trunk/java/src/site/xdoc/Synapse_Samples_Setup.xml (original)
+++ synapse/trunk/java/src/site/xdoc/Synapse_Samples_Setup.xml Mon Aug 23 11:48:29 2010
@@ -781,6 +781,38 @@ synapse.sh -sample &lt;n&gt;</pre>
       here</a>.
     </p>
     <p/>
+    <h2 id="json">
+      Configuring Synapse for JSON Support
+    </h2>
+    <p/>
+    <p>
+      <a href="http://json.org">JSON</a> is a lightweight data-interchange format.
+      It can be used as an alternative to the XML or SOAP. To enable the JSON support
+      in Synapse, following two jar files should be deployed into the 'lib' directory
+      of Synapse.
+    </p>
+    <ul>
+        <li><a href="http://repo1.maven.org/maven2/org/apache/axis2/axis2-saaj">axis2-saaj.jar</a></li>
+        <li><a href="http://jettison.codehaus.org/Download">jettison.jar</a></li>
+    </ul>
+    <p>
+      Having deployed the necessary libraries you should now register the JSON message
+      builder and formatter with Synapse. Open up 'repository/conf/axis2.xml' file
+      of Synapse and add the following two entries under the 'messageBuilders' and
+      'messageFormatters' sections respectively.
+    </p>
+    <pre>
+      &lt;messageBuilder contentType="application/json"
+                         class="org.apache.axis2.json.JSONOMBuilder"/&gt;
+
+      &lt;messageFormatter contentType="application/json"
+                         class="org.apache.axis2.json.JSONMessageFormatter"/&gt;
+    </pre>
+    <p>
+      If you are planning to run sample 440, you should also add the above two entries
+      to the 'samples/axis2Client/client_repo/conf/axis2.xml' file.
+    </p>    
+    <p/>
     <h2 id="derby">
       Setting up Derby database server
     </h2>