The XSD Schema I used to generate my Java classes contains a lot of
statements. While trying to enable validation by setting schema location to
"classpath:/rootSchema.xsd" I get an error "Validation will be disabled,
failed to create schema : an element from an included schema can't be
resolved".
After some debugging I found that the method createSchema in
org.apache.cxf.jaxrs.utils.schemas.SchemaHandler loads only the root schema,
but ignores all nested schemas. After changing the method to
public static Schema createSchema(List locations, Bus bus) {
SchemaFactory factory =
SchemaFactory.newInstance(WSDLConstants.NS_SCHEMA_XSD);
Schema s = null;
try {
List sources = new ArrayList();
for (String loc : locations) {
InputStream is = ResourceUtils.getResourceStream(loc, bus);
if (is == null) {
return null;
}
Reader r = new BufferedReader(
new InputStreamReader(is, "UTF-8"));
sources.add(new StreamSource(r));
}
s = factory.newSchema(sources.toArray(new Source[]{}));
} catch (Exception ex) {
LOG.warning("Try another load algoritmus for schemas ");
try
{
List sources = new ArrayList();
for (String loc : locations) {
String url =
ClassLoaderUtils.getResource(loc.substring("classpath:".length()),ClassLoaderUtils.class).toExternalForm();
Source source=new StreamSource(url);
sources.add(source);
s = factory.newSchema(sources.toArray(new Source[]{}));
}
}
catch (Exception ex1)
{
LOG.warning("Validation will be disabled, failed to create
schema : " + ex1.getMessage());
}
}
return s;
}
it started to work.
Is there any "non-hacking" way to enable setting schemas that includes
nested schema with the same namespace?
--
View this message in context:
http://cxf.547215.n5.nabble.com/JAX-RS-Schema-validation-tp1046229p1046229.html
Sent from the cxf-user mailing list archive at Nabble.com.