I am trying to validate a request body against multiple XSD files using Java Callout Policy .We have 4 XSD's under resources folder and reading all using InputStream but only main the XSD (saml-schema-protocol-2.0.xsd) is getting loaded and we are getting the below error.
= org.xml.sax.SAXParseException; src-resolve: Cannot resolve the name 'saml:EncryptedElementType' to a(n) 'type definition' component.
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); Schema schema = schemaFactory.newSchema(new Source[] { new StreamSource(stream("saml-sch ema-protocol-2.0.xsd")),new StreamSource(stream("saml-schema-assertion-2.0.xs d")), new StreamSource(stream("xenc-schema.xsd")),new StreamSource(stream("xmlds ig-core-schema.xsd"))}); Validator validator = schema.newValidator(); validator.validate(xmlFile);
private InputStream stream(String string) { InputStream is = getClass().getClassLoader().getResourceAsStream(string);schemavalidation.zip return is; }
Also we have attached the Java code for same.
We are facing the similar issue while compliling when tried with Soap Message Validation policy . we have raised ticket(1449932) with APIGEE.
src-resolve: Cannot resolve the name 'ds:Signature' to a(n) 'element declaration' component.
I don't know how to specify multiple schema in the MessageValidation policy.
As for your Java code, I think the order of placement in the array of Source is important. If schema A imports schema B, then B must appear before A in the list. In your case I think the xenc-schema.xsd is required by something else in the list. So maybe reorder things , and it will be able to resolve the name for you.
If you like you can try this callout which was designed to allow multiple schema.
https://github.com/DinoChiesa/ApigeeEdge-Java-Xsd-Validation
You could re-compile the callout to embed the SAML schema and then use a configuration like:
<JavaCallout name='JavaCallout-XSD-1'> <Properties> <Property name='xsd'>file://schema1.xsd,file://schema2.xsd,file://schema3.xsd</Property> <Property name='source'>request</Property> </Properties> <ClassName>com.google.apigee.edgecallouts.xsdvalidation.XsdValidatorCallout</ClassName> <ResourceURL>java://edge-custom-xsd-validation-1.0.5.jar</ResourceURL> </JavaCallout>
As a workaround until SOAPMessageValidation policy supports this use case, you can try