cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject git commit: [CXF-4913] Initial support for validating WADL documents
Date Wed, 27 Aug 2014 21:04:17 GMT
Repository: cxf
Updated Branches:
  refs/heads/2.7.x-fixes bf0610b9b -> 3e361fb48


[CXF-4913] Initial support for validating WADL documents


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/3e361fb4
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/3e361fb4
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/3e361fb4

Branch: refs/heads/2.7.x-fixes
Commit: 3e361fb487253e796bd3d12b2af83b11d06edf10
Parents: bf0610b
Author: Sergey Beryozkin <sberyozkin@talend.com>
Authored: Wed Aug 27 18:08:22 2014 +0100
Committer: Sergey Beryozkin <sberyozkin@talend.com>
Committed: Wed Aug 27 22:03:48 2014 +0100

----------------------------------------------------------------------
 .../cxf/tools/wadlto/WadlToolConstants.java     |   1 +
 .../cxf/tools/wadlto/jaxrs/JAXRSContainer.java  |   1 +
 .../cxf/tools/wadlto/jaxrs/SourceGenerator.java |  68 ++++-
 .../tools/wadlto/jaxrs/ValidationException.java |  30 +++
 .../cxf/tools/wadlto/jaxrs/jaxrs-toolspec.xml   |   6 -
 .../src/main/resources/schemas/wadl/wadl.xsd    | 263 +++++++++++++++++++
 .../tools/wadlto/jaxrs/ValidateWadlTest.java    |  21 +-
 .../src/test/resources/wadl/invalidWadl.xml     |  13 +
 8 files changed, 389 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/3e361fb4/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/WadlToolConstants.java
