You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by na...@apache.org on 2010/10/26 10:46:34 UTC

svn commit: r1027405 - in /tuscany/sca-java-1.x/trunk/demos/xml-bigbank: README pom.xml src/main/java/bigbank/AccountServiceImpl.java src/main/java/bigbank/ExchangeRateImpl.java src/main/resources/BigBank.composite src/main/resources/wsdl/StockQuotes.wsdl

Author: nash
Date: Tue Oct 26 08:46:33 2010
New Revision: 1027405

URL: http://svn.apache.org/viewvc?rev=1027405&view=rev
Log:
Merge r1001526 TUSCANY-3690: Handle unavailability of live RSS feed or web service by using historical data

Modified:
    tuscany/sca-java-1.x/trunk/demos/xml-bigbank/README
    tuscany/sca-java-1.x/trunk/demos/xml-bigbank/pom.xml
    tuscany/sca-java-1.x/trunk/demos/xml-bigbank/src/main/java/bigbank/AccountServiceImpl.java
    tuscany/sca-java-1.x/trunk/demos/xml-bigbank/src/main/java/bigbank/ExchangeRateImpl.java
    tuscany/sca-java-1.x/trunk/demos/xml-bigbank/src/main/resources/BigBank.composite
    tuscany/sca-java-1.x/trunk/demos/xml-bigbank/src/main/resources/wsdl/StockQuotes.wsdl

Modified: tuscany/sca-java-1.x/trunk/demos/xml-bigbank/README
URL: http://svn.apache.org/viewvc/tuscany/sca-java-1.x/trunk/demos/xml-bigbank/README?rev=1027405&r1=1027404&r2=1027405&view=diff
==============================================================================
--- tuscany/sca-java-1.x/trunk/demos/xml-bigbank/README (original)
+++ tuscany/sca-java-1.x/trunk/demos/xml-bigbank/README Tue Oct 26 08:46:33 2010
@@ -3,7 +3,8 @@ XML BigBank Demo
 
 This demo showcases the integration with XML technolgies in the service assembly.
 
-Note: The live stock quote web service is not always running. Sometimes empty response is returned and the stock value is 0.
+Note: The live currency exchange rate RSS feed and the live stock quote web service are not always running.
+When this happens, the demo code uses historical data instead of live data.
 
 To run the demo, type "ant run" and it will produce the following output.
 

Modified: tuscany/sca-java-1.x/trunk/demos/xml-bigbank/pom.xml
URL: http://svn.apache.org/viewvc/tuscany/sca-java-1.x/trunk/demos/xml-bigbank/pom.xml?rev=1027405&r1=1027404&r2=1027405&view=diff
==============================================================================
--- tuscany/sca-java-1.x/trunk/demos/xml-bigbank/pom.xml (original)
+++ tuscany/sca-java-1.x/trunk/demos/xml-bigbank/pom.xml Tue Oct 26 08:46:33 2010
@@ -38,6 +38,18 @@
         </dependency>
 
         <dependency>
+            <groupId>rome</groupId>
+            <artifactId>rome</artifactId>
+            <version>0.9</version>
+        </dependency>
+
+        <dependency>
+            <groupId>log4j</groupId>
+            <artifactId>log4j</artifactId>
+            <version>1.2.13</version>
+        </dependency>
+
+        <dependency>
             <groupId>org.apache.tuscany.sca</groupId>
             <artifactId>tuscany-implementation-java-runtime</artifactId>
             <version>1.7-SNAPSHOT</version>
@@ -48,14 +60,14 @@
             <groupId>org.apache.tuscany.sca</groupId>
             <artifactId>tuscany-binding-ws-axis2</artifactId>
             <version>1.7-SNAPSHOT</version>
-            <scope>compile</scope>
+            <scope>runtime</scope>
         </dependency>
 
         <dependency>
             <groupId>org.apache.tuscany.sca</groupId>
             <artifactId>tuscany-binding-rss-rome</artifactId>
             <version>1.7-SNAPSHOT</version>
-            <scope>compile</scope>
+            <scope>runtime</scope>
         </dependency>
 
         <dependency>
@@ -65,7 +77,6 @@
             <scope>runtime</scope>
         </dependency>
 
-
         <dependency>
             <groupId>org.apache.tuscany.sca</groupId>
             <artifactId>tuscany-implementation-xquery</artifactId>

Modified: tuscany/sca-java-1.x/trunk/demos/xml-bigbank/src/main/java/bigbank/AccountServiceImpl.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-1.x/trunk/demos/xml-bigbank/src/main/java/bigbank/AccountServiceImpl.java?rev=1027405&r1=1027404&r2=1027405&view=diff
==============================================================================
--- tuscany/sca-java-1.x/trunk/demos/xml-bigbank/src/main/java/bigbank/AccountServiceImpl.java (original)
+++ tuscany/sca-java-1.x/trunk/demos/xml-bigbank/src/main/java/bigbank/AccountServiceImpl.java Tue Oct 26 08:46:33 2010
@@ -25,6 +25,9 @@ import javax.xml.stream.XMLInputFactory;
 import javax.xml.stream.XMLStreamReader;
 
 import org.apache.axiom.om.OMElement;
