2011-04-29 59 views
0

我改變了標題來概括這個問題,這個問題確實不是Axis2特有的。我最終完全放棄了Axis2並切換到Metro/JAX-WS,但我現在正在認真考慮放棄這兩者並切換到OpenSAML。我努力在這裏得到解答的真正問題是,如何構建實際工作的基於複雜標準的SOA服務。用於構建SOA服務和客戶端的Maven?

最初的措辭是:有人可以粘貼工作 maven pom的示例可以用我可以使用的默認值調用Axis2 java2wsdl嗎?這是一個行爲良好的命令行咒語。

-o target/generated-sources/java2wsdl \ 
    -l "http://localhost:9763/services/PolicyService" \ 
    -tn urn:sesgg:sc:security:1.0.spec.PolicyService \ 
    -tp ps \ 
    -stn urn:oasis:names:tc:SAML:2.0:protocol \ 
    -stp samlp \ 
    -of PolicyService.wsdl \ 
    -sn PolicyService \ 
    -cp "../../Schema/target/Schema-1.0-SNAPSHOT.jar target/PolicyService-1.0-SNAPSHOT.jar" \ 
    -cn com.technica.pbac.ps.PolicyService \ 

我所做的每件事都真的會產生真正的結果;例如奇怪的顛倒名稱空間(例如http://xmldsig._09._2000.w3.org/xsd)。你能解釋一下爲什麼這樣以及如何阻止它?

似乎有很多java2wsdl在那裏,期望完全不同的參數,命令行和maven pom之間幾乎沒有一致性。

回答

1

沒有反應,所以我會張貼我自己的實驗的當前結果,以幫助其他與 類似的問題。不能保證這是正確的,直到測試結束,但至少現在我得到的結果,我可以忍受看着在Eclipse:

<build> 
    <plugins> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-compiler-plugin</artifactId> 
      <version>2.3.2</version> 
      <configuration> 
       <source>1.6</source> 
       <target>1.6</target> 
      </configuration> 
     </plugin> 
     <plugin> 
      <groupId>org.jvnet.jaxb2.maven2</groupId> 
      <artifactId>maven-jaxb2-plugin</artifactId> 
      <version>0.7.5</version> 
      <configuration> 
       <schemaExcludes> 
        <exclude>*saml*.xsd</exclude> 
       </schemaExcludes> 
       <strict>true</strict> 
       <extension>true</extension> 
      </configuration> 
      <executions> 
       <execution> 
        <goals> 
         <goal>generate</goal> 
        </goals> 
       </execution> 
      </executions> 
     </plugin> 
     <plugin> 
      <groupId>org.apache.axis2</groupId> 
      <artifactId>axis2-java2wsdl-maven-plugin</artifactId> 
      <version>1.5.4</version> 
      <executions> 
       <execution> 
        <goals> 
         <goal>java2wsdl</goal> 
        </goals> 
       </execution> 
      </executions> 
      <configuration> 
       <id>Generate WSDL based on PolicyService Interface</id> 
       <serviceName>PolicyService</serviceName> 
       <className>com.technica.pbac.ps.PolicyServiceImpl</className> 
       <targetNamespace>http://sesgg/sc/security/1.0/spec/PolicyService</targetNamespace> 
       <targetNamespacePrefix>sesgg</targetNamespacePrefix> 
       <schemaTargetNamespace>http://sesgg/sc/security/1.0/spec/PolicyService</schemaTargetNamespace> 
       <schemaTargetNamespacePrefix>sesgg</schemaTargetNamespacePrefix> 
       <elementFormDefault>qualified</elementFormDefault> 
       <extension>false</extension> 
       <package2Namespace> 
        <property> 
         <name>urn:sesgg:sc:security:1.0:spec:PolicyService</name> 
         <value>http://sesgg/sc/security/1.0/spec/PolicyService</value> 
        </property> 
        <property> 
         <name>com.technica.pbac.ps</name> 
         <value>http://com.technica.pbac.ps</value> 
        </property> 
        <property> 
         <name>oasis.names.tc.saml._2_0.protocol.xsd</name> 
         <value>http://oasis/names/tc/saml/2.0/protocol</value> 
        </property> 
        <property> 
         <name>oasis.names.tc.saml._2_0.protocol</name> 
         <value>http://oasis/names/tc/saml/2.0/protocol</value> 
        </property> 
       </package2Namespace> 
       <episodes> 
        <episode> 
         <groupId>Technica-PBAC</groupId> 
         <artifactId>Schema-1.0-SNAPSHOT.jar</artifactId> 
        </episode> 
       </episodes> 
       <outputFileName>target/generated-sources/java2wsdl/PolicyService.wsdl</outputFileName> 
       <filename>target/generated-sources/java2wsdl/services.xml</filename> 
       <locationUri>http://localhost:9763/services/PolicyService</locationUri> 
      </configuration> 
     </plugin> 
     <plugin> 
      <groupId>org.apache.axis2</groupId> 
      <artifactId>axis2-wsdl2code-maven-plugin</artifactId> 
      <version>1.5.4</version> 
      <executions> 
       <execution> 
        <goals> 
         <goal>wsdl2code</goal> 
        </goals> 
        <configuration> 
         <wsdlFile>target/generated-sources/java2wsdl/PolicyService.wsdl</wsdlFile> 
         <packageName>com.technica.pbac.ps</packageName> 
         <outputDirectory>target/generated-sources/wsdl2java</outputDirectory> 
         <unwrap>true</unwrap> 
         <allPorts>true</allPorts> 
         <databindingName>adb</databindingName> 
         <generateServerSide>true</generateServerSide> 
         <generateAllClasses>true</generateAllClasses> 
         <generateServicesXml>true</generateServicesXml> 
         <generateTestcase>true</generateTestcase> 
         <overWrite>true</overWrite> 
         <serviceName>PolicyService</serviceName> 
         <syncMode>sync</syncMode> 
         <backwardCompatible>false</backwardCompatible> 
        </configuration> 
       </execution> 
      </executions> 
     </plugin> 
    </plugins> 
    <pluginManagement> 
     <plugins> 
      <plugin> 
       <groupId>org.apache.axis2</groupId> 
       <artifactId>axis2-java2wsdl-maven-plugin</artifactId> 
       <version>1.5.4</version> 
      </plugin> 
      <plugin> 
       <groupId>org.apache.axis2</groupId> 
       <artifactId>axis2-wsdl2code-maven-plugin</artifactId> 
       <version>1.5.4</version> 
      </plugin> 
     </plugins> 
    </pluginManagement> 
</build> 

一個警告:我真的懷疑它的權利運行JAXB,的Java2WSDL, wsdl2java並在一個pom中編譯階段。目前java2wsdl運行 wsdl2java這種方式顯然是不正確的。這個pom是雙重可疑的,因爲java2wsdl需要一個編譯的jar來運行,並且似乎正在使用之前運行剩下的一個。它是在mvn clean之後再次工作的熊。我可能會把它分解成幾個poms,並在我做時調整這個答案。

0

我答應用大約「正確」的東西來擴展這個答案。這是迄今爲止的進展,我仍然不能確定100%是正確的。稍後再詳細介紹。

這都是基於Oasis發佈的模式堆棧來定義XACML標準的XACML和SAML-P。 XSD已被收集到Commons-Schema模塊(未顯示)中,用於修復幾個Oasis錯誤,並使用JAX-B編譯爲Java類。這些類是下面描述的服務的基礎。 schema.episode.path和schema.catalog.path屬性指向此模塊中的文件。

我將每個服務(本例中爲PolicyService)分成兩個maven模塊。 PolicyService-SVC是服務和POM看起來是這樣的:

<plugin> 
    <groupId>org.codehaus.mojo</groupId> 
    <artifactId>jaxws-maven-plugin</artifactId> 
    <executions> 
    <execution> 
     <id>Generate WSDL</id> 
     <phase>generate-resources</phase> 
     <goals> 
     <goal>wsgen</goal> 
     </goals> 
     <configuration> 
     <sei>com.technica.pbac.ps.PolicyService</sei> 
     <genWsdl>true</genWsdl> 
     <keep>true</keep> 
     <verbose>true</verbose> 
     <extension>true</extension> 
     <catalog>${schema.catalog.path}</catalog> 
     <xjcArg>-episode</xjcArg> 
     <xjcArg>${schema.episode.path}</xjcArg> 
     <xjcArg>-catalog</xjcArg> 
     <xjcArg>${schema.catalog.path}</xjcArg> 
     </configuration> 
    </execution> 
    </executions> 
</plugin> 

PolicyService代理是一般代理代碼,任何客戶端或服務可以用它來調用該服務(更多有關此問題的下面)。它的POM看起來是這樣的:

<plugin> 
    <groupId>org.codehaus.mojo</groupId> 
    <artifactId>jaxws-maven-plugin</artifactId> 
    <executions> 
    <execution> 
     <!-- <phase>generate-sources</phase> --> 
     <goals> 
     <goal>wsimport</goal> 
     </goals> 
     <configuration> 
     <wsdlFiles> 
      <wsdlFile>localhost_8080/PolicyService-Svc/PolicyService.wsdl</wsdlFile> 
     </wsdlFiles> 
     <wsdlLocation>http://localhost:8080/PolicyService-Svc/PolicyService?WSDL</wsdlLocation> 
     <sourceDestDir>${project.build.directory}/generated-sources/jaxws</sourceDestDir> 
     <genWsdl>true</genWsdl> 
     <verbose>true</verbose> 
     <extension>true</extension> 
     <catalog>${schema.catalog.path}</catalog> 
     <xjcArg>-episode</xjcArg> 
     <xjcArg>${schema.episode.path}</xjcArg> 
     </configuration> 
    </execution> 
    </executions> 
</plugin> 

現在的問題,我會很感激的建議。儘管Commons-Schema爲所有模式提供了編譯的Java類,但wsgen堅持使用新生成的xsds生成wsdl,這些xsds稍有不同,並且在各種方式上稍微不正確。

作爲錯誤和不同的一個示例,SAML定義了與另一個模式中的同名衝突的擴展元素。所以我修好它在這樣的基礎下議院-架構:

<element name="Extensions" type="samlp:ExtensionsType"> 
    <annotation> 
     <appinfo> 
     <jxb:class name="Extensions-SAML"/> 
     </appinfo> 
</annotation> 
</element> 

但WSGEN/wsimport的這樣的矛盾再次變成了省略這種修正。對構建造成傷害和絕對致命。

另一種是省略所需包括所以日食驗證報告他們的錯誤,直到手動糾正。我的解決方法是定期將生成的wsdl和xsds從目標文件夾複製到src/main/webapp/WEB-Inf/wsdl,手動修復它們,並調整poms以使用此文件夾而不是目標中生成的文件夾。這適用於從非服務客戶端調用服務。我將同樣的wsdls和xsds複製到類似的客戶端文件夾中,並確保pom引用這些文件,而不是那些jaxws在該模塊中生成的文件。

當任何服務需要通過其代理調用另一個服務時,我無法解決問題。調用服務的代理jar(其重要基礎類的版本略有不同)現在與調用服務jar(基於Commons-Schema的JAXB生成的類)混合在一起,這不會造成任何麻煩。

有人能請指教嗎?謝謝!

0

這個問題的最終答案確實是放棄嘗試修復破壞的模式和工具,並切換到OpenSAML,它已經做到了這一點。對於XACML 2.0編譯器和基於它的Web服務,這很好。但是對於XACML 3.0編譯器來說,它是平淡無奇的,因爲OpenSAML不支持XACML 3.0並且沒有計劃這麼做,所以我必須自己處理。但有了XACML 2.0的經驗,我最終得到了兩個工作。這個項目比過去更加痛苦,「強大的」工具讓它變得更加困難。