Author: asankha
Date: Wed Nov 22 22:01:55 2006
New Revision: 478478

URL: http://svn.apache.org/viewvc?view=rev&rev=478478
Log:
Fix SYNAPSE-38 (fireAndForget) and add a sample and documentation

Added:
    
incubator/synapse/trunk/java/modules/samples/src/main/java/samples/userguide/PlaceOrderClient.java
Modified:
    
incubator/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2FlexibleMEPClient.java
    
incubator/synapse/trunk/java/modules/samples/src/main/java/samples/common/StockQuoteHandler.java
    incubator/synapse/trunk/java/modules/samples/src/main/scripts/build.xml
    incubator/synapse/trunk/java/src/site/resources/Synapse_Samples.html

Modified: 
incubator/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2FlexibleMEPClient.java
URL: 
http://svn.apache.org/viewvc/incubator/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2FlexibleMEPClient.java?view=diff&rev=478478&r1=478477&r2=478478
==============================================================================
--- 
incubator/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2FlexibleMEPClient.java
 (original)
+++ 
incubator/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2FlexibleMEPClient.java
 Wed Nov 22 22:01:55 2006
@@ -146,13 +146,16 @@
             MessageContext responseReceived =
                 
mepClient.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
 
-            MessageContext response = 
Utils.createOutMessageContext(originalInMsgCtx);
-            response.setEnvelope(removeAddressingHeaders(responseReceived));
+            if (responseReceived != null && responseReceived.getEnvelope() != 
null) {
+                MessageContext response = 
Utils.createOutMessageContext(originalInMsgCtx);
+                
response.setEnvelope(removeAddressingHeaders(responseReceived));
+                response.setServerSide(true);
+                response.setProperty(Constants.ISRESPONSE_PROPERTY, 
Boolean.TRUE);
+                return response;
 
-            response.setServerSide(true);
-            response.setProperty(Constants.ISRESPONSE_PROPERTY, Boolean.TRUE);
-
-            return response;
+            } else {
+                return null;
+            }
         }
     }
 

Modified: 
incubator/synapse/trunk/java/modules/samples/src/main/java/samples/common/StockQuoteHandler.java
URL: 
http://svn.apache.org/viewvc/incubator/synapse/trunk/java/modules/samples/src/main/java/samples/common/StockQuoteHandler.java?view=diff&rev=478478&r1=478477&r2=478478
==============================================================================
--- 
incubator/synapse/trunk/java/modules/samples/src/main/java/samples/common/StockQuoteHandler.java
 (original)
+++ 
incubator/synapse/trunk/java/modules/samples/src/main/java/samples/common/StockQuoteHandler.java
 Wed Nov 22 22:01:55 2006