----------------------------------------------------------------------
diff --git a/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/WadlToolConstants.java
b/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/WadlToolConstants.java
index 3eaa831..42026f5 100644
--- a/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/WadlToolConstants.java
+++ b/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/WadlToolConstants.java
@@ -56,6 +56,7 @@ public final class WadlToolConstants {
     public static final String CFG_INHERIT_PARAMS = "inheritResourceParams";
     public static final String CFG_GENERATE_RESPONSE_IF_HEADERS_SET = "generateResponseIfHeadersSet";
     public static final String CFG_GENERATE_RESPONSE_FOR_METHODS = "generateResponseForMethods";
+    public static final String CFG_VALIDATE_WADL = "validate";
     
     // JAX-RS 2.0 @Suspended AsyncResponse
     public static final String CFG_SUSPENDED_ASYNC = "async";

http://git-wip-us.apache.org/repos/asf/cxf/blob/3e361fb4/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainer.java
----------------------------------------------------------------------
diff --git a/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainer.java
b/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainer.java
index f357d12..07a628e 100644
--- a/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainer.java
+++ b/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainer.java
@@ -155,6 +155,7 @@ public class JAXRSContainer extends AbstractCXFToolContainer {
         sg.setResponseMethods(getResponseMethods());
                 
         sg.setGenerateEnums(context.optionSet(WadlToolConstants.CFG_GENERATE_ENUMS));
+        sg.setValidateWadl(context.optionSet(WadlToolConstants.CFG_VALIDATE_WADL));
         boolean inheritResourceParams = context.optionSet(WadlToolConstants.CFG_INHERIT_PARAMS);
         sg.setInheritResourceParams(inheritResourceParams);
         if (inheritResourceParams) {

http://git-wip-us.apache.org/repos/asf/cxf/blob/3e361fb4/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/SourceGenerator.java
----------------------------------------------------------------------
diff --git a/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/SourceGenerator.java
b/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/SourceGenerator.java
index 22d8f86..2026f37 100644
--- a/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/SourceGenerator.java
+++ b/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/SourceGenerator.java
@@ -18,6 +18,7 @@
  */
 package org.apache.cxf.tools.wadlto.jaxrs;
 
+import java.io.BufferedReader;
 import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
@@ -41,6 +42,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.TreeSet;
+import java.util.logging.Level;
 import java.util.logging.Logger;
 
 import javax.ws.rs.Consumes;
@@ -66,12 +68,19 @@ import javax.ws.rs.core.PathSegment;
 import javax.ws.rs.core.Response;
 import javax.xml.namespace.QName;
 import javax.xml.transform.Source;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamSource;
+import javax.xml.validation.Schema;
+import javax.xml.validation.SchemaFactory;
+import javax.xml.validation.Validator;
 
 import org.w3c.dom.Element;
 import org.w3c.dom.NamedNodeMap;
 import org.w3c.dom.Node;
 
+import org.xml.sax.ErrorHandler;
 import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
 import org.xml.sax.SAXParseException;
 
 import org.apache.cxf.Bus;
@@ -98,7 +107,6 @@ import org.apache.cxf.jaxrs.utils.JAXRSUtils;
 import org.apache.cxf.jaxrs.utils.ResourceUtils;
 import org.apache.cxf.service.model.SchemaInfo;
 import org.apache.cxf.staxutils.StaxUtils;
-import org.apache.cxf.tools.common.ToolException;
 import org.apache.ws.commons.schema.XmlSchema;
 
 public class SourceGenerator {
@@ -210,7 +218,7 @@ public class SourceGenerator {
     private Map<String, String> mediaTypesMap = Collections.emptyMap();
     private Bus bus;
     private boolean supportMultipleXmlReps;
-        
+    private boolean validateWadl;    
     private SchemaCollection schemaCollection = new SchemaCollection();
     
     public SourceGenerator() {
@@ -279,7 +287,6 @@ public class SourceGenerator {
     
     public void generateSource(String wadl, File srcDir, String codeType) {
         Application app = readWadl(wadl, wadlPath);
-        
         Set<String> typeClassNames = new HashSet<String>();
         GrammarInfo gInfo = generateSchemaCodeAndInfo(app, typeClassNames, srcDir);
         if (!CODE_TYPE_GRAMMAR.equals(codeType)) {
@@ -1120,7 +1127,7 @@ public class SourceGenerator {
             if (PLAIN_PARAM_STYLE.equals(paramStyle)) {
                 error += ", plain style parameters have to be wrapped by representations";
   
             }
-            throw new ToolException(error); 
+            throw new ValidationException(error); 
         }
         return paramAnn;
     }
@@ -1448,7 +1455,30 @@ public class SourceGenerator {
     }
     
     private Application readWadl(String wadl, String docPath) {
-        return new Application(readXmlDocument(new StringReader(wadl)), docPath);
+        Element wadlElement = readXmlDocument(new StringReader(wadl));
+        try {
+            if (validateWadl) {
+                SchemaFactory factory = SchemaFactory.newInstance(Constants.URI_2001_SCHEMA_XSD);
+                URL schemaURL = ResourceUtils.getResourceURL("classpath:/schemas/wadl/wadl.xsd",
bus);
+                Reader r = new BufferedReader(new InputStreamReader(schemaURL.openStream(),
"UTF-8"));
+                StreamSource source = new StreamSource(r);
+                source.setSystemId(schemaURL.toString());
+                Schema s = factory.newSchema(new Source[]{source});
+                DOMSource wadlDoc = new DOMSource(wadlElement);
+                Validator v = s.newValidator();
+                WadlValidationErrorHandler errorHandler = new WadlValidationErrorHandler();
+                v.setErrorHandler(errorHandler);
+                v.validate(wadlDoc);
+                if (errorHandler.isValidationFailed()) {
+                    throw new ValidationException("WADL document is not valid.");
+                }
+            }
+        } catch (ValidationException ex) {
+            throw ex;
+        } catch (Exception ex) {
+            throw new ValidationException("WADL document can not be validated", ex);
+        }
+        return new Application(wadlElement, docPath);
     }
     
     private Element readXmlDocument(Reader reader) {
@@ -1709,6 +1739,10 @@ public class SourceGenerator {
         return generatedTypeClasses;    
     }
     
+    public void setValidateWadl(boolean validateWadl) {
+        this.validateWadl = validateWadl;
+    }
+
     private static class GrammarInfo {
         private Map<String, String> nsMap = new HashMap<String, String>();
         private Map<String, String> elementTypeMap = new HashMap<String, String>();
@@ -1836,4 +1870,28 @@ public class SourceGenerator {
         
         
     }
+    
+    private static class WadlValidationErrorHandler implements ErrorHandler {
+        private int fatalErrors;
+        private int errors;
+        @Override
+        public void warning(SAXParseException exception) throws SAXException {
+            LOG.log(Level.WARNING, exception.toString());
+        }
+
+        @Override
+        public void error(SAXParseException exception) throws SAXException {
+            LOG.log(Level.WARNING, exception.toString());
+            errors++;
+        }
+
+        @Override
+        public void fatalError(SAXParseException exception) throws SAXException {
+            LOG.log(Level.WARNING, exception.toString());
+            fatalErrors++;
+        }
+        private boolean isValidationFailed() {
+            return fatalErrors > 0 || errors > 0;
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/3e361fb4/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/ValidationException.java
----------------------------------------------------------------------
diff --git a/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/ValidationException.java
b/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/ValidationException.java
new file mode 100644
index 0000000..dcf3974
--- /dev/null
+++ b/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/ValidationException.java
@@ -0,0 +1,30 @@
+/**
+ * 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.
+ */
+package org.apache.cxf.tools.wadlto.jaxrs;
+
+public class ValidationException extends RuntimeException {
+
+    private static final long serialVersionUID = 4372513715544855298L;
+    public ValidationException(String error) {
+        super(error);
+    }
+    public ValidationException(String error, Throwable t) {
+        super(error, t);
+    }
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/3e361fb4/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/jaxrs-toolspec.xml
----------------------------------------------------------------------
diff --git a/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/jaxrs-toolspec.xml
b/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/jaxrs-toolspec.xml
index d45d64e..a140c54 100644
--- a/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/jaxrs-toolspec.xml
+++ b/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/jaxrs-toolspec.xml
@@ -263,9 +263,6 @@ Examples:
                     <annotation>encoding</annotation>
                 </associatedArgument>
             </option>
-            
-            <!-- 
-
             <option id="validate" maxOccurs="1">
                 <annotation>
                     Specifies that the WADL is validated before generating the code. Using

@@ -273,9 +270,6 @@ Examples:
                 </annotation>
                 <switch>validate</switch>
             </option>
-            
-            -->
-            
         </optionGroup>
         <optionGroup id="common_options">
             <option id="help" maxOccurs="1">

http://git-wip-us.apache.org/repos/asf/cxf/blob/3e361fb4/tools/wadlto/jaxrs/src/main/resources/schemas/wadl/wadl.xsd
----------------------------------------------------------------------
diff --git a/tools/wadlto/jaxrs/src/main/resources/schemas/wadl/wadl.xsd b/tools/wadlto/jaxrs/src/main/resources/schemas/wadl/wadl.xsd
new file mode 100644
index 0000000..1f71474
--- /dev/null
+++ b/tools/wadlto/jaxrs/src/main/resources/schemas/wadl/wadl.xsd
@@ -0,0 +1,263 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
+  targetNamespace="http://wadl.dev.java.net/2009/02"
+  xmlns:tns="http://wadl.dev.java.net/2009/02"
+  xmlns:xml="http://www.w3.org/XML/1998/namespace"
+  elementFormDefault="qualified">
+
+  <xs:import namespace="http://www.w3.org/XML/1998/namespace"
+    schemaLocation="http://www.w3.org/2001/xml.xsd"/>
+
+  <xs:element name="application">
+    <xs:complexType>
+      <xs:sequence>
+        <xs:element ref="tns:doc" minOccurs="0" maxOccurs="unbounded"/>
+        <xs:element ref="tns:grammars" minOccurs="0"/>
+        <xs:element ref="tns:resources" minOccurs="0"
+          maxOccurs="unbounded"/>
+        <xs:choice minOccurs="0" maxOccurs="unbounded">
+          <xs:element ref="tns:resource_type"/>
+          <xs:element ref="tns:method"/>
+          <xs:element ref="tns:representation"/>
+          <xs:element ref="tns:param"/>
+        </xs:choice>
+        <xs:any namespace="##other" processContents="lax" minOccurs="0"
+          maxOccurs="unbounded"/>
+      </xs:sequence>
+    </xs:complexType>
+  </xs:element>
+
+  <xs:element name="doc">
+    <xs:complexType mixed="true">
+      <xs:sequence>
+        <xs:any namespace="##other" processContents="lax" minOccurs="0"
+          maxOccurs="unbounded"/>
+      </xs:sequence>
+      <xs:attribute name="title" type="xs:string"/>
+      <xs:attribute ref="xml:lang"/>
+      <xs:anyAttribute namespace="##other" processContents="lax"/>
+    </xs:complexType>
+  </xs:element>
+
+  <xs:element name="grammars">
+    <xs:complexType>
+      <xs:sequence>
+        <xs:element ref="tns:doc" minOccurs="0" maxOccurs="unbounded"/>
+        <xs:element minOccurs="0" maxOccurs="unbounded" ref="tns:include"/>
+        <xs:any namespace="##other" processContents="lax" minOccurs="0"
+          maxOccurs="unbounded"/>
+      </xs:sequence>
+    </xs:complexType>
+  </xs:element>
+
+  <xs:element name="resources">
+    <xs:complexType>
+      <xs:sequence>
+        <xs:element ref="tns:doc" minOccurs="0" maxOccurs="unbounded"/>
+        <xs:element ref="tns:resource" maxOccurs="unbounded"/>
+        <xs:any namespace="##other" processContents="lax" minOccurs="0"
+          maxOccurs="unbounded"/>
+      </xs:sequence>
+      <xs:attribute name="base" type="xs:anyURI"/>
+      <xs:anyAttribute namespace="##other" processContents="lax"/>
+    </xs:complexType>
+  </xs:element>
+
+  <xs:element name="resource">
+    <xs:complexType>
+      <xs:sequence>
+        <xs:element ref="tns:doc" minOccurs="0" maxOccurs="unbounded"/>
+        <xs:element ref="tns:param" minOccurs="0" maxOccurs="unbounded"/>
+        <xs:choice minOccurs="0" maxOccurs="unbounded">
+          <xs:element ref="tns:method"/>
+          <xs:element ref="tns:resource"/>
+        </xs:choice>
+        <xs:any minOccurs="0" maxOccurs="unbounded" namespace="##other"
+          processContents="lax"/>
+      </xs:sequence>
+      <xs:attribute name="id" type="xs:ID"/>
+      <xs:attribute name="type" type="tns:resource_type_list"/>
+      <xs:attribute name="queryType" type="xs:string"
+        default="application/x-www-form-urlencoded"/>
+      <xs:attribute name="path" type="xs:string"/>
+      <xs:anyAttribute namespace="##other" processContents="lax"/>
+    </xs:complexType>
+  </xs:element>
+
+  <xs:simpleType name="resource_type_list">
+    <xs:list itemType="xs:anyURI"/>
+  </xs:simpleType>
+
+  <xs:element name="resource_type">
+    <xs:complexType>
+      <xs:sequence>
+        <xs:element ref="tns:doc" minOccurs="0" maxOccurs="unbounded"/>
+        <xs:element ref="tns:param" minOccurs="0" maxOccurs="unbounded"/>
+        <xs:choice minOccurs="0" maxOccurs="unbounded">
+          <xs:element ref="tns:method"/>
+          <xs:element ref="tns:resource"/>
+        </xs:choice>
+        <xs:any minOccurs="0" maxOccurs="unbounded" namespace="##other"
+          processContents="lax"/>
+      </xs:sequence>
+      <xs:attribute name="id" type="xs:ID"/>
+      <xs:anyAttribute namespace="##other" processContents="lax"/>
+    </xs:complexType>
+  </xs:element>
+
+  <xs:element name="method">
+    <xs:complexType>
+      <xs:sequence>
+        <xs:element ref="tns:doc" minOccurs="0" maxOccurs="unbounded"/>
+        <xs:element ref="tns:request" minOccurs="0"/>
+        <xs:element ref="tns:response" minOccurs="0"
+          maxOccurs="unbounded"/>
+        <xs:any namespace="##other" processContents="lax" minOccurs="0"
+          maxOccurs="unbounded"/>
+      </xs:sequence>
+      <xs:attribute name="id" type="xs:ID"/>
+      <xs:attribute name="name" type="tns:Method"/>
+      <xs:attribute name="href" type="xs:anyURI"/>
+      <xs:anyAttribute namespace="##other" processContents="lax"/>
+    </xs:complexType>
+  </xs:element>
+
+  <xs:simpleType name="Method">
+    <xs:union memberTypes="tns:HTTPMethods xs:NMTOKEN"/>
+  </xs:simpleType>
+
+  <xs:simpleType name="HTTPMethods">
+    <xs:restriction base="xs:NMTOKEN">
+      <xs:enumeration value="GET"/>
+      <xs:enumeration value="POST"/>
+      <xs:enumeration value="PUT"/>
+      <xs:enumeration value="HEAD"/>
+      <xs:enumeration value="DELETE"/>
+    </xs:restriction>
+  </xs:simpleType>
+
+  <xs:element name="include">
+    <xs:complexType>
+      <xs:sequence>
+        <xs:element ref="tns:doc" minOccurs="0" maxOccurs="unbounded"/>
+      </xs:sequence>
+      <xs:attribute name="href" type="xs:anyURI"/>
+      <xs:anyAttribute namespace="##other" processContents="lax"/>
+    </xs:complexType>
+  </xs:element>
+
+  <xs:element name="request">
+    <xs:complexType>
+      <xs:sequence>
+        <xs:element ref="tns:doc" minOccurs="0" maxOccurs="unbounded"/>
+        <xs:element ref="tns:param" minOccurs="0" maxOccurs="unbounded"/>
+        <xs:element ref="tns:representation" minOccurs="0"
+          maxOccurs="unbounded"/>
+        <xs:any namespace="##other" processContents="lax" minOccurs="0"
+          maxOccurs="unbounded"/>
+      </xs:sequence>
+      <xs:anyAttribute namespace="##other" processContents="lax"/>
+    </xs:complexType>
+  </xs:element>
+
+  <xs:element name="response">
+    <xs:complexType>
+      <xs:sequence>
+        <xs:element ref="tns:doc" minOccurs="0" maxOccurs="unbounded"/>
+        <xs:element ref="tns:param" minOccurs="0" maxOccurs="unbounded"/>
+        <xs:element ref="tns:representation" minOccurs="0"
+          maxOccurs="unbounded"/>
+        <xs:any namespace="##other" processContents="lax" minOccurs="0"
+          maxOccurs="unbounded"/>
+      </xs:sequence>
+      <xs:attribute name="status" type="tns:statusCodeList"/>
+      <xs:anyAttribute namespace="##other" processContents="lax"/>
+    </xs:complexType>
+  </xs:element>
+
+  <xs:simpleType name="uriList">
+    <xs:list itemType="xs:anyURI"/>
+  </xs:simpleType>
+
+  <xs:element name="representation">
+    <xs:complexType>
+      <xs:sequence>
+        <xs:element ref="tns:doc" minOccurs="0" maxOccurs="unbounded"/>
+        <xs:element ref="tns:param" minOccurs="0" maxOccurs="unbounded"/>
+        <xs:any namespace="##other" processContents="lax" minOccurs="0"
+          maxOccurs="unbounded"/>
+      </xs:sequence>
+      <xs:attribute name="id" type="xs:ID"/>
+      <xs:attribute name="element" type="xs:QName"/>
+      <xs:attribute name="mediaType" type="xs:string"/>
+      <xs:attribute name="href" type="xs:anyURI"/>
+      <xs:attribute name="profile" type="tns:uriList"/>
+      <xs:anyAttribute namespace="##other" processContents="lax"/>
+    </xs:complexType>
+  </xs:element>
+
+  <xs:simpleType name="statusCodeList">
+    <xs:list itemType="xs:unsignedInt"/>
+  </xs:simpleType>
+
+  <xs:simpleType name="ParamStyle">
+    <xs:restriction base="xs:string">
+      <xs:enumeration value="plain"/>
+      <xs:enumeration value="query"/>
+      <xs:enumeration value="matrix"/>
+      <xs:enumeration value="header"/>
+      <xs:enumeration value="template"/>
+    </xs:restriction>
+  </xs:simpleType>
+
+  <xs:element name="param">
+    <xs:complexType>
+      <xs:sequence>
+        <xs:element ref="tns:doc" minOccurs="0" maxOccurs="unbounded"/>
+        <xs:element ref="tns:option" minOccurs="0" maxOccurs="unbounded"/>
+        <xs:element ref="tns:link" minOccurs="0"/>
+        <xs:any namespace="##other" processContents="lax" minOccurs="0"
+          maxOccurs="unbounded"/>
+      </xs:sequence>
+      <xs:attribute name="href" type="xs:anyURI"/>
+      <xs:attribute name="name" type="xs:NMTOKEN"/>
+      <xs:attribute name="style" type="tns:ParamStyle"/>
+      <xs:attribute name="id" type="xs:ID"/>
+      <xs:attribute name="type" type="xs:QName" default="xs:string"/>
+      <xs:attribute name="default" type="xs:string"/>
+      <xs:attribute name="required" type="xs:boolean" default="false"/>
+      <xs:attribute name="repeating" type="xs:boolean" default="false"/>
+      <xs:attribute name="fixed" type="xs:string"/>
+      <xs:attribute name="path" type="xs:string"/>
+      <xs:anyAttribute namespace="##other" processContents="lax"/>
+    </xs:complexType>
+  </xs:element>
+
+  <xs:element name="option">
+    <xs:complexType>
+      <xs:sequence>
+        <xs:element ref="tns:doc" minOccurs="0" maxOccurs="unbounded"/>
+        <xs:any namespace="##other" processContents="lax" minOccurs="0"
+          maxOccurs="unbounded"/>
+      </xs:sequence>
+      <xs:attribute name="value" type="xs:string" use="required"/>
+      <xs:attribute name="mediaType" type="xs:string"/>
+      <xs:anyAttribute namespace="##other" processContents="lax"/>
+    </xs:complexType>
+  </xs:element>
+
+  <xs:element name="link">
+    <xs:complexType>
+      <xs:sequence>
+        <xs:element ref="tns:doc" minOccurs="0" maxOccurs="unbounded"/>
+        <xs:any namespace="##other" processContents="lax" minOccurs="0"
+          maxOccurs="unbounded"/>
+      </xs:sequence>
+      <xs:attribute name="resource_type" type="xs:anyURI"/>
+      <xs:attribute name="rel" type="xs:token"/>
+      <xs:attribute name="rev" type="xs:token"/>
+      <xs:anyAttribute namespace="##other" processContents="lax"/>
+    </xs:complexType>
+  </xs:element>
+
+</xs:schema>

http://git-wip-us.apache.org/repos/asf/cxf/blob/3e361fb4/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/ValidateWadlTest.java
----------------------------------------------------------------------
diff --git a/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/ValidateWadlTest.java
b/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/ValidateWadlTest.java
index 771943b..9eb5797 100644
--- a/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/ValidateWadlTest.java
+++ b/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/ValidateWadlTest.java
@@ -23,7 +23,6 @@ import java.net.URISyntaxException;
 
 import org.apache.cxf.tools.common.ProcessorTestBase;
 import org.apache.cxf.tools.common.ToolContext;
-import org.apache.cxf.tools.common.ToolException;
 import org.apache.cxf.tools.wadlto.WadlToolConstants;
 
 import org.junit.Test;
@@ -31,7 +30,23 @@ import org.junit.Test;
 public class ValidateWadlTest extends ProcessorTestBase {
 
     @Test    
-    public void testCodeGenInterfaces() throws Exception {
+    public void testInvalidWadl() throws Exception {
+        try {
+            JAXRSContainer container = new JAXRSContainer(null);
+
+            ToolContext context = new ToolContext();
+            context.put(WadlToolConstants.CFG_WADLURL, getLocation("/wadl/invalidWadl.xml"));
+            context.put(WadlToolConstants.CFG_VALIDATE_WADL, "true");
+            container.setContext(context);
+            container.execute();
+            fail("Validation exception expected");
+        } catch (ValidationException e) {
+            // expected
+        }
+    }
+    
+    @Test    
+    public void testInvalidParameterStyle() throws Exception {
         try {
             JAXRSContainer container = new JAXRSContainer(null);
 
@@ -40,7 +55,7 @@ public class ValidateWadlTest extends ProcessorTestBase {
             container.setContext(context);
             container.execute();
             fail();            
-        } catch (ToolException e) {
+        } catch (ValidationException e) {
             String message = e.getMessage();
             assertTrue(message.startsWith("Unsupported parameter style: plain"));
         }

http://git-wip-us.apache.org/repos/asf/cxf/blob/3e361fb4/tools/wadlto/jaxrs/src/test/resources/wadl/invalidWadl.xml
----------------------------------------------------------------------
diff --git a/tools/wadlto/jaxrs/src/test/resources/wadl/invalidWadl.xml b/tools/wadlto/jaxrs/src/test/resources/wadl/invalidWadl.xml
new file mode 100644
index 0000000..bdabe57
--- /dev/null
+++ b/tools/wadlto/jaxrs/src/test/resources/wadl/invalidWadl.xml
@@ -0,0 +1,13 @@
+<application xmlns="http://wadl.dev.java.net/2009/02" xmlns:xs="http://www.w3.org/2001/XMLSchema"
>
+	<grammars />
+	<resources>
+		<resource id="Test" path="/repository">
+			<method name="GET" id="listRepositories">
+			    <param name="top" style="template" type="xs:string"/>
+				<response>
+					<representation mediaType="application/json" />
+				</response>
+			</method>
+		</resource>
+	</resources>
+</application>
\ No newline at end of file


Mime
View raw message