随笔 - 312, 文章 - 14, 评论 - 1393, 引用 - 0
数据加载中……

WebService大讲堂之Axis2(10):使用soapmonitor模块监视soap请求与响应消息

本文为原创,如需转载,请注明作者和出处,谢谢!

上一篇:WebService大讲堂之Axis2(9):编写Axis2模块(Module)

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

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

1步:部署AppletServlet

    由于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文件,在其中加入如下的内容:

<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文件的内容如下:
<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的界面,当访问MyServicegetGreeting方法时,在Tomcat控制台与Applet中都显示了相应的SOAP请求和响应消息。如图1和图2分别是调用了两次getGreeting方法后输出的SOAP请求和响应消息。



图1



图2

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

    <!--  引用logging模块  -->
    
<module ref="logging"/>
    
<!--  引用soapmonitor模块  -->
    
<module ref="soapmonitor"/>




Android开发完全讲义(第2版)(本书版权已输出到台湾)

http://product.dangdang.com/product.aspx?product_id=22741502



Android高薪之路:Android程序员面试宝典 http://book.360buy.com/10970314.html


新浪微博:http://t.sina.com.cn/androidguy   昵称:李宁_Lining

posted on 2009-02-17 09:22 银河使者 阅读(9184) 评论(8)  编辑  收藏 所属分类: java 原创webservice

评论

# re: WebService大讲堂之Axis2(10):使用soapmonitor模块监视soap请求与响应消息  回复  更多评论   

除了用模块还有没有其他方法可以获取SOAP头的?谢谢
2009-05-18 12:03 | 我有问题

# re: WebService大讲堂之Axis2(10):使用soapmonitor模块监视soap请求与响应消息  回复  更多评论   

SOAP消息是底层的信息,除非提供了接口,否则无法获得这些信息。我一般是通过模块获得soap消息,但通过其他方式还没试过。
2009-05-18 12:49 | 银河使者

# re: WebService大讲堂之Axis2(10):使用soapmonitor模块监视soap请求与响应消息  回复  更多评论   

大哥,你的QQ群满人了阿,加不进去阿,加我阿,我qq451684548
2009-07-14 09:52 | 大佬

# re: WebService大讲堂之Axis2(10):使用soapmonitor模块监视soap请求与响应消息  回复  更多评论   

我有按照你上面的配置,启动能成功。但是访问服务http://localhost:8080/axis2/SOAPMonitor的时候老是不能弹出什么东西
就光秃秃的一个页面,什么都没有显示,服务器也没有报错!
这个是什么原因啊?没实现你上面说的那个applet界面呀!!
2009-10-24 21:14 | zuowangxi

# re: WebService大讲堂之Axis2(10):使用soapmonitor模块监视soap请求与响应消息  回复  更多评论   

@zuowangxi
有可能是你的浏览器阻止了applet的显示,试试修改一下浏览器的安全隔离级别
2010-01-21 17:25 | Mr.Blue

# re: WebService大讲堂之Axis2(10):使用soapmonitor模块监视soap请求与响应消息  回复  更多评论   

后面的章节怎么没有了?
2010-06-03 18:09 | web

# re: WebService大讲堂之Axis2(10):使用soapmonitor模块监视soap请求与响应消息  回复  更多评论   

在WEB-INFO/lib里面已经有了soapmonitor的jar,还有必要把解压出来的东西放到classes下面吗?
2010-09-10 21:21 | A.L

# re: WebService大讲堂之Axis2(10):使用soapmonitor模块监视soap请求与响应消息[未登录]  回复  更多评论   

好东西,这十讲是过了一遍了,就是不知道怎么用到实际项目开发中去~~~
2011-08-04 10:03 | frank

只有注册用户登录后才能发表评论。


网站导航: