加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

WebService的开发模版(Axis2 1.5环境)

发布时间:2020-12-17 02:10:45 所属栏目:安全 来源:网络整理
导读:WebService的开发模版(Axis2 1.5环境) ? 今天在做apache-cxf-2.2.2整合Spring时候,出现了包版本与JDK1.5包冲突的问题,折腾了不少时间,还是没解决。于是改为Axis2开发,暂时绕过问题,完成任务要紧。 ? Axis2已经升级到1.5了,下载地址: http://apache.
WebService的开发模版(Axis2 1.5环境)
?
今天在做apache-cxf-2.2.2整合Spring时候,出现了包版本与JDK1.5包冲突的问题,折腾了不少时间,还是没解决。于是改为Axis2开发,暂时绕过问题,完成任务要紧。
?
Axis2已经升级到1.5了,下载地址:
http://apache.etoak.com/ws/axis2/1_5/axis2-1.5-bin.zip
http://apache.etoak.com/ws/axis2/1_5/axis2-1.5-war.zip
?
两个包,bin是开发包,war是部署包,实际上,如果只用jar包,两个里面的jar都一样用。
?
在IDEA环境下,Axis2的开发环境稍微麻烦些,毕竟没CXF或XFire方便。每次写build.xml脚本也挺麻烦的。这次写个项目模版,方便以后使用。
?
环境:
axis2-1.5
jdk1.5
idea-8.13
apache-tomcat-6.0.20
ant-1.6以上即可
?
一、创建项目
?
使用idea向导创建一个Java项目,项目结构如下图:
testaxis2
├─lib
├─resources
│????└─META-INF
└─src
????????└─mytest
?
二、导入axis2的包
?
解压缩 axis2-1.5-bin.zip到一个目录下,然后直接在idea中引入axis2的包即可。也可以讲axis2的包复制到lib下。
?
三、创建服务
?
axis2服务的创建过程就是写Java类,不要求有接口,有也不会错。
这里创建一个最简单的Service,作为发布对象。
?
package mytest;

/**
* 测试Service
*
* @author leizhimin 2009-8-4 15:46:39
*/

public interface MyService {
????????String doSomething(String taskname);
}
?
package mytest;

/**
* 测试Service
*
* @author leizhimin 2009-8-4 15:48:13
*/

public class MyServiceImpl implements MyService {
???????? public String doSomething(String taskname) {
????????????????System.out.println( "MyServiceImpl is calling doSomething with " + taskname + "!");
???????????????? return taskname + "is finished!";
????????}
}
?
四、描述服务
?
在项目的resourcesMETA-INF文件夹下面,创建services.xml,内容如下:
< service name ="myws" scope ="application" targetNamespace ="http://lavasoft.blog.51cto.com/" >
???????? < messageReceivers >
???????????????? < messageReceiver mep ="http://www.w3.org/2004/08/wsdl/in-only"
???????????????????????????????????????????????? class ="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver" />
???????????????? < messageReceiver mep ="http://www.w3.org/2004/08/wsdl/in-out"
???????????????????????????????????????????????? class ="org.apache.axis2.rpc.receivers.RPCMessageReceiver" />
???????? </ messageReceivers >
???????? < schema schemaNamespace ="http://lavasoft.blog.51cto.com/xsd" />
???????? < parameter name ="ServiceClass" >mytest.MyServiceImpl </ parameter >
</ service >
?
服务名:myws
命名空间: http://lavasoft.blog.51cto.com
服务实现类:mytest.MyServiceImpl
?
五、编写构建脚本
?
用Ant编写build.xml,放到项目根文件夹下。
<? xml version ="1.0" encoding ="UTF-8" ?>
< project name ="ccmws" basedir ="." default ="generate.service" >

???????? < property environment ="env" />
???????? < property name ="AXIS2_HOME" value ="F:/axis2-1.5" />
???????? < property name ="wsdl.uri" value ="./build/myws.wsdl" />

???????? < property name ="build.dir" value ="build" />

???????? < path id ="axis2.classpath" >
???????????????? < fileset dir ="${AXIS2_HOME}/lib" >
???????????????????????? < include name ="*.jar" />
???????????????? </ fileset >
???????????????? < fileset dir ="./lib" >
???????????????????????? < include name ="*.jar" />
???????????????? </ fileset >
???????? </ path >

???????? < target name ="compile.service" >
???????????????? < mkdir dir ="${build.dir}" />
???????????????? < mkdir dir ="${build.dir}/classes" />
???????????????? < javac debug ="on"
???????????????????????????? fork ="true"
???????????????????????????? encoding ="UTF-8"
???????????????????????????? destdir ="${build.dir}/classes"
???????????????????????????? srcdir ="${basedir}/src"
???????????????????????????? extdirs ="**/test/**"
???????????????????????????? classpathref ="axis2.classpath" >
???????????????? </ javac >
???????? </ target >

???????? < target name ="generate.wsdl" depends ="compile.service" >
???????????????? < taskdef name ="java2wsdl"
???????????????????????????????? classname ="org.apache.ws.java2wsdl.Java2WSDLTask"
???????????????????????????????? classpathref ="axis2.classpath" />
???????????????? < java2wsdl className ="mytest.MyServiceImpl"
???????????????????????????????????? outputLocation ="${build.dir}"
???????????????????????????????????? targetNamespace ="http://lavasoft.blog.51cto.com/"
???????????????????????????????????? schemaTargetNamespace ="http://lavasoft.blog.51cto.com/xsd" >
???????????????????????? < classpath >
???????????????????????????????? < pathelement path ="${axis2.classpath}" />
???????????????????????????????? < pathelement location ="${build.dir}/classes" />
???????????????????????? </ classpath >
???????????????? </ java2wsdl >
???????? </ target >

???????? < target name ="generate.service" depends ="compile.service" >
???????????????? < copy toDir ="${build.dir}/classes" failonerror ="false" >
???????????????????????? < fileset dir ="${basedir}/resources" >
???????????????????????????????? < include name ="**/*.xml" />
???????????????????????? </ fileset >
???????????????? </ copy >
???????????????? < jar destfile ="${build.dir}/myws.aar" >
???????????????????????? < fileset excludes ="**/Test.class" dir ="${build.dir}/classes" />
???????????????????????? < fileset includes ="lib/*.jar" dir ="${basedir}" />
???????????????? </ jar >
???????? </ target >

???????? < target name ="clean" >
???????????????? < delete dir ="${build.dir}" />
???????? </ target >
</ project >
?
注意设定一些环境参数,Axis2的目录、发布服务的aar包名字,生成wsdl时候所用的服务实现类,以及命名空间等等。
?
六、运行build脚本打包
?

?
运行后:

?
?
七、部署服务
?
将下载的 axis2-1.5-war.zip解开,得到一个axis2.war,将其解压缩到tomcat的默认的web发布目录webapp下面,比如,在我机器上会产生C:apache-tomcat-6.0.20webappsaxis2的目录,目录下面就是axis2.war里面的内容。
?
然后,将生成的my.aar复制到C:apache-tomcat-6.0.20webappsaxis2WEB-INFservices下面。
?
八、启动tomcat,查看发布服务
?

?
浏览axis2的服务

?
点Services,查看所有的服务

?
在点击服务连接,就可以查看wsdl了:

?
经过这样的测试后,服务发布算成功了。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读