我比较懒惰,不想把user guide全部翻译,就记录一些点吧。
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的版本,因为里面有例程。
第二步:copy axis2.war到$tomcat_home/webapps目录下面。tomcat好像只能用jdk1.4,我在jdk1.5 用不出来。
第三步:打开 http://localhost:8080/axis2,就可以看到axis2的welcome页面了。点一下validate 和services,看是不是都没有错误。都没有错误的话,就表示deploy成功了。那个adminstration页面可以通过上传文件来hot deploy web service,可以用来remote deploy。
第四步:研究例程。先从"samples/userguide/src"目录下的例程看起。看到写一个web service很简单嘛:
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已经被列出来了。
关于调用web service的东西蛮多,下次写吧。
闽公网安备 35060202000074号