WebService实现包--AXIS2
深度探索 Axis2:AXIOM:
http://www.ibm.com/developerworks/cn/webservices/ws-java2/index.html
?
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很简单嘛:
理论真无聊,还是来看实例吧。
打开 Eclipse, 创建一个新Project, 新建一个叫userguide.clients的包, 把"samples\userguide\src\userguide\clients" 下面的文件都copy到那个包下面, 把AXIS2的lib下面的jar都加到ilbrary里面去(应该不用全加,懒一点就全加了吧.) 发现了关于echo的调用的方式, 居然有五个:
EchoBlockingClient
EchoBlockingDualClient
EchoBlockingWsaBasedClient
EchoNonBlockingClient
EchoNonBlockingDualClient
一个一个看吧.
public class EchoNonBlockingDualClient { private static EndpointReference targetEPR = new EndpointReference("http://127.0.0.1:8080/axis2/services/MyService"); public static void main(String[] args) { try { OMElement payload = ClientUtil.getEchoOMElement(); Call call = new Call(); call.setTo(targetEPR); //The boolean flag informs the axis2 engine to use two separate transport connection //to retrieve the response. call.engageModule(new QName(Constants.MODULE_ADDRESSING)); call.setTransportInfo(Constants.TRANSPORT_HTTP, Constants.TRANSPORT_HTTP, true); //Callback to handle the response Callback callback = new Callback() { public void onComplete(AsyncResult result) { try { StringWriter writer = new StringWriter(); result.getResponseEnvelope().serializeWithCache(XMLOutputFactory.newInstance() .createXMLStreamWriter(writer)); writer.flush(); System.out.println(writer.toString()); } catch (XMLStreamException e) { reportError(e); } } public void reportError(Exception e) { e.printStackTrace(); } }; //Non-Blocking Invocation call.invokeNonBlocking("echo", payload, callback); //Wait till the callback receives the response. while (!callback.isComplete()) { Thread.sleep(1000); } //Need to close the Client Side Listener. call.close(); } catch (AxisFault axisFault) { axisFault.printStackTrace(); } catch (Exception ex) { ex.printStackTrace(); } } }?
?
?
?