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

AXIS2:如何发布webservice .

发布时间:2020-12-16 23:43:58 所属栏目:安全 来源:网络整理
导读:一种是打aar包放在指定位置(适合发布),一种是不打aar包(适合调试)。 ? 说明:Eclipse版本3.4.2、tomcat版本6、AXIS2版本1.5.1、EclipseTomcatPlugin3.2.1 准备工作: 下载 WAR (Web Archive) Distribution “This will be the web application of Axis2

一种是打aar包放在指定位置(适合发布),一种是不打aar包(适合调试)。

?

说明:Eclipse版本3.4.2、tomcat版本6、AXIS2版本1.5.1、EclipseTomcatPlugin3.2.1

准备工作:

下载WAR (Web Archive) Distribution

“This will be the web application of Axis2 which can be deployed in most of the servlet containers.”

http://labs.xiaonei.com/apache-mirror/ws/axis2/1_5_1/axis2-1.5.1-war.zip

下载完后解压至tomcat安装目录下的webapps文件夹下,启动tomcat后,在webapps目录下会生成axis2文件夹。

访问http://localhost:8080/axis2/

?点击Service会进入Service列表页面,当前只有一个Version服务。

一.打包发布:

在Eclipse下建立Java Project,工程名HelloFriend。

建包com.dm.service,包下建类HelloFriend。代码如下:

?

Java代码
[c-sharp] view plain copy print ?
  1. package?com.dm.service;?????
  2. public?class?HelloFriend?{?????
  3. ?private?String?friendName?=?"aaa";?????
  4. ?public?String?sayHello(String?name)?{return?"Hello,?"?+?name?+?".";?}?????
  5. ?public?String?saySorry(String?name)?{return?"Sorry,?"?+?name?+?".";?}?????
  6. ?public?String?getName()?{return?friendName;?}?????
  7. }????
在工程下新文件夹services/HelloFriend,HelloFriend下按类HelloFriend.java包路径建文件路径com/dm/service,
最后将编译后的HelloFriend.class拷入com/dm/service下。
HelloFriend文件夹下在新建文件夹META-INF,META-INF下新建services.xml。
最后在Windows命令行下进到services/HelloWord目录下运行: jar cvf HelloFriend.aar . (最后有个点号),
会在HelloFriend目录下生成HelloFriend.aar包。

services.xml内容如下:

Xml代码
[c-sharp] view plain copy print ?
  1. <service?name="HelloFriend">????
  2. ????<description>Hello?Friend?Example</description>????
  3. ????<parameter?name="ServiceClass">com.dm.service.HelloFriend</parameter>????
  4. ????<operation?name="sayHello">????
  5. ????????<messageReceiver?class="org.apache.axis2.rpc.receivers.RPCMessageReceiver"?/>????
  6. ????</operation>????
  7. ????<operation?name="saySorry">????
  8. ????????<messageReceiver?class="org.apache.axis2.rpc.receivers.RPCMessageReceiver"?/>????
  9. ????</operation>????
  10. ????<operation?name="getName">????
  11. ????????<messageReceiver????
  12. ????????????class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver"?/>????
  13. ????</operation>????
  14. </service>????
最后的工程目录如下:
??

?

把HelloFriend.aar拷入tomcat安装目录下的webapps/axis2/WEB-INF/services下,再进入http://localhost:8080/axis2/进入Services就会看到HelloFriend了。

?

二.不打包发布:

在Eclipse下新建Tomcat Project,工程名:HelloWorld。新建包com.cm.service,新建类HelloWorld,代码如下:

[java] view plain copy print ?
  1. package?com.dm.service;??
  2. public?class?HelloWorld?{??
  3. ????public?String?sayHello(String?name)?{return?"Hello,?"?+?name?+?".";?}??
  4. ????public?String?saySorry(String?name)?{return?"Hello,?"?+?name?+?".";?}??
  5. ????public?String?getWorld()?{return?"Hello,?world!";}??
  6. }??

?

在WEB-INF目录下新建web.xml文件,内容如下:

[xhtml] view plain copy print ?
  1. <?xml?version="1.0"?encoding="UTF-8"?>??
  2. <web-app?id="wmf"?version="2.4"?xmlns="http://java.sun.com/xml/ns/j2ee"??
  3. ????xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"??
  4. ????xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee?http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">??
  5. ????<servlet>??
  6. ????????<servlet-name>AxisServlet</servlet-name>??
  7. ????????<servlet-class>org.apache.axis2.transport.http.AxisServlet</servlet-class>??
  8. ????????<load-on-startup>1</load-on-startup>??
  9. ????</servlet>??
  10. ????<servlet-mapping>??
  11. ????????<servlet-name>AxisServlet</servlet-name>??
  12. ????????<url-pattern>/services/*</url-pattern>??
  13. ????</servlet-mapping>??
  14. </web-app>??

把tomcat安装目录下的webapps/axis2/WEB-INF下的modules、service和conf文件件拷至HelloWorld下的WEB-INF目录下。

把lib下的如下jar包夜拷过去,以下jar包已经是最精简的了。

?

?

然后再services下新建HelloWorld/META-INF路径,META-INF下新建services.xml,内容如下:

[xhtml] view plain copy print ?
  1. <service?name="HelloWorld">??
  2. ????<description>??
  3. ????????HelloWorld?Service?Example??
  4. ????</description>??
  5. ????<parameter?name="ServiceClass">??
  6. ????????com.dm.service.HelloWorld????
  7. ????</parameter>??
  8. ????<operation?name="sayHello">??
  9. ????????<messageReceiver?class="org.apache.axis2.rpc.receivers.RPCMessageReceiver"?/>??
  10. ????</operation>??
  11. ????<operation?name="saySorry">??
  12. ????????<messageReceiver?class="org.apache.axis2.rpc.receivers.RPCMessageReceiver"?/>??
  13. ????</operation>??
  14. ????<operation?name="getWorld">??
  15. ????????<messageReceiver?class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver"?/>??
  16. ????</operation>??
  17. </service>??

?

启动tomcat后访问http://localhost:8080/HelloWorld/services/HelloWorld?wsdl能看到服务信息了。

?

三.总结:

1. 第一种方法不用打aar包,把整个文件夹拷过去也是可以的。

2. 第二种方式只是相当于是在AXIS2工程上再开发。(得引入AXIS2的包,web.xml里要加AxisServlet)。同样需要services.xml。

3. 此文只是告诉大家怎么把AXIS2加到已有工程里来,至于servicex.xml格式怎么样,这里没有分析。

(编辑:李大同)

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

    推荐文章
      热点阅读