Skip to content

Instantly share code, notes, and snippets.

@ricston-git
Last active January 10, 2018 16:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ricston-git/8581121 to your computer and use it in GitHub Desktop.
Save ricston-git/8581121 to your computer and use it in GitHub Desktop.
Mule Schema Validator
package com.ricston.xml;
import java.io.IOException;
import java.io.InputStream;
import org.apache.xerces.dom.DOMInputImpl;
import org.mule.util.IOUtils;
import org.w3c.dom.ls.LSInput;
import org.w3c.dom.ls.LSResourceResolver;
public class ClasspathResourceResolver implements LSResourceResolver {
@Override
public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId, String baseURI) {
try {
InputStream resource = IOUtils.getResourceAsStream(systemId, getClass());
return new DOMInputImpl(publicId, systemId, baseURI, resource, null);
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
}
log4j.logger.org.mule.module.xml.filters.SchemaValidationFilter=DEBUG
<spring:bean id="classpathResourceResolver" name="classpathResourceResolver" class="com.ricston.xml.ClasspathResourceResolver"/>
<mulexml:schema-validation-filter schemaLocations="${app.home}/classes/MyXsd1_v2.1.0.xsd,${app.home}/classes/xsd/MyXsd2_v1.2.0.xsd" returnResult="true" resourceResolver-ref="classpathResourceResolver"/>
<mulexml:schema-validation-filter schemaLocations="${app.home}/classes/MyXsd1_v2.1.0.xsd,${app.home}/classes/xsd/MyXsd2_v1.2.0.xsd" returnResult="true"/>
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'schemaValidator': Invocation of init method failed; nested exception is org.mule.api.lifecycle.InitialisationException: src-resolve: Cannot resolve the name 'xxxyyy' to a(n) 'type definition' component.
...
Caused by: org.mule.api.lifecycle.InitialisationException: src-resolve: Cannot resolve the name 'xxxyyy' to a(n) 'type definition' component.
...
Caused by: org.xml.sax.SAXParseException: src-resolve: Cannot resolve the name 'xxxyyy' to a(n) 'type definition' component.
...
@muleworld
Copy link

Kindly let me know what should i change in that Java Class to meet my requirement like baseURI SystyemID etc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment