2012-06-03 14 views
55

我一直在努力XSD,並設法讓所有CRUD操作的工作,有幾個交換格式:XML, JSON,Google Protobuf。故障與WADL /現在生成使用澤西與利用澤西幾天一個REST Web服務的合同,第一種方法

不過,我面臨着與自動生成WADL和XSD的一些問題。


語境

要定義對象這三種格式的交換,我都跟着「合同第一」的方針

  • 從XSD我寫的,我產生的我使用JAXB的模型類;
  • 從我寫的等價原始文件中,我生成了Google Protobuf類(並且在內部有一種方法可將這些類轉換爲JAXB生成的對象,以便擁有一個獨特的模型)。

然而,正如我希望我的用戶能夠以生成自己的班級過,我想和大家分享這些模式文件(的.xsd和.proto),並讓他們與自動生成很好地整合WADL

爲此,得益於this wiki頁面:

  • 我已經暴露下
    • /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(); 
        } 
    } 
    

這種方式,下面出現在WADL,當我打/rest/application.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. 如果沒有(如,因爲我跟隨這「契約優先」的做法我並不需要它),是有辦法「覆蓋」與我的手寫的XSD內容時/rest/application.wadl/xsd0.xsd被擊中? (我用Google搜索了一圈,發現大約WadlResource,以生成定製WADL,但沒有發現任何有關XSD一代本身)


預先感謝您的幫助!

M.


編輯

1)我提出的問題澤西團隊,並得到了答覆: http://java.net/projects/jersey/lists/users/archive/2012-06/message/8

2)我養的一票(JERSEY-1230) ,根據帕維爾的指示。 我目前正在追蹤自己提交修復或從澤西團隊獲得修復。

+2

問題是固定的,請參閱http://java.net/jira/browse/JERSEY-1230 –

+0

你應該張貼以上的回答爲你自己的問題,然後接受它(從沒有答案Q的列表中清除它)。 – scottb

回答

1

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,新澤西州已生成的語法將不會被包含在返回WADL。現在