cocoon-docs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@cocoon.apache.org
Subject [Cocoon Wiki] Updated: FlowAndWebServices
Date Wed, 28 Jul 2004 18:07:31 GMT
   Date: 2004-07-28T11:07:31
   Editor: ReinhardPoetz <reinhard@apache.org>
   Wiki: Cocoon Wiki
   Page: FlowAndWebServices
   URL: http://wiki.apache.org/cocoon/FlowAndWebServices

   add latest discussion

Change Log:

------------------------------------------------------------------------------
@@ -5,89 +5,89 @@
 Why is this needed?
 Well for some web services such as services that return stock quotes or search results the
WebServiceProxyGenerator is probably better suited. However for more transactional orientated
web services it could be very usefull. Consider the following simple example flow script for
placing an order using a web service.
 
-{{{
-
-// initialize some global varibles
-var partnerId = 443;
-
-// load a webservice given the uri of the wsdl file
-var bookshop = loadWebService('http://books.biz/ws/orderservice?WSDL');
-var parcelService = loadWebService('http://shipping.com/ws/parcelservice?WSDL');
-
-// define the prototype for a book object
-Book.prototype.isbn
-Book.prototype.price
-
-function placeOrder(){
-
-  var userId = cocoon.session['userId'];
-  var book = new Book();
-  var quantity = 0;
-  
-  while(true){
-    
-    // populate the book object
-    book.isbn = cocoon.request['isbn'];
-    quantity = cocoon.request['quantity'];    
-
-    // check to see if the book is in stock
-    var stockCheck = bookshop.checkStock(book.isbn,quantity);
-
-    // update the books price
-    book.price = stockCheck.pricePerItem;
-
-    // if there are enough books in stock break this loop
-    if(stockCheck.number >= quantity) break;
-
-    // if there are no copies available
-    if(stockCheck.number == 0){
-      // send a page saying sorry
-      cocoon.sendPage('view/sorry.jx',
-        {message:'Sorry, but the book is sold out'});
-      // exit this order
-      return;
-    }
-
-    // otherwise, tell the user they must modify the order
-    var message = 'Sorry we do not have enough copies. '
-      + 'We only have ' + stockCheck.number + ' in stock. '
-      + 'Please modify your order. ';
-
-    cocoon.sendPageAndWait('view/editOrder.jx', 
-      {book:book, message:message);
-
-  }
-
-  cocoon.sendPageAndWait('view/deliveryAddress.jx');
-  
-  var deliveryAddress = cocoon.request['address'];
-
-  // use the parcel service to calc the shipping costs
-  var shippingInfo = parcelService.calculateShippingCost(
-    {class:1, type:'book', quantity:quantity, address: deliveryAddress}); 
-
-  var totalCost = quantity * book.price;
-
-  if(totalCost < 50){
-    // for orders under £50 add post and packaging
-    totalCost += shippingInfo.cost;
-    totalCost += quantity * 0.5; 
-  }
-
-  // ask the user to confirm the order
-  cocoon.sendPageAndWait('view/confirm.jx',
-    {book:book,total:totalCost});
-
-  // go ahead and place the order
-  var order = bookshop.placeOrder(partnerId,userId,
-    {order:{isbn:book.isbn, quantity:quantity}},shippingInfo.trackingId);
-
-  // now send a success page
-  cocoon.sendPage('view/done.jx',
-    {order:order,tracking:shippingInfo.trackingId});
-
-}
-
+{{{
+
+// initialize some global varibles
+var partnerId = 443;
+
+// load a webservice given the uri of the wsdl file
+var bookshop = loadWebService('http://books.biz/ws/orderservice?WSDL');
+var parcelService = loadWebService('http://shipping.com/ws/parcelservice?WSDL');
+
+// define the prototype for a book object
+Book.prototype.isbn
+Book.prototype.price
+
+function placeOrder(){
+
+  var userId = cocoon.session['userId'];
+  var book = new Book();
+  var quantity = 0;
+  
+  while(true){
+    
+    // populate the book object
+    book.isbn = cocoon.request['isbn'];
+    quantity = cocoon.request['quantity'];    
+
+    // check to see if the book is in stock
+    var stockCheck = bookshop.checkStock(book.isbn,quantity);
+
+    // update the books price
+    book.price = stockCheck.pricePerItem;
+
+    // if there are enough books in stock break this loop
+    if(stockCheck.number >= quantity) break;
+
+    // if there are no copies available
+    if(stockCheck.number == 0){
+      // send a page saying sorry
+      cocoon.sendPage('view/sorry.jx',
+        {message:'Sorry, but the book is sold out'});
+      // exit this order
+      return;
+    }
+
+    // otherwise, tell the user they must modify the order
+    var message = 'Sorry we do not have enough copies. '
+      + 'We only have ' + stockCheck.number + ' in stock. '
+      + 'Please modify your order. ';
+
+    cocoon.sendPageAndWait('view/editOrder.jx', 
+      {book:book, message:message);
+
+  }
+
+  cocoon.sendPageAndWait('view/deliveryAddress.jx');
+  
+  var deliveryAddress = cocoon.request['address'];
+
+  // use the parcel service to calc the shipping costs
+  var shippingInfo = parcelService.calculateShippingCost(
+    {class:1, type:'book', quantity:quantity, address: deliveryAddress}); 
+
+  var totalCost = quantity * book.price;
+
+  if(totalCost < 50){
+    // for orders under £50 add post and packaging
+    totalCost += shippingInfo.cost;
+    totalCost += quantity * 0.5; 
+  }
+
+  // ask the user to confirm the order
+  cocoon.sendPageAndWait('view/confirm.jx',
+    {book:book,total:totalCost});
+
+  // go ahead and place the order
+  var order = bookshop.placeOrder(partnerId,userId,
+    {order:{isbn:book.isbn, quantity:quantity}},shippingInfo.trackingId);
+
+  // now send a success page
+  cocoon.sendPage('view/done.jx',
+    {order:order,tracking:shippingInfo.trackingId});
+
+}
+
 }}}
 
 ===  Data type mapping. ===
@@ -133,3 +133,4 @@
 ===  Discussions on Cocoon Dev Mailinglist ===
  *  [http://marc.theaimsgroup.com/?l=xml-cocoon-dev&m=107609041818163&w=2]
  *  [http://marc.theaimsgroup.com/?t=106432248900006&r=1&w=2]
+ *  [http://marc.theaimsgroup.com/?t=109085126300004&r=1&w=2], July 2004

Mime
View raw message