很多朋友都在討論XFire和AXIS的優(yōu)劣,就我而言,更喜歡XFire,至少目前是如此。
最討厭axis要生成一段東西,才能在wsdd文件注冊(cè)服務(wù),很是麻煩。而且,調(diào)試時(shí)要是設(shè)成debug,那可就慘了,一大堆用戶信息,出了異常還不好捕捉。相比之下,XFire的開(kāi)發(fā)就要簡(jiǎn)單的點(diǎn)多了,包括代碼開(kāi)發(fā),配置,還是返回自定義類型,真是easy。不過(guò),客戶端調(diào)用時(shí)(動(dòng)態(tài)模式或根據(jù)WSDL生成Client Stub),返回的自定義類型是否能順利取得,到時(shí)需要研究一下。
今天,就返回類型問(wèn)題困了好久,還好已經(jīng)解決了。
對(duì)象的屬性、函數(shù)的參數(shù)和返回值如果為int、String、Date等普通類型以及由普通類型組成的復(fù)雜對(duì)象都無(wú)需定義。我見(jiàn)到只有兩種情況需要定義:
- 無(wú)法使用泛型定義Collection中元素的類型時(shí)。
- 需要為屬性定義不同的名字,或者定義復(fù)雜對(duì)象里的某些屬性不要輸出。
1 <?xml version="1.0" encoding="UTF-8"?>
2 <mappings>
3 <mapping>
4 <method name="getResources">
<!--配置getResources服務(wù)的返回值,List內(nèi)對(duì)象為Resource-->
5 <return-type componentType="com.test.Resource" />
6 </method>
7
8 <method name="getAuthentication">
9 <return-type componentType="com.test.Authentication" />
10 </method>
11 </mapping>
12 </mappings>
2 <mappings>
3 <mapping>
4 <method name="getResources">
<!--配置getResources服務(wù)的返回值,List內(nèi)對(duì)象為Resource-->
5 <return-type componentType="com.test.Resource" />
6 </method>
7
8 <method name="getAuthentication">
9 <return-type componentType="com.test.Authentication" />
10 </method>
11 </mapping>
12 </mappings>
若返回的Javabeans存在Collections 時(shí),需要定義一個(gè)與javabean相關(guān)的文件名,如User.aegis.xml,并且放在相同的目錄下:
<?xml version="1.0" encoding="UTF-8"?>
<mappings>
<mapping>
<!--User bean ,包含了一個(gè) List , 其中的對(duì)象是Resource -->
<property name="resources" componentType="com.test.Resource" />
<!--配置User類,忽略內(nèi)嵌的roles屬性不要輸出XML-->
<property name="roles" ignore="true" />
</mapping>
</mappings>
<mappings>
<mapping>
<!--User bean ,包含了一個(gè) List , 其中的對(duì)象是Resource -->
<property name="resources" componentType="com.test.Resource" />
<!--配置User類,忽略內(nèi)嵌的roles屬性不要輸出XML-->
<property name="roles" ignore="true" />
</mapping>
</mappings>
有空將XFire使用總結(jié)一下,也貼出來(lái)。