[英]Troubles with WADL / generated XSD using Jersey with a contract-first approach
I have been working on a REST web service using Jersey for a few days now, and managed to have all CRUD operations working, with several exchange formats: XML, JSON, Google Protobuf. 我已经使用Jersey工作了几天的REST Web服务,并设法让所有CRUD操作工作,有几种交换格式:XML,JSON,Google Protobuf。
However I am facing some issues related to automatically generated WADL and XSD. 但是,我面临一些与自动生成的WADL和XSD相关的问题。
To define the objects exchanged in these three formats, I have followed a "contract-first" approach : 为了定义以这三种格式交换的对象,我遵循了“契约优先”的方法 :
However, as I would like my users to be able to generate their classes too, I would like to share these schema files (.xsd and .proto) and have them well integrated with the automatically generated WADL . 但是,由于我希望我的用户也能够生成他们的类 ,我想分享这些模式文件(.xsd和.proto)并将它们与自动生成的WADL很好地集成 。
For that purpose, thanks to this wiki page: 为此,感谢这个维基页面:
/schema/schema.xsd
/schema/schema.proto
I have added an application-grammar file: 我添加了一个应用程序语法文件:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <grammars xmlns="http://wadl.dev.java.net/2009/02" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xi="http://www.w3.org/1999/XML/xinclude"> <include href="../schema/schema.xsd" /> </grammars>
I have added a customized WADL generator: 我添加了一个自定义的WADL生成器:
public class RichWadlGeneratorConfig extends WadlGeneratorConfig { @Override public List<WadlGeneratorDescription> configure() { return generator(WadlGeneratorApplicationDoc.class) .prop("applicationDocsStream", "application-doc.xml") .generator(WadlGeneratorGrammarsSupport.class) .prop("grammarsStream", "application-grammars.xml") .descriptions(); } }
This way the below appears in the WADL, when I hit /rest/application.wadl
: 这样,当我点击
/rest/application.wadl
时,下面会出现在WADL中:
<grammars>
<include href="../schema/schema.xsd"/>
<include href="application.wadl/xsd0.xsd">
<doc title="Generated" xml:lang="en"/>
</include>
</grammars>
/rest/application.wadl/xsd0.xsd
is automatically generated from my classes, but is quite different from what I initially had in schema.xsd
. /rest/application.wadl/xsd0.xsd
是从我的类自动生成的,但与我最初在schema.xsd
有的完全不同 。 In addition to that, calling a tool like wadl2java
on this WADL fails miserably, presumably because 除此之外,在这个WADL上调用像
wadl2java
这样的工具失败了,大概是因为
/schema/schema.xsd
, and /schema/schema.xsd
,和 /rest/application.wadl/xsd0.xsd
are now conflicting (two definitions for the same objects). 现在是冲突的(相同对象的两个定义)。
Is there a way to disable the generation and diffusion of this automatically generated XSD? 有没有办法禁用这个自动生成的XSD的生成和传播? (As I don't need it since I'm following this "contract-first" approach)
(因为我不需要它,因为我遵循这种“契约优先”的方法)
If not, is there a way to "override" its content with my manually written XSD when /rest/application.wadl/xsd0.xsd
is hit? 如果没有,当
/rest/application.wadl/xsd0.xsd
被击中时,有没有办法用手动编写的XSD“覆盖”其内容? (I have googled around and found about WadlResource, to generate customized WADL, but found nothing about the XSD generation itself) (我已经google了一下,发现了WadlResource,生成了定制的WADL,但没有发现XSD一代本身)
Thanks in advance for your help! 在此先感谢您的帮助!
M. M.
1) I raised the issue to the Jersey team and got a reply: http://java.net/projects/jersey/lists/users/archive/2012-06/message/8 1)我向泽西岛队提出了问题并得到了答复: http : //java.net/projects/jersey/lists/users/archive/2012-06/message/8
2) I raised a ticket (JERSEY-1230), according to Pavel's instructions. 2)根据帕维尔的指示,我提出了一张票(JERSEY-1230)。 I am currently following up to either submit a fix myself or get a fix from the Jersey team.
我目前正在跟进自己提交修复或从泽西团队获得修复。
1.14-SNAPSHOT should allow you to do this: 1.14-SNAPSHOT应该允许你这样做:
public class SampleWadlGeneratorConfig extends WadlGeneratorConfig {
@Override
public List<WadlGeneratorDescription> configure() {
return generator( WadlGeneratorApplicationDoc.class )
.prop( "applicationDocsStream", "application-doc.xml" )
.generator( WadlGeneratorGrammarsSupport.class )
.prop( "grammarsStream", "application-grammars.xml" )
.prop("overrideGrammars", true) // !!!
.generator( WadlGeneratorResourceDocSupport.class )
.prop( "resourceDocStream", "resourcedoc.xml" )
.descriptions();
}
}
when overrideGrammars is set to true, Jersey generated grammars won't be included in returned WADL. 当overrideGrammars设置为true时,Jersey生成的语法将不包含在返回的WADL中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.