繁体   English   中英

使用带有契约优先方法的泽西岛WADL /生成XSD的麻烦

[英]Troubles with WADL / generated XSD using Jersey with a contract-first approach

我已经使用Jersey工作了几天的REST Web服务,并设法让所有CRUD操作工作,有几种交换格式:XML,JSON,Google Protobuf。

但是,我面临一些与自动生成的WADL和XSD相关的问题。


上下文

为了定义以这三种格式交换的对象,我遵循了“契约优先”的方法

  • 从我写的XSD中,我使用JAXB生成了我的模型类;
  • 从我写的等效原型文件中,我生成了Google Protobuf类(并且内部有一种方法可以将这些转换为JAXB生成的对象,以便拥有一个独特的模型)。

但是,由于我希望我的用户也能够生成他们的类 ,我想分享这些模式文件(.xsd和.proto)并将它们与自动生成的WADL很好地集成

为此,感谢这个维基页面:

  • 我已经公开了这两个文件
    • /schema/schema.xsd
    • /schema/schema.proto
  • 我添加了一个应用程序语法文件:

     <?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> 
  • 我添加了一个自定义的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(); } } 

这样,当我点击/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是从我的类自动生成的,但与我最初在schema.xsd有的完全不同 除此之外,在这个WADL上调用像wadl2java这样的工具失败了,大概是因为

  • /schema/schema.xsd ,和
  • /rest/application.wadl/xsd0.xsd

现在是冲突的(相同对象的两个定义)。


问题

  1. 有没有办法禁用这个自动生成的XSD的生成和传播? (因为我不需要它,因为我遵循这种“契约优先”的方法)

  2. 如果没有,当/rest/application.wadl/xsd0.xsd被击中时,有没有办法用手动编写的XSD“覆盖”其内容? (我已经google了一下,发现了WadlResource,生成了定制的WADL,但没有发现XSD一代本身)


在此先感谢您的帮助!

M.


编辑

1)我向泽西岛队提出了问题并得到了答复: http//java.net/projects/jersey/lists/users/archive/2012-06/message/8

2)根据帕维尔的指示,我提出了一张票(JERSEY-1230)。 我目前正在跟进自己提交修复或从泽西团队获得修复。

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();
    }

}

当overrideGrammars设置为true时,Jersey生成的语法将不包含在返回的WADL中。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM