资源预览内容
第1页 / 共14页
第2页 / 共14页
第3页 / 共14页
第4页 / 共14页
第5页 / 共14页
第6页 / 共14页
第7页 / 共14页
第8页 / 共14页
第9页 / 共14页
第10页 / 共14页
亲,该文档总共14页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述
Axis2集成Spring (POJO)以前用过Axis2的,但是想再次用的时候居然还得花大半天时间,哭了都,老老实实做个笔记吧。本示例是在 Axis2 通过 外部 Spring容器 获取指定的实现Bean,以提供服务。全部自己写WSDL和服务实现类,不使用 Axis2提供的 Java2WSDL 和 WSDL2Java 工具(生成的太丑,太臃肿)。文件: SampleAxis2SpringPojoWebService.zip大小: 13KB下载: 下载压缩包中省略了 axis2-web中所有的 JSP,和Axis2 、Spring及其所以来的jar包,请自行追加。README.txtAxis2 工程一般的目录结构SampleWebApp * META-INF/* WEB-INF/ classes/* lib/* conf axis2.xml modules/ modules.list *.mar services services.list *.aar sampleWebService (sampleWebService.aar) * META-INF services.wsdl service.xml- axis2.xmlaxis2.xsd (axis2-1.4.1-src.zipaxis2-1.4.1moduleskernelresources)- service.xmlservices.xsd (axis2-1.4.1-src.zipaxis2-1.4.1moduleskernelresources)如果你使用Axis2在 0.91 版本以上,你可以不使用 ARR 压缩文件,而直接创建一个相应的目录结构即可。- services.wsdl该文件的主文件名可以任意注意: 的 name 属性的值 必须为 services.wsdl 父目录(META-INF)的父目录名(sampleWebService)示例工程 SampleAxis2SpringPojoWebService 运行步骤拷贝以下Jar文件到 SampleAxis2SpringPojoWebService/WebContent/WEB-INF/lib 目录下:axis2-1.5.1-bin.zip/axis2-1.5.1/lib/*.jarspring-framework-2.5.6-with-dependencies.zip/spring-framework-2.5.6/dist/spring.jarspring-framework-2.5.6-with-dependencies.zip/spring-framework-2.5.6/dist/modules/*.jarspring-framework-2.5.6-with-dependencies.zip/spring-framework-2.5.6/lib/*/*.jar拷贝以下Jar文件到 SampleAxis2SpringPojoWebService/WebContent/axis2-web/ 目录下:axis2-1.5.1-bin.zip/axis2-1.5.1/webapp/axis2-webweb.xmlSampleAxis2SpringPojoWebServiceorg.springframework.web.context.ContextLoaderListenercontextConfigLocation/WEB-INF/applicationContext.xmlAxisServletorg.apache.axis2.transport.http.AxisServlet axis2.xml.path /WEB-INF/conf/axis2.xml axis2.xml.url http:/localhot/myrepo/axis2.xml axis2.repository.path /WEB-INF axis2.repository.url http:/localhot/myrepo 1AxisAdminServletorg.apache.axis2.transport.http.AxisAdminServletAxisServlet/servlet/AxisServletAxisServlet*.jws AxisServlet/services/*AxisAdminServlet/axis2-admin/*index.jspindex.htmlindex.htmdefault.htmldefault.htmdefault.jspapplicationContext.xml services.xmlthis is a Sample by btpka3.com.org.apache.axis2.extensions.spring.receivers.SpringServletContextObjectSupplier org.apache.axis2.extensions.spring.receivers.SpringAppContextAwareObjectSuppliermyAddServiceBeanme.sample.MyAddServicetruetrueservices.wsdlmyAdddfdiiiioooooooddee MyAddService.java package me.sample;/* 一个示例用Web Service的接口。该接口中的方法与WSDL上公布的方法原型一致。* * author btpka3163.com* */public interface MyAddService /* 用于计算两个数的和。* * param num1* 数值1* param num2* 数值2* return num1与num2的和*/float myAdd(float num1, float num2);MyAddServiceImpl.java package me.sample;/* 这是Web Service接口的实现类,可以额外拥有其他一些不公开的方法。* * author btpka3163.com* */public class MyAddServiceImpl implements MyAddService /* inheritDoc*/Overridepublic float myAdd(float num1, float num2) System.out.println(INVOKED : num1=+num1+, num2=+num2);return num1 + num2;MyClient.java package me.sample;import javax.xml.namespace.QName;import org.apache.axis2.AxisFault;import org.apache.axis2.addressing.EndpointReference;import org.apache.axis2.client.Options;import org.apache.axis2.rpc.client.RPCServiceClient;public class MyClient public static void main(String args1) throws AxisFault / Step 1. 创建 Client RPCServiceClient serviceClient = new RPCServiceClient();/ Step 2. 访问设定(路径等)Options options = serviceClient.getOptions();EndpointReference targetEPR = new EndpointReference(http:/localhost:8080/SampleAxis2SpringPojoWebService/services/myAddService);options.setTo(targetEPR);/ Step 3.1. 准备方法调用(设定方法名)QName opGetWeather = new QName(http:/me.test, myAdd);/ Step 3.2. 准备方法调用(设定参数)float num1 = 3;float num2 = 2;Object opGetWeatherArgs = new Object num1, num2 ;/ Step 3.3. 准备方法调用(设定返回值类型)SuppressWarnings(unchecked)Class returnTypes = new Class Float.class ;/ Step 4. 执行方法调用Object response = serviceClient.invokeBlocking(opGetWeather,opGetWeatherArgs, returnTypes); / Step 5. 取的返回值Float result = (Float) response0;/ Step 6. 检查结果并输出if (result = null) System.out.println(result is null!); else System.out.println(result = + num1 + + + num2 + = + result);
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号