SchemaFactory failed to report invalid xsd schema extracted from a wsdl

时间:2016-05-17 11:20:51

标签: java validation wsdl

I am using scheamaFactory to validate schema of a wsdl file. Below is my code.


javax.wsdl.xml.WSDLReader wsdlReader = javax.wsdl.factory.WSDLFactory.newInstance().newWSDLReader();
            Definition def = wsdlReader.readWSDL(xsdPath);

    List schemaElementList = new ArrayList();
            for (Object o : def.getTypes().getExtensibilityElements()) {
                if (o instanceof javax.wsdl.extensions.schema.Schema) {
                    javax.wsdl.extensions.schema.Schema schema = (javax.wsdl.extensions.schema.Schema) o;
                    org.w3c.dom.Element elt = schema.getElement();
                    if (elt != null) {
                        schemaElementList.add(elt);
                    }   
                }
            }

    SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
            factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);

            for (Element e : schemaElementList) {
                DOMSource domSource = new DOMSource(e,e.getNamespaceURI());
                Schema sch = factory.newSchema(domSource);
            }
    

I expect exception to be thrown when factory.newSchema(domSource) is called but its not working as I expect. Am I missing anything here? Please suggest.

Below is my part of wsdl file where line#-7 is incorrect.

    <wsdl:definitions xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tns="http://www.webserviceX.NET" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" targetNamespace="http://www.webserviceX.NET" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
  <wsdl:types>
    <s:schema elementFormDefault="qualified" targetNamespace="http://www.webserviceX.NET" >
      <s:element name="GetWeather">
        <s:complexType>
          <s:sequence>
            s:element minOccurs="0" maxOccurs="1" name="CityName" type="s:string" />
            <s:element minOccurs="0" maxOccurs="1" name="CountryName" type="s:string" />
          </s:sequence>
        </s:complexType>
      </s:element>
      <s:element name="GetWeatherResponse">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="0" maxOccurs="1" name="GetWeatherResult" type="s:string" />
          </s:sequence>
        </s:complexType>
      </s:element>
      <s:element name="GetCitiesByCountry">
        <s:complexType>fgdfg
          <s:sequence>
            <s:element minOccurs="0" maxOccurs="1" name="CountryName" type="s:string" />
          </s:sequence>
        </s:complexType>
      </s:element>
      <s:element name="GetCitiesByCountryResponse">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="0" maxOccurs="1" name="GetCitiesByCountryResult" type="s:string" />
          </s:sequence>
        </s:complexType>
      </s:element>
      <s:element name="string" nillable="true" type="s:string" />
    </s:schema>
  </wsdl:types>

You can download complete wsdl from getWeatherWSDL and edit xsd schema to introduce some error.

0 个答案:

没有答案