From 6f23eadf23acaaf2b9959ea53388b6e60a2d309a Mon Sep 17 00:00:00 2001 From: nash Date: Tue, 26 Oct 2010 08:46:33 +0000 Subject: Merge r1001526 TUSCANY-3690: Handle unavailability of live RSS feed or web service by using historical data git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1027405 13f79535-47bb-0310-9956-ffa450edef68 --- sca-java-1.x/trunk/demos/xml-bigbank/README | 3 +- sca-java-1.x/trunk/demos/xml-bigbank/pom.xml | 17 ++++- .../src/main/java/bigbank/AccountServiceImpl.java | 55 ++++++++++++++-- .../src/main/java/bigbank/ExchangeRateImpl.java | 14 +++- .../src/main/resources/BigBank.composite | 3 +- .../src/main/resources/wsdl/StockQuotes.wsdl | 76 +++++++++++++++------- 6 files changed, 135 insertions(+), 33 deletions(-) (limited to 'sca-java-1.x/trunk') diff --git a/sca-java-1.x/trunk/demos/xml-bigbank/README b/sca-java-1.x/trunk/demos/xml-bigbank/README index 3bdeeca60a..dca80898f1 100644 --- a/sca-java-1.x/trunk/demos/xml-bigbank/README +++ b/sca-java-1.x/trunk/demos/xml-bigbank/README @@ -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. diff --git a/sca-java-1.x/trunk/demos/xml-bigbank/pom.xml b/sca-java-1.x/trunk/demos/xml-bigbank/pom.xml index bd9f3dcf8a..8f8335ca41 100644 --- a/sca-java-1.x/trunk/demos/xml-bigbank/pom.xml +++ b/sca-java-1.x/trunk/demos/xml-bigbank/pom.xml @@ -37,6 +37,18 @@ 1.7-SNAPSHOT + + rome + rome + 0.9 + + + + log4j + log4j + 1.2.13 + + org.apache.tuscany.sca tuscany-implementation-java-runtime @@ -48,14 +60,14 @@ org.apache.tuscany.sca tuscany-binding-ws-axis2 1.7-SNAPSHOT - compile + runtime org.apache.tuscany.sca tuscany-binding-rss-rome 1.7-SNAPSHOT - compile + runtime @@ -65,7 +77,6 @@ runtime - org.apache.tuscany.sca tuscany-implementation-xquery diff --git a/sca-java-1.x/trunk/demos/xml-bigbank/src/main/java/bigbank/AccountServiceImpl.java b/sca-java-1.x/trunk/demos/xml-bigbank/src/main/java/bigbank/AccountServiceImpl.java index 00fce39462..46995de393 100644 --- a/sca-java-1.x/trunk/demos/xml-bigbank/src/main/java/bigbank/AccountServiceImpl.java +++ b/sca-java-1.x/trunk/demos/xml-bigbank/src/main/java/bigbank/AccountServiceImpl.java @@ -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 implements AccountService { 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( + ""+ + ""+ + "IBM"+ + "134.11"+ + "9/24/2010"+ + ""+ + "+2.44"+ + "132.42"+ + "134.15"+ + "132.34"+ + "7122325"+ + "169.1B"+ + "131.67"+ + "+1.85%"+ + "116.00 - 134.25"+ + "10.582"+ + "12.44"+ + "International Bus"+ + ""+ + "")); + } - 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); diff --git a/sca-java-1.x/trunk/demos/xml-bigbank/src/main/java/bigbank/ExchangeRateImpl.java b/sca-java-1.x/trunk/demos/xml-bigbank/src/main/java/bigbank/ExchangeRateImpl.java index fcb3707cfe..11c300cd3c 100644 --- a/sca-java-1.x/trunk/demos/xml-bigbank/src/main/java/bigbank/ExchangeRateImpl.java +++ b/sca-java-1.x/trunk/demos/xml-bigbank/src/main/java/bigbank/ExchangeRateImpl.java @@ -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(); diff --git a/sca-java-1.x/trunk/demos/xml-bigbank/src/main/resources/BigBank.composite b/sca-java-1.x/trunk/demos/xml-bigbank/src/main/resources/BigBank.composite index 8afde4bf80..18f848fdcb 100644 --- a/sca-java-1.x/trunk/demos/xml-bigbank/src/main/resources/BigBank.composite +++ b/sca-java-1.x/trunk/demos/xml-bigbank/src/main/resources/BigBank.composite @@ -45,7 +45,8 @@ - + + diff --git a/sca-java-1.x/trunk/demos/xml-bigbank/src/main/resources/wsdl/StockQuotes.wsdl b/sca-java-1.x/trunk/demos/xml-bigbank/src/main/resources/wsdl/StockQuotes.wsdl index 8411e22ff7..26000e4480 100644 --- a/sca-java-1.x/trunk/demos/xml-bigbank/src/main/resources/wsdl/StockQuotes.wsdl +++ b/sca-java-1.x/trunk/demos/xml-bigbank/src/main/resources/wsdl/StockQuotes.wsdl @@ -1,23 +1,53 @@ - - - - - \ No newline at end of file + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- cgit v1.2.3