在以前的項目中,我通過解析WSDL文件,並從中提取模式解決了這個問題。該代碼是類似於下面的東西,它假定WSDL已經被讀入以某種方式源變量「wsdlSource」和導入的命名空間中的「模式」 - 元素聲明。將它在啓動時執行一次然後在SOAPHandler中進行驗證可能是一個好主意。
//First create a document from the WSDL-source
DocumentBuilder db = DocumentBuilderFactory.newInstance()
.newDocumentBuilder();
Document wsdlDoc = db.newDocument();
TransformerFactory transformerFactory = TransformerFactory
.newInstance();
Transformer transformer = transformerFactory.newTransformer();
transformer.transform(wsdlSource, new DOMResult(wsdlDoc));
//Now get the schemas from the WSDL
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);
//Now we have a schema that can validate the payload
Schema schema = schemaFactory.newSchema(schemas);
Validator validator = schema.newValidator();
看起來像現在唯一的方法!感謝您的摘錄。 – Ellis