Axis2自带监控模块soapmonitor,soapmonitor会监视soap请求和响应信息,并以Applet方式在页面输出。
配置和使用soapmonitor模块:
1、部署servlet和applet。
将 axis2\WEB-INF\lib\axis2-soapmonitor-servlet-1.6.1.jar 解压,然后将解压后的org文件夹分别拷贝至axis2、axis2\WEB-INF\classes路径下。
2、启用SOAPMonitorService。
Axis2中,文件axis2\WEB-INF\web.xml中,servlet SOAPMonitorService的配置默认是注释掉的,找到相应位置,去除相关注释。
<servlet> <servlet-name>SOAPMonitorService</servlet-name> <display-name>SOAPMonitorService</display-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> <init-param> <param-name>SOAPMonitorHostName</param-name> <param-value>localhost</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模块。
<service name="myService"> <description> Web Service例子 </description> <module ref="soapmonitor"/><!-- 引入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" /> <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-only" class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver" /> </messageReceivers> </service>
4、service.MyService.java
package service; public class MyService { public String getGreeting(String name) { return "您好 " + name; } public void update(String data) { System.out.println("<" + data + ">已经更新"); } }
5、发布webservice
将META-INF\services.xml、service\MyService.class打成.aar包(jar -cvf ws.jar *.*).
将生成的.aar包拷贝至axis2\WEB-INF\services目录下。
6、新建客户端类
package client; import javax.xml.namespace.QName; import org.apache.axis2.addressing.EndpointReference; import org.apache.axis2.client.Options; import org.apache.axis2.rpc.client.RPCServiceClient; public class MyServiceRPCClient { public static void main(String[] args) throws Exception { //使用RPC方式调用WebService RPCServiceClient serviceClient = new RPCServiceClient(); Options options = serviceClient.getOptions(); // 指定调用WebService的URL EndpointReference targetEPR = new EndpointReference("http://localhost:8080/axis2/services/myService"); options.setTo(targetEPR); // 指定getGreeting方法的参数值 Object[] opAddEntryArgs = new Object[] {"张三"}; //指定getGreeting方法返回值的数据类型的Class对象 Class<?>[] classes = new Class<?>[] {String.class}; // 指定要调用的getGreeting方法及WSDL文件的命名空间,注意命名空间 QName opAddEntry = new QName("http://service", "getGreeting"); //调用getGreeting方法并输出该方法的返回值 System.out.println(serviceClient.invokeBlocking(opAddEntry, opAddEntryArgs, classes)[0]); //调用 update 方法,该方法有入参,无返回值。 opAddEntry = new QName("http://service", "update"); opAddEntryArgs = new Object[]{"测试update"}; //无返回值的webservice,使用invokeRobust进行调用。 serviceClient.invokeRobust(opAddEntry, opAddEntryArgs); } }
7、打开soap监控器,http://localhost:8080/axis2/SOAPMonitor,效果如下:
8、执行客户端程序,再次查看soap监控器。
http://huangqiqing123.iteye.com/blog/1455755