diff options
author | nash <nash@13f79535-47bb-0310-9956-ffa450edef68> | 2010-10-26 08:46:33 +0000 |
---|---|---|
committer | nash <nash@13f79535-47bb-0310-9956-ffa450edef68> | 2010-10-26 08:46:33 +0000 |
commit | 6f23eadf23acaaf2b9959ea53388b6e60a2d309a (patch) | |
tree | 493bfb570e59eabf8e99094fc10585d28166c920 /sca-java-1.x/trunk | |
parent | 758114996eea515967ae25389b8349c7cf573c19 (diff) |
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
Diffstat (limited to 'sca-java-1.x/trunk')
6 files changed, 135 insertions, 33 deletions
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 @@ -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> 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( + "<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); 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 @@ </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>
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 @@ -<?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>
|