@@ -91,6 +91,39 @@
     }
 
     /**
+     * Create a new order for a quantiry of a stock at a given price
+     * <m:placeOrder xmlns:m="http://services.samples/xsd";>
+     *   <m:order>
+     *       <m:price>3.141593E0</m:price>
+     *       <m:quantity>4</m:quantity>
+     *       <m:symbol>IBM</m:symbol>
+     *    </m:order>
+     *         </m:placeOrder>
+     *
+     * @param purchPrice the purchase price
+     * @param qty the quantiry
+     * @param symbol the stock
+     * @return an OMElement payload for the order
+     */
+    public static OMElement createPlaceOrderPayload(double purchPrice, int 
qty, String symbol) {
+        OMFactory factory   = OMAbstractFactory.getOMFactory();
+        OMNamespace ns      = 
factory.createOMNamespace("http://services.samples/xsd";, "m0");
+        OMElement placeOrder= factory.createOMElement("placeOrder", ns);
+        OMElement order     = factory.createOMElement("order", ns);
+        OMElement price     = factory.createOMElement("price", ns);
+        OMElement quantity  = factory.createOMElement("quantity", ns);
+        OMElement symb      = factory.createOMElement("symbol", ns);
+        price.setText(Double.toString(purchPrice));
+        quantity.setText(Integer.toString(qty));
+        symb.setText(symbol);
+        order.addChild(price);
+        order.addChild(quantity);
+        order.addChild(symb);
+        placeOrder.addChild(order);        
+        return placeOrder;
+    }
+
+    /**
      * Digests the standard StockQuote response and extracts the last trade 
price
      * @param result
      * @return

Added: 
incubator/synapse/trunk/java/modules/samples/src/main/java/samples/userguide/PlaceOrderClient.java
URL: 
http://svn.apache.org/viewvc/incubator/synapse/trunk/java/modules/samples/src/main/java/samples/userguide/PlaceOrderClient.java?view=auto&rev=478478
==============================================================================
--- 
incubator/synapse/trunk/java/modules/samples/src/main/java/samples/userguide/PlaceOrderClient.java
 (added)
+++ 
incubator/synapse/trunk/java/modules/samples/src/main/java/samples/userguide/PlaceOrderClient.java
 Wed Nov 22 22:01:55 2006
@@ -0,0 +1,67 @@
+/*
+ *  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.
+ */
+package samples.userguide;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axis2.client.Options;
+import org.apache.axis2.client.ServiceClient;
+import org.apache.axis2.Constants;
+import samples.common.StockQuoteHandler;
+
+public class PlaceOrderClient {
+
+    public static void main(String[] args) {
+
+        String symbol  = "IBM";
+        String turl    = "http://localhost:8080/StockQuote";;
+        String sAction = "urn:placeOrder";
+
+        if (args.length > 0) symbol = args[0];
+        if (args.length > 1) turl   = args[1];
+
+        try {
+            double price = getRandom(100, 0.9, true);
+            int quantity = (int) getRandom(10000, 1.0, true);
+            OMElement placeOrder =
+                StockQuoteHandler.createPlaceOrderPayload(price, quantity, 
symbol);
+
+            Options options = new Options();
+            options.setProperty(Constants.Configuration.TRANSPORT_URL, turl);
+            options.setAction(sAction);
+
+            ServiceClient serviceClient = new ServiceClient();
+            serviceClient.setOptions(options);
+
+            serviceClient.fireAndForget(placeOrder);
+            Thread.sleep(5000);
+            
+            System.out.println("Order placed for " + quantity + " shares of 
stock " +
+                symbol + " at a price of $ " + price);
+
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    private static double getRandom(double base, double varience, boolean 
onlypositive) {
+        double rand = Math.random();
+        return (base + ((rand > 0.5 ? 1 : -1) * varience * base * rand))
+            * (onlypositive ? 1 : (rand > 0.5 ? 1 : -1));
+    }
+}

Modified: 
incubator/synapse/trunk/java/modules/samples/src/main/scripts/build.xml
URL: 
http://svn.apache.org/viewvc/incubator/synapse/trunk/java/modules/samples/src/main/scripts/build.xml?view=diff&rev=478478&r1=478477&r2=478478
==============================================================================
--- incubator/synapse/trunk/java/modules/samples/src/main/scripts/build.xml 
(original)
+++ incubator/synapse/trunk/java/modules/samples/src/main/scripts/build.xml Wed 
Nov 22 22:01:55 2006
@@ -32,48 +32,58 @@
     ant compile 
                build the samples
 
-       These samples make stockquote requests to the sample services through 
Synapse
+       These client samples are able to send stock quote and order placement 
messages
 
        ant stockquote
-               Use the smart client - Synapse in WS-Addressing router mode
-               Use default sample configuration (i.e. start with -sample 0)
-    
-         examples:
+         This could be used to act as a 'smart client' for Synapse, by 
specifying an
+      WS-Addressing EPR directed to the real endpoint, and the transport 
endpoint
+      set to Synapse
+
+      examples:
          ant stockquote
          ant stockquote [-Dsymbol=IBM] 
                
[-Durl=http://localhost:9000/axis2/services/SimpleStockQuoteService]
                [-Dsynapseurl=http://localhost:8080] [-Drepository=client_repo]
         
[-Dsecpolicy=..\..\repository\conf\sample\resources\policy\policy_1.xml]
 
-      ant proxystockquote
-           Use the http proxy client - Synapse in "transparent mode" as an 
HTTP proxy
-           Use default sample configuration (i.e. start with -sample 0)
+    ant proxystockquote
+      A client that could set Synapse as its HTTP proxy when sending requests
     
-               examples:
+         examples:
          ant proxystockquote
-         ant proxystockquote [-Dsymbol=IBM] 
+         ant proxystockquote [-Dsymbol=IBM]
                
[-Durl=http://localhost:9000/axis2/services/SimpleStockQuoteService]
                [-Dsynapseurl=http://localhost:8080]
 
-    ant dumbstockquote 
-      Use the dumb soap client - Synapse in "gateway" mode; transport set to 
virtual
-      url which is interpreted by Synapse
-      Use default sample configuration (i.e. start with -sample 0)
+    ant dumbstockquote
+      A client that could directly invoke the service on a given endpoint. 
Could be
+      used to test Synapse as a 'gateway'
   
          examples:
-               ant dumbstockquote 
-           ant dumbstockquote [-Dsymbol=IBM] 
[-Dgatewayurl=http://localhost:8080/StockQuote]
+         ant dumbstockquote
+         ant dumbstockquote [-Dsymbol=IBM]
+        [-Dhttp://localhost:8080/axis2/services/StockQuoteProxy]
         
[-Dsecpolicy=..\..\repository\conf\sample\resources\policy\policy_1.xml]
 
     ant customquote 
-      Use a custom stock quote request and response format, and transform 
(XSLT) between
-      Use sample configuration #1 (i.e. start with -sample 1)
+      A client which could send out a stock quote request in a custom format. 
Synapse is
+      expected to transform this message to a standard request, and the 
response back as
+      a custom response as expected by this client
   
-               examples:
+         examples:
                ant customquote 
            ant customquote [-Dsymbol=IBM] 
                
[-Durl=http://localhost:9000/axis2/services/SimpleStockQuoteService]
                [-Dsynapseurl=http://localhost:8080]
+
+    ant placeorder
+      A client which could send out a one way message using the Axis2 
ServiceClient's
+      fireAndForget() API
+
+      examples:
+               ant placeorder
+           ant placeorder 
+        [-Dsymbol=IBM] 
[-Dgatewayurl=http://localhost:8080/axis2/services/StockQuoteProxy]
         </echo>
     </target>
 
@@ -133,6 +143,14 @@
                <arg value="${symbol}"/>
             <arg value="${url}"/>
             <arg value="${synapseurl}"/>
+        </java>
+    </target>
+
+    <target name="placeorder" depends="compile">
+        <java classname="samples.userguide.PlaceOrderClient"
+              classpathref="javac.classpath" fork="true">
+               <arg value="${symbol}"/>
+            <arg value="${gatewayurl}"/>
         </java>
     </target>
 

Modified: incubator/synapse/trunk/java/src/site/resources/Synapse_Samples.html
URL: 
http://svn.apache.org/viewvc/incubator/synapse/trunk/java/src/site/resources/Synapse_Samples.html?view=diff&rev=478478&r1=478477&r2=478478
==============================================================================
--- incubator/synapse/trunk/java/src/site/resources/Synapse_Samples.html 
(original)
+++ incubator/synapse/trunk/java/src/site/resources/Synapse_Samples.html Wed 
Nov 22 22:01:55 2006
@@ -751,5 +751,28 @@
 received messages to the above EPR using JMS, and sends back the response to
 the client over HTTP once the simple stock quote service responds with the
 stock quote reply over JMS to the Synapse server.</p>
+
+<p></p>
+
+<h2>Sample 112:</h2>
+
+<p><strong>Objective: Demonstrate one way messaging /
+fireAndForget()</strong></p>
+
+<p><strong>Pre-Requisites:</strong><br>
+Start the Axis2 server and deploy the SimpleStockQuoteService (Refer steps
+above)<br>
+Start the Synapse configuration numbered 1: i.e. synapse -sample 1</p>
+
+<p>This example invokes the one-way 'placeOrder' operation on the
+SimpleStockQuoteService using the custom client which uses the Axis2
+ServiceClient.fireAndForget() API. To test this, use 'ant placeorder' and you
+will notice the one way message flowing through Synapse into the sample Axis2
+server instance, which reports the acceptance of the order as follows:</p>
+<pre>SimpleStockQuoteService :: Accepted order for : 7482 stocks of IBM at $ 
169.27205579038733</pre>
+
+<p>If you send your client request through TCPmon, you will notice that the
+SimpleStockQuoteService replies to Synapse with a HTTP 202 reply, and that
+Synapse in-turn replies to the client with a HTTP 202 acknowledgement.</p>
 </body>
 </html>



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to