Author: rfeng
Date: Thu Oct 19 11:06:27 2006
New Revision: 465708

URL: http://svn.apache.org/viewvc?view=rev&rev=465708
Log:
Add more error handling for WSDL operation introspection

Added:
    
incubator/tuscany/java/sca/services/idl/wsdl/src/test/resources/org/apache/tuscany/idl/wsdl/invalid-stockquote.wsdl
Modified:
    
incubator/tuscany/java/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/WSDLOperation.java
    
incubator/tuscany/java/sca/services/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/WSDLOperationTestCase.java

Modified: 
incubator/tuscany/java/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/WSDLOperation.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/WSDLOperation.java?view=diff&rev=465708&r1=465707&r2=465708
==============================================================================
--- 
incubator/tuscany/java/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/WSDLOperation.java
 (original)
+++ 
incubator/tuscany/java/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/WSDLOperation.java
 Thu Oct 19 11:06:27 2006
@@ -88,7 +88,7 @@
      * 
      * @return true if the operation qualifies wrapper style, otherwise false
      */
-    public boolean isWrapperStyle() {
+    public boolean isWrapperStyle() throws InvalidWSDLException {
         if (wrapperStyle == null) {
             wrapperStyle =
                     Boolean.valueOf(wrapper.getInputChildElements() != null
@@ -97,7 +97,7 @@
         return wrapperStyle.booleanValue();
     }
 
-    public Wrapper getWrapper() {
+    public Wrapper getWrapper() throws InvalidWSDLException {
         if (!isWrapperStyle()) {
             throw new IllegalStateException("The operation is not wrapper 
style.");
         } else {
@@ -300,11 +300,17 @@
         
         private transient WrapperInfo wrapperInfo;
 
-        private List<XmlSchemaElement> getChildElements(XmlSchemaElement 
element) {
+        private List<XmlSchemaElement> getChildElements(XmlSchemaElement 
element) throws InvalidWSDLException {
             if (element == null) {
                 return null;
             }
             XmlSchemaType type = element.getSchemaType();
+            if (type == null) {
+                InvalidWSDLException ex =
+                    new InvalidWSDLException("The XML schema element doesn't 
have a type");
+                ex.addContextName("element: " + element.getQName());
+                throw ex;
+            }
             if (!(type instanceof XmlSchemaComplexType)) {
                 // Has to be a complexType
                 return null;
@@ -348,7 +354,7 @@
          * 
          * @return a list of child XSD elements or null if if the request 
element is not wrapped
          */
-        public List<XmlSchemaElement> getInputChildElements() {
+        public List<XmlSchemaElement> getInputChildElements() throws 
InvalidWSDLException {
             if (inputElements != null) {
                 return inputElements;
             }
@@ -369,7 +375,10 @@
                 }
                 inputWrapperElement = schemaRegistry.getElement(elementName);
                 if (inputWrapperElement == null) {
-                    return null;
+                    InvalidWSDLException ex =
+                        new InvalidWSDLException("The element is not declared 
in a XML schema");
+                    ex.addContextName("element: " + elementName);
+                    throw ex;
                 }
                 inputElements = getChildElements(inputWrapperElement);
                 return inputElements;
@@ -383,7 +392,7 @@
          * 
          * @return a list of child XSD elements or null if if the response 
element is not wrapped
          */
-        public List<XmlSchemaElement> getOutputChildElements() {
+        public List<XmlSchemaElement> getOutputChildElements() throws 
InvalidWSDLException {
             if (outputElements != null) {
                 return outputElements;
             }
@@ -397,7 +406,10 @@
                 Part part = (Part) parts.iterator().next();
                 QName elementName = part.getElementName();
                 if (elementName == null) {
-                    return null;
+                    InvalidWSDLException ex =
+                        new InvalidWSDLException("The element is not declared 
in the XML schema");
+                    ex.addContextName("element: " + elementName);
+                    throw ex;
                 }
                 outputWrapperElement = schemaRegistry.getElement(elementName);
                 if (outputWrapperElement == null) {
@@ -425,7 +437,7 @@
             return outputWrapperElement;
         }
 
-        public DataType<List<DataType<QName>>> getUnwrappedInputType() {
+        public DataType<List<DataType<QName>>> getUnwrappedInputType() throws 
InvalidWSDLException {
             if (unwrappedInputType == null) {
                 List<DataType<QName>> childTypes = new 
ArrayList<DataType<QName>>();
                 for (XmlSchemaElement element : getInputChildElements()) {

Modified: 
incubator/tuscany/java/sca/services/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/WSDLOperationTestCase.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/WSDLOperationTestCase.java?view=diff&rev=465708&r1=465707&r2=465708
==============================================================================
--- 
incubator/tuscany/java/sca/services/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/WSDLOperationTestCase.java
 (original)
+++ 
incubator/tuscany/java/sca/services/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/WSDLOperationTestCase.java
 Thu Oct 19 11:06:27 2006
@@ -37,7 +37,8 @@
  * Test case for WSDLOperation
  */
 public class WSDLOperationTestCase extends TestCase {
-    private static final QName PORTTYPE_NAME = new 
QName("http://example.com/stockquote.wsdl";, "StockQuotePortType");
+    private static final QName PORTTYPE_NAME =
+        new QName("http://example.com/stockquote.wsdl";, "StockQuotePortType");
 
     private WSDLDefinitionRegistryImpl registry;
 
@@ -55,30 +56,30 @@
         Definition definition = registry.loadDefinition(null, url);
         PortType portType = definition.getPortType(PORTTYPE_NAME);
         Operation operation = portType.getOperation("getLastTradePrice", null, 
null);
-        
+
         WSDLOperation op = new WSDLOperation(operation, "org.w3c.dom.Node", 
registry.getSchemaRegistry());
-        
+
         DataType<List<DataType<QName>>> inputType = op.getInputType();
         Assert.assertEquals(1, inputType.getLogical().size());
-        Assert.assertEquals(new QName("http://example.com/stockquote.xsd";, 
"getLastTradePrice"), inputType.getLogical()
-                .get(0).getLogical());
-        
+        Assert.assertEquals(new QName("http://example.com/stockquote.xsd";, 
"getLastTradePrice"), inputType
+            .getLogical().get(0).getLogical());
+
         DataType<QName> outputType = op.getOutputType();
-        Assert.assertEquals(new QName("http://example.com/stockquote.xsd";, 
"getLastTradePriceResponse"), outputType
-                .getLogical());
+        Assert.assertEquals(new QName("http://example.com/stockquote.xsd";, 
"getLastTradePriceResponse"),
+                            outputType.getLogical());
         Assert.assertTrue(op.isWrapperStyle());
-        
+
         DataType<List<DataType<QName>>> unwrappedInputType = 
op.getWrapper().getUnwrappedInputType();
         List<DataType<QName>> childTypes = unwrappedInputType.getLogical();
         Assert.assertEquals(1, childTypes.size());
         DataType<QName> childType = childTypes.get(0);
         Assert.assertEquals(new QName(null, "tickerSymbol"), 
childType.getLogical());
-        ElementInfo element = (ElementInfo) 
childType.getMetadata(ElementInfo.class.getName());
+        ElementInfo element = 
(ElementInfo)childType.getMetadata(ElementInfo.class.getName());
         Assert.assertNotNull(element);
-        
+
         childType = op.getWrapper().getUnwrappedOutputType();
         Assert.assertEquals(new QName(null, "price"), childType.getLogical());
-        element = (ElementInfo) 
childType.getMetadata(ElementInfo.class.getName());
+        element = 
(ElementInfo)childType.getMetadata(ElementInfo.class.getName());
         Assert.assertNotNull(element);
     }
 
@@ -86,16 +87,33 @@
         URL url = getClass().getResource("unwrapped-stockquote.wsdl");
         Definition definition = registry.loadDefinition(null, url);
         PortType portType = definition.getPortType(PORTTYPE_NAME);
-        
+
         Operation operation = portType.getOperation("getLastTradePrice1", 
null, null);
         WSDLOperation op = new WSDLOperation(operation, "org.w3c.dom.Node", 
registry.getSchemaRegistry());
         Assert.assertFalse(op.isWrapperStyle());
         Assert.assertEquals(1, op.getInputType().getLogical().size());
-        
+
         operation = portType.getOperation("getLastTradePrice2", null, null);
         op = new WSDLOperation(operation, "org.w3c.dom.Node", 
registry.getSchemaRegistry());
         Assert.assertFalse(op.isWrapperStyle());
         Assert.assertEquals(2, op.getInputType().getLogical().size());
+    }
+
+    public final void testInvalidWSDL() throws Exception {
+        URL url = getClass().getResource("invalid-stockquote.wsdl");
+        Definition definition = registry.loadDefinition(null, url);
+        PortType portType = definition.getPortType(PORTTYPE_NAME);
+
+        Operation operation = portType.getOperation("getLastTradePrice", null, 
null);
+        WSDLOperation op = new WSDLOperation(operation, "org.w3c.dom.Node", 
registry.getSchemaRegistry());
+
+        try {
+            op.isWrapperStyle();
+            fail("InvalidWSDLException should have been thrown");
+        } catch (InvalidWSDLException e) {
+            // Expected
+        }
+
     }
 
 }

Added: 
incubator/tuscany/java/sca/services/idl/wsdl/src/test/resources/org/apache/tuscany/idl/wsdl/invalid-stockquote.wsdl
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/idl/wsdl/src/test/resources/org/apache/tuscany/idl/wsdl/invalid-stockquote.wsdl?view=auto&rev=465708
==============================================================================
--- 
incubator/tuscany/java/sca/services/idl/wsdl/src/test/resources/org/apache/tuscany/idl/wsdl/invalid-stockquote.wsdl
 (added)
+++ 
incubator/tuscany/java/sca/services/idl/wsdl/src/test/resources/org/apache/tuscany/idl/wsdl/invalid-stockquote.wsdl
 Thu Oct 19 11:06:27 2006
@@ -0,0 +1,40 @@
+<?xml version="1.0"?>
+<definitions name="StockQuote" 
targetNamespace="http://example.com/stockquote.wsdl";
+    xmlns:tns="http://example.com/stockquote.wsdl"; 
xmlns:xsd1="http://example.com/stockquote.xsd";
+    xmlns="http://schemas.xmlsoap.org/wsdl/";>
+
+    <types>
+        <schema targetNamespace="http://example.com/stockquote.xsd"; 
xmlns="http://www.w3.org/2001/XMLSchema";>
+            <element name="getLastTradePrice1">
+                <complexType>
+                    <sequence>
+                        <element name="tickerSymbol" type="string" />
+                    </sequence>
+                </complexType>
+            </element>
+            <element name="getLastTradePriceResponse">
+                <complexType>
+                    <sequence>
+                        <element name="price" type="float" />
+                    </sequence>
+                </complexType>
+            </element>
+        </schema>
+    </types>
+
+    <message name="GetLastTradePriceInput">
+        <part name="body" element="xsd1:getLastTradePrice" />
+    </message>
+
+    <message name="GetLastTradePriceOutput">
+        <part name="body" element="xsd1:getLastTradePriceResponse" />
+    </message>
+
+    <portType name="StockQuotePortType">
+        <operation name="getLastTradePrice">
+            <input message="tns:GetLastTradePriceInput" />
+            <output message="tns:GetLastTradePriceOutput" />
+        </operation>
+    </portType>
+
+</definitions>
\ No newline at end of file



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to