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:56:52 UTC

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

Author: nash
Date: Tue Oct 26 08:56:52 2010
New Revision: 1027408

URL: http://svn.apache.org/viewvc?rev=1027408&view=rev
Log:
Merge r1001690 TUSCANY-3690: Improve error handling and fix problems with local WSDL

Modified:
    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/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/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=1027408&r1=1027407&r2=1027408&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:56:52 2010
@@ -78,7 +78,17 @@ public class AccountServiceImpl implemen
             try {
                 OMElement quotes = stockQuote.GetQuote(request);
                 xml = quotes.getText();
+                if (!xml.startsWith("<")) {
+                    System.out.println("Server responded: " + xml);
+                    throw new IllegalStateException("Unexpected response from server");
+                }
             } catch (Exception e) {
+                if (e.getMessage().contains("Transport error: 503")) {
+                    // server is down, use local historical data
+                } else {
+                    // report any other errors
+                    throw e;
+                }
             
             // restore the previous logging setting
             } finally {
@@ -87,8 +97,8 @@ public class AccountServiceImpl implemen
 
             // if the web service invocation was successful, process the response
             XMLStreamReader qts = null;
-            if (xml != null && xml.startsWith("<")) {
-                System.out.println(xml);
+            if (xml != null) {
+                System.out.println("Server responded: " + xml);
                 qts = factory.createXMLStreamReader(new StringReader(xml));
 
             // if the web service isn't responding, continue with the demo using historical data 

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=1027408&r1=1027407&r2=1027408&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:56:52 2010
@@ -45,8 +45,7 @@
     </component>
 
     <reference name="StockQuoteReference" promote="AccountService/stockQuote">
-        <binding.ws wsdlElement="http://bigbank/#wsdl.port(StockQuoteService/StockQuotePort)" />
-        <!--binding.ws wsdlElement="http://www.webserviceX.NET/#wsdl.port(StockQuote/StockQuoteSoap)" /-->
+        <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=1027408&r1=1027407&r2=1027408&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:56:52 2010
@@ -1,31 +1,66 @@
-<?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/">
+<?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.    
+-->
+
+<!--
+   Ideally we would obtain the WSDL from the remote server using <wsdl:import location="..."/>, but this
+   causes major problems if the server is down because the unresolved import causes the contribution load
+   to fail.  A simple workaround is to use a local WSDL definition that matches the service we are attempting
+   to invoke.  This ensures that the contribution can always be loaded.  If the service invocation fails at
+   runtime because the server is down, there is code in the demo to catch the exception and use local
+   historical data instead.
+  -->
+
+<!-- If you're feeling brave, uncomment the following and comment out the local definition below 
+<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.net/stockquote.asmx?wsdl" />
+</wsdl:definitions>
+--> 
+
+<!-- This is the local definition for the remote web service --> 
+<wsdl:definitions targetNamespace="http://www.webserviceX.NET/" xmlns:tns="http://www.webserviceX.NET/"
+      xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:SOAP="http://schemas.xmlsoap.org/wsdl/soap/">
   <wsdl:types>
-    <xs:schema attributeFormDefault="qualified" elementFormDefault="unqualified"
+    <xs:schema attributeFormDefault="qualified" elementFormDefault="qualified"
         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:element minOccurs="0" name="GetQuoteResult" 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:element minOccurs="0" name="symbol" 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:part name="GetQuoteResponse" element="tns:GetQuoteResponse" /> 
   </wsdl:message>
   <wsdl:message name="GetQuote">
-    <wsdl:part name="GetQuote" element="wsx:GetQuote" /> 
+    <wsdl:part name="GetQuote" element="tns:GetQuote" /> 
   </wsdl:message>
   <wsdl:portType name="StockQuote">
     <wsdl:operation name="GetQuote">
@@ -45,8 +80,8 @@
       </wsdl:output>
     </wsdl:operation>
   </wsdl:binding>
-  <wsdl:service name="StockQuoteService">
-    <wsdl:port name="StockQuotePort" binding="tns:StockQuoteBinding">
+  <wsdl:service name="StockQuote">
+    <wsdl:port name="StockQuoteSoap" binding="tns:StockQuoteBinding">
       <SOAP:address location="http://www.webservicex.net/stockquote.asmx" /> 
     </wsdl:port>
   </wsdl:service>