+import org.apache.log4j.Level;
+import org.apache.log4j.LogManager;
+import org.apache.log4j.spi.LoggerRepository;
 import org.osoa.sca.ServiceRuntimeException;
 import org.osoa.sca.annotations.Property;
 import org.osoa.sca.annotations.Reference;
@@ -65,11 +68,55 @@ public class AccountServiceImpl implemen
             System.out.println("Getting stock quote...");
             XMLStreamReader request = factory.createXMLStreamReader(new StringReader(STOCK_QUOTE_REQUEST));
 
-            OMElement quotes = stockQuote.GetQuote(request);
+            // temporarily disable INFO logging before calling the web service
+            LoggerRepository repository = LogManager.getLoggerRepository();
+            Level threshold = repository.getThreshold();
+            repository.setThreshold(Level.WARN);
+
+            // first try to get a live stock quote from the web service
+            String xml = null;
+            try {
+                OMElement quotes = stockQuote.GetQuote(request);
+                xml = quotes.getText();
+            } catch (Exception e) {
+            
+            // restore the previous logging setting
+            } finally {
+                repository.setThreshold(threshold);
+            }
+
+            // if the web service invocation was successful, process the response
+            XMLStreamReader qts = null;
+            if (xml != null && xml.startsWith("<")) {
+                System.out.println(xml);
+                qts = factory.createXMLStreamReader(new StringReader(xml));
+
+            // if the web service isn't responding, continue with the demo using historical data 
+            } else {
+                System.out.println("Stock price live quote not available, using historical data");
+                qts = factory.createXMLStreamReader(new StringReader(
+                        "<StockQuotes>"+
+                          "<Stock>"+
+                            "<Symbol>IBM</Symbol>"+
+                            "<Last>134.11</Last>"+
+                            "<Date>9/24/2010</Date>"+
+                            "<Time>4:00pm</Time>"+
+                            "<Change>+2.44</Change>"+
+                            "<Open>132.42</Open>"+
+                            "<High>134.15</High>"+
+                            "<Low>132.34</Low>"+
+                            "<Volume>7122325</Volume>"+
+                            "<MktCap>169.1B</MktCap>"+
+                            "<PreviousClose>131.67</PreviousClose>"+
+                            "<PercentageChange>+1.85%</PercentageChange>"+
+                            "<AnnRange>116.00 - 134.25</AnnRange>"+
+                            "<Earns>10.582</Earns>"+
+                            "<P-E>12.44</P-E>"+
+                            "<Name>International Bus</Name>"+
+                          "</Stock>"+
+                        "</StockQuotes>"));
+            }
 
-            String xml = quotes.getText();
-            System.out.println(xml);
-            XMLStreamReader qts = factory.createXMLStreamReader(new StringReader(xml));
             System.out.println("Calculating total value...");
             double value = stockValue.calculate(qts, accounts);
 

