Merge r1001690 TUSCANY-3690: Improve error handling and fix problems with local WSDL

git-svn-id: https://svn.apache.org/repos/asf/tuscany/sca-java-1.x/trunk@1027408 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/demos/xml-bigbank/src/main/java/bigbank/AccountServiceImpl.java b/demos/xml-bigbank/src/main/java/bigbank/AccountServiceImpl.java
index 46995de..c2d0e8a 100644
--- a/demos/xml-bigbank/src/main/java/bigbank/AccountServiceImpl.java
+++ b/demos/xml-bigbank/src/main/java/bigbank/AccountServiceImpl.java
@@ -78,7 +78,17 @@
             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 @@
 
             // 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 
diff --git a/demos/xml-bigbank/src/main/resources/BigBank.composite b/demos/xml-bigbank/src/main/resources/BigBank.composite
index 18f848f..8afde4b 100644
--- a/demos/xml-bigbank/src/main/resources/BigBank.composite
+++ b/demos/xml-bigbank/src/main/resources/BigBank.composite
@@ -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>

diff --git a/demos/xml-bigbank/src/main/resources/wsdl/StockQuotes.wsdl b/demos/xml-bigbank/src/main/resources/wsdl/StockQuotes.wsdl
index 26000e4..7af2b67 100644
--- a/demos/xml-bigbank/src/main/resources/wsdl/StockQuotes.wsdl
+++ b/demos/xml-bigbank/src/main/resources/wsdl/StockQuotes.wsdl
@@ -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: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:element name="GetQuote">

+        <xs:complexType>

+          <xs:sequence>

+            <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>