2013-07-16 102 views
1

我想验证WSDL的SOAP响应消息,并且我遵循给定的示例in this question。但是,我得到下面的例外。SAXParseException无法将SOAP-ENC:Array解析为类型定义组件

org.xml.sax.SAXParseException: src-resolve: Cannot resolve the name 'SOAP-ENC:Array' to a(n) 'type definition' component.

我见过a question有关类似错误,但我不知道这是否是同样的问题。我也不明白为什么SOAP-ENC:Array在出现在SOAP spec中时被认为是非标准问题。

这是我的验证码。 Schema schema = schemaFactory.newSchema(schemas)系列产生异常。

DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder(); 
Document wsdlDoc = db.newDocument(); 
TransformerFactory transformerFactory = TransformerFactory.newInstance(); 
Transformer transformer = transformerFactory.newTransformer(); 
Source wsdlSource = new StreamSource(new File("d:\\temp\\demo.wsdl")); 
transformer.transform(wsdlSource, new DOMResult(wsdlDoc)); 

NodeList schemaNodes = wsdlDoc.getElementsByTagNameNS(XMLConstants.W3C_XML_SCHEMA_NS_URI, "schema"); 
int nrSchemas = schemaNodes.getLength(); 

Source[] schemas = new Source[nrSchemas]; 
for (int i = 0; i < nrSchemas; ++i) 
{ 
    schemas[i] = new DOMSource(schemaNodes.item(i)); 
} 

SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); 
Schema schema = schemaFactory.newSchema(schemas); 
Validator validator = schema.newValidator(); 
Source soapMessage = new StreamSource(new File("d:\\temp\\soapmessage.xml")); 
Result result = new StreamResult(System.out); 
validator.validate(soapMessage, result); 

我修剪WSDL和只剩相关部分,或者至少我认为是相关的。如果需要更多,我会更新这个问题。

<?xml version='1.0' encoding='UTF-8'?> 
<definitions xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" 
      xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" 
      xmlns:tns="run:demo" 
      xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" 
      xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" 
      xmlns="http://schemas.xmlsoap.org/wsdl/" 
      targetNamespace="run:demo"> 
    <types> 
    <xsd:schema targetNamespace="run:demo"> 
     <xsd:import namespace="http://schemas.xmlsoap.org/soap/encoding/"/> 
     <xsd:import namespace="http://schemas.xmlsoap.org/wsdl/"/> 
     <xsd:complexType name="itemsCT"> 
     <xsd:all> 
      <xsd:element name="Name" type="xsd:string"/> 
      <xsd:element name="Address" type="xsd:string"/> 
     </xsd:all> 
     </xsd:complexType> 
     <xsd:complexType name="itemsArray"> 
     <xsd:complexContent> 
      <xsd:restriction base="SOAP-ENC:Array"> 
      <xsd:attribute ref="SOAP-ENC:arrayType" 
          wsdl:arrayType="tns:itemsCT[]"/> 
      </xsd:restriction> 
     </xsd:complexContent> 
     </xsd:complexType> 
    </xsd:schema> 
    </types> 
</definitions> 

回答

1

眼前的问题是,模式验证被称为不加载任何架构文档命名空间http://schemas.xmlsoap.org/soap/encoding/ - 可能是因为它是一个通用的验证,没有SOAP命名空间的任何内在的知识,或者是因为它没有没有设法从schemas.xmlsoap.org的服务器检索模式文档。

如果您有http://schemas.xmlsoap.org/soap/encoding/http://schemas.xmlsoap.org/wsdl/名称空间的模式的本地副本,您可以尝试向模式中的两个xsd:import元素添加模式位置信息。如果你没有本地副本,那么我希望你能够比我刚刚做的更好地获得schemas.xmlsoap.org的回应。

相关问题