You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Vlad Isajkin <vl...@isajkin.de> on 2010/07/12 09:56:16 UTC
[JAX-RS] Schema validation
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.
Re: [JAX-RS] Schema validation
Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi
The current workaround is to list all the schemas upfront in the right
order, ex, if A.xsd imports B.xsd & C.xsd then B.xsd & C.xsd should be
listed first (in any order) and A.xsd should be listed last.
For example, this schema :
http://svn.apache.org/repos/asf/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/resources/book.xsd
is loaded like this :
<util:list id="theSchemas">
<value>classpath:/WEB-INF/schemas/bookid.xsd</value>
<value>
classpath:/org/apache/cxf/systest/jaxrs/resources/book.xsd
</value>
</util:list>
see
http://svn.apache.org/repos/asf/cxf/trunk/systests/jaxrs/src/test/resources/jaxrs/WEB-INF/beans.xml
cheers, Sergey
On Mon, Jul 12, 2010 at 10:50 AM, Glen Mazza <gl...@gmail.com> wrote:
>
>
> Vlad Isajkin wrote:
> >
> > Is there any "non-hacking" way to enable setting schemas that includes
> > nested schema with the same namespace?
> >
>
> Yes, please check out the TRUNK/HEAD version of the source and submit a
> code
> patch (diff file) to https://issues.apache.org/jira/browse/CXF so our
> resident JAX-RS expert can review it and apply it to the codebase.
>
> Thanks,
> Glen
>
> [1] http://cxf.apache.org/source-repository.html
>
> --
> View this message in context:
> http://cxf.547215.n5.nabble.com/JAX-RS-Schema-validation-tp1046229p1046276.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>
Re: [JAX-RS] Schema validation
Posted by Glen Mazza <gl...@gmail.com>.
Vlad Isajkin wrote:
>
> Is there any "non-hacking" way to enable setting schemas that includes
> nested schema with the same namespace?
>
Yes, please check out the TRUNK/HEAD version of the source and submit a code
patch (diff file) to https://issues.apache.org/jira/browse/CXF so our
resident JAX-RS expert can review it and apply it to the codebase.
Thanks,
Glen
[1] http://cxf.apache.org/source-repository.html
--
View this message in context: http://cxf.547215.n5.nabble.com/JAX-RS-Schema-validation-tp1046229p1046276.html
Sent from the cxf-user mailing list archive at Nabble.com.