Axis2是全新設計的,在2004年的“Axis峰會”上,大家決定采用新的架構來讓Axis更加的富有彈性,更有效率,并且更加的可配置。Axis2現在具有的一些feature: Speed Low memory foot PRint AXIOM - AXis Object Model Hot Deployment Asynchronous Web Services MEP Support - Message Exchange Patterns Flexibility Stability Component-oriented deployment Transport framework WSDL support
有些feature現在看不懂,還是先動手做一下,感性熟悉一下吧
第一步:下載AXIS2。http://ws.apache.org/axis2/download.cgi。很有趣,在apache的Web Service 的Project目錄下面還看不到AXIS2。要下那個binary的版本,因為里面有例程。
public class MyService { public OMElement echo(OMElement element) throws xmlStreamException { //Praparing the OMElement so that it can be attached to another OM Tree. //First the OMElement should be completely build in case it is not fully built and still //some of the xml is in the stream. element.build(); //Secondly the OMElement should be detached from the current OMTree so that it can be attached //some other OM Tree. Once detached the OmTree will remove its connections to this OMElement. element.detach(); return element; }
public void ping(OMElement element) throws XMLStreamException { //Do some processing } public void pingF(OMElement element) throws AxisFault{ throw new AxisFault("Fault being thrown"); } }
看得出來,函數統一使用OMElement作為參數。在META-INF目錄下面有個services.xml文件: <service name="MyService"> <description> This is a sample Web Service with two Operations,echo and ping. </description> <parameter name="ServiceClass" locked="false">userguide.example1.MyService</parameter> <operation name="echo"> <messageReceiver class="org.apache.axis2.receivers.RawXMLINOutMessageReceiver"/> </operation> <operation name="ping"> <messageReceiver class="org.apache.axis2.receivers.RawXMLINOnlyMessageReceiver"/> </operation> </service> 呵呵,也很簡單嘛。有返回值的就用RawXMLINOutMessageReceiver,沒返回值的就用RawXMLINOnlyMessageReceiver。把它們編譯(要把axis2的jar寫到classpath里去)打包壓到 MyService.aar,包里文件目錄如下: .//META-INF/services.xml ./userguide/example1/MyService.class 把MyService.aar拷貝到$TOMCAT_HOME/webapps/axis2/WEB-INF/services,然后去點一下http://localhost:8080/axis2頁面上的Services,也就是http://localhost:8080/axis2/listServices.jsp,就可以看到MyService已經被列出來了。