Modified: tuscany/sca-java-1.x/trunk/demos/xml-bigbank/src/main/java/bigbank/ExchangeRateImpl.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-1.x/trunk/demos/xml-bigbank/src/main/java/bigbank/ExchangeRateImpl.java?rev=1027405&r1=1027404&r2=1027405&view=diff
==============================================================================
--- tuscany/sca-java-1.x/trunk/demos/xml-bigbank/src/main/java/bigbank/ExchangeRateImpl.java (original)
+++ tuscany/sca-java-1.x/trunk/demos/xml-bigbank/src/main/java/bigbank/ExchangeRateImpl.java Tue Oct 26 08:46:33 2010
@@ -65,7 +65,19 @@ public class ExchangeRateImpl {
     public double getExchangeRate(String currency) {
         try {
             System.out.println("Retrieving exchange rate...");
-            SyndFeed feed = exchangeRate.getRates();
+
+            // first try to get a live exchange rate quote from the RSS feed
+            SyndFeed feed = null;
+            try {
+                feed = exchangeRate.getRates();
+
+            // if the RSS feed isn't responding, continue with the demo using historical data 
+            } catch (Exception e) {
+                System.out.println("Exchange rate live quote not available, using historical data");
+                return 0.74107;
+            }
+
+            // extract the exchange rate from the feed data
             SyndEntry entry = (SyndEntry)feed.getEntries().get(0);
             String rateTable = entry.getDescription().getValue();
 

Modified: tuscany/sca-java-1.x/trunk/demos/xml-bigbank/src/main/resources/BigBank.composite
URL: http://svn.apache.org/viewvc/tuscany/sca-java-1.x/trunk/demos/xml-bigbank/src/main/resources/BigBank.composite?rev=1027405&r1=1027404&r2=1027405&view=diff
==============================================================================
--- tuscany/sca-java-1.x/trunk/demos/xml-bigbank/src/main/resources/BigBank.composite (original)
+++ tuscany/sca-java-1.x/trunk/demos/xml-bigbank/src/main/resources/BigBank.composite Tue Oct 26 08:46:33 2010
@@ -45,7 +45,8 @@
     </component>
 
     <reference name="StockQuoteReference" promote="AccountService/stockQuote">
-        <binding.ws wsdlElement="http://www.webserviceX.NET/#wsdl.port(StockQuote/StockQuoteSoap)" />
+        <binding.ws wsdlElement="http://bigbank/#wsdl.port(StockQuoteService/StockQuotePort)" />
+        <!--binding.ws wsdlElement="http://www.webserviceX.NET/#wsdl.port(StockQuote/StockQuoteSoap)" /-->
     </reference>
 
 </composite>

Modified: tuscany/sca-java-1.x/trunk/demos/xml-bigbank/src/main/resources/wsdl/StockQuotes.wsdl
URL: http://svn.apache.org/viewvc/tuscany/sca-java-1.x/trunk/demos/xml-bigbank/src/main/resources/wsdl/StockQuotes.wsdl?rev=1027405&r1=1027404&r2=1027405&view=diff
==============================================================================
--- tuscany/sca-java-1.x/trunk/demos/xml-bigbank/src/main/resources/wsdl/StockQuotes.wsdl (original)
+++ tuscany/sca-java-1.x/trunk/demos/xml-bigbank/src/main/resources/wsdl/StockQuotes.wsdl Tue Oct 26 08:46:33 2010
@@ -1,23 +1,53 @@
-<?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.    
--->
-<wsdl:definitions targetNamespace="http://www.webserviceX.NET/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
-    <wsdl:import namespace="http://www.webserviceX.NET/"
-        location="http://www.webservicex.com/stockquote.asmx?WSDL" />
-</wsdl:definitions>
\ No newline at end of file
+<?xml version="1.0" encoding="UTF-8" ?> 
+<wsdl:definitions name="StockQuoteService" targetNamespace="http://bigbank/" xmlns:tns="http://bigbank/"
+      xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xs="http://www.w3.org/2001/XMLSchema"
+      xmlns:wsx="http://www.webserviceX.NET/" xmlns:SOAP="http://schemas.xmlsoap.org/wsdl/soap/">
+  <wsdl:types>
+    <xs:schema attributeFormDefault="qualified" elementFormDefault="unqualified"
+        targetNamespace="http://www.webserviceX.NET/" xmlns:xs="http://www.w3.org/2001/XMLSchema">
+      <xs:element name="GetQuoteResponse">
+        <xs:complexType>
+          <xs:sequence>
+            <xs:element minOccurs="0" name="return" nillable="true" type="xs:string" /> 
+          </xs:sequence>
+        </xs:complexType>
+      </xs:element>
+      <xs:element name="GetQuote">
+        <xs:complexType>
+          <xs:sequence>
+            <xs:element minOccurs="0" name="GetQuoteResult" nillable="true" type="xs:string" /> 
+          </xs:sequence>
+        </xs:complexType>
+      </xs:element>
+    </xs:schema>
+  </wsdl:types>
+  <wsdl:message name="GetQuoteResponse">
+    <wsdl:part name="GetQuoteResponse" element="wsx:GetQuoteResponse" /> 
+  </wsdl:message>
+  <wsdl:message name="GetQuote">
+    <wsdl:part name="GetQuote" element="wsx:GetQuote" /> 
+  </wsdl:message>
+  <wsdl:portType name="StockQuote">
+    <wsdl:operation name="GetQuote">
+      <wsdl:input message="tns:GetQuote" /> 
+      <wsdl:output message="tns:GetQuoteResponse" /> 
+    </wsdl:operation>
+  </wsdl:portType>
+  <wsdl:binding name="StockQuoteBinding" type="tns:StockQuote">
+    <SOAP:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" /> 
+    <wsdl:operation name="GetQuote">
+      <SOAP:operation soapAction="http://www.webserviceX.NET/GetQuote" /> 
+      <wsdl:input>
+        <SOAP:body use="literal" /> 
+      </wsdl:input>
+      <wsdl:output>
+        <SOAP:body use="literal" /> 
+      </wsdl:output>
+    </wsdl:operation>
+  </wsdl:binding>
+  <wsdl:service name="StockQuoteService">
+    <wsdl:port name="StockQuotePort" binding="tns:StockQuoteBinding">
+      <SOAP:address location="http://www.webservicex.net/stockquote.asmx" /> 
+    </wsdl:port>
+  </wsdl:service>
+</wsdl:definitions>