WebService之Axis2快速入门(10): 编写Axis2模块(Module)

在Axis2中提供了一个Axis2模块(soapmonitor),该模块实现了与《WebService大讲堂之Axis2(9):编写Axis2模块(Module)》中实现的logging模块相同的功能,所不同的是,logging模块直接将SOAP请求与响应消息输出到Tomcat控制台中,而soapmonitor模块利用applet直接在页面中输出SOAP请求和响应消息。

下面是配置和使用soapmonitor模块的步骤:    

第1步:部署Applet和Servlet

由于axis2默认情况下已经自带了soapmonitor模块,因此,soapmonitor模块并不需要单独安装。但applet所涉及到的相应的.class文件需要安装一下。在<Tomcat安装目录>\webapps\axis2\WEB-INF\lib目录中找到soapmonitor-1.4.1.jar文件,将该文件解压。虽然applet并不需要soapmonitor-1.4.1.jar文件中所有的.class文件,但为了方便,读者也可以直接将解压目录中的org目录复制到<Tomcat安装目录>\webapps\axis2目录中,Applet所需的.class文件需要放在这个目录。然后再将org目录复制到<Tomcat安装目录>\webapps\axis2\WEB-INF\classes目录中,soapmonitor模块中的Servlet所对应的.class文件需要放在这个目录。

第2步:配置Servlet

打开<Tomcat安装目录>\webapps\axis2\WEB-INF\web.xml文件,在其中加入如下的内容:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<servlet>
    <servlet-name>SOAPMonitorService</servlet-name>
    <servlet-class>
        org.apache.axis2.soapmonitor.servlet.SOAPMonitorService
    </servlet-class>
    <init-param>
        <param-name>SOAPMonitorPort</param-name>
        <param-value>5001</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>SOAPMonitorService</servlet-name>
    <url-pattern>/SOAPMonitor</url-pattern>
</servlet-mapping>

第3步:在services.xml文件中引用soapmonitor模块

与引用logging模块一样,引用soapmonitor模块也需要使用<module>元素,引用soapmonitor模块的services.xml文件的内容如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<service name="myService">
    <description>
        使用logging和soapmonitor模块
    </description>
    <!--  引用logging模块  -->
    <module ref="logging"/>
    <!--  引用soapmonitor模块  -->
    <module ref="soapmonitor"/>
    <parameter name="ServiceClass">
        service.MyService
    </parameter>
    <messageReceivers>
        <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-out"
            class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" />
    </messageReceivers>
</service>

由于soapmonitor模块已经在axis2.xml进行配置了,因此,在本例中不需要再对axis2.xml文件进行配置了。    

第4步:使用soapmonitor模块

启动Tomcat后,在浏览器中输入如下的URL:

http://localhost:8080/axis2/SOAPMonitor  

在浏览器中将出现soapmonitor所带的Applet的界面,当访问MyService的getGreeting方法时,在Tomcat控制台与Applet中都显示了相应的SOAP请求和响应消息。如图1和图2分别是调用了两次getGreeting方法后输出的SOAP请求和响应消息。

09002453_1fhg.jpg

图1


09002454_OI7a.jpg

图2

如果读者想让logging和soapmonitor模块监视部署在Axis2中的所有WebService,可以在axis2.xml文件中使用<module>元素来引用这两个模块,代码如下:

1
2
3
4
<!--  引用logging模块  -->
<module ref="logging"/>
<!--  引用soapmonitor模块  -->
<module ref="soapmonitor"/>

转载于:https://my.oschina.net/kkrgwbj/blog/671907

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值