具有模式验证的 JAX-RS
我有一个 RESTful 服务,它有一个路径参数和一个从请求正文中解组的参数。请求正文参数是 XML,我有一个 XSD。我一直在尝试根据 XSD 验证 XML 有效负载,但无济于事。我已经尝试了以下操作,如此处所述:
<jaxrs:server address="/"
serviceClass="my.endpoint.class">
<jaxrs:schemaLocations>
<jaxrs:schemaLocation>classpath:schema/myschema.xsd</jaxrs:schemaLocation>
</jaxrs:schemaLocations>
</jaxrs:server>
正在找到模式(至少没有错误),但我期望无效的有效负载不会引发异常。与 XSD 内容不匹配的参数将显示为 null。它可能不相关,但我的自动生成的有效负载类具有三个属性,其中一些是必需的。
我已经简单地创建了一个 MessageBodyReader,如 此处< /a> 但我认为我遇到了范围问题,并且在调用 readFrom 时我的架构对象不可用。
任何帮助或建议将不胜感激!
I have a RESTful service that has a single path parameter and a parameter that is unmarshalled from the request body. The request body parameter is XML for which I have an XSD. I've been trying to validate the XML payload against the XSD but to no avail. I've tried the following, as described here:
<jaxrs:server address="/"
serviceClass="my.endpoint.class">
<jaxrs:schemaLocations>
<jaxrs:schemaLocation>classpath:schema/myschema.xsd</jaxrs:schemaLocation>
</jaxrs:schemaLocations>
</jaxrs:server>
The schemas are being found (there are no errors at least) but what I expect to be an invalid payload is not throwing an exception. Parameters that don't match the XSD contents are coming through as null. It may not be relevant but my auto-generated payload class has three attributes, some of which are required.
I've had a brief go at creating a MessageBodyReader, as described here but I think I'm having scope issues and my schema object is not available when readFrom is called.
Any help or suggestions would be gratefully appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
结果我使用的 servlet 不接受上面显示的 jaxrs 配置。我从使用这个: 更改
为:
我的 applicationContext.xml
架构引用的片段来自与 WEB-INF 相邻的资源目录。
Turns out the servlet I was using wasn't accepting the jaxrs configuration shown above. I changed from using this:
to this:
Snippet of my applicationContext.xml
Schema references are from the resources directory, adjacent to WEB-INF.