JAX-WS:针对客户端和服务器端的SOAP处理程序测试

这是JAX-WS SOAP处理程序的第3部分。 第1部分:服务器端的SOAP处理程序第2部分:客户端的SOAP处理程序的测试结果。 请参阅以下用例

1.有效的MAC地址

从上至下显示具有有效计算机MAC地址的客户端,该客户端向已发布的服务发送请求。

Client : getHeaders()......
Client : getHeaders()......
Client : handleMessage()......
Current IP address : 192.168.0.2
Current MAC address : 90-4C-E5-44-B9-8F
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
	<S:Header>
		<macAddress xmlns="http://ws.mkyong.com/" 
			xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" 
			SOAP-ENV:actor="http://schemas.xmlsoap.org/soap/actor/next">
				90-4C-E5-44-B9-8F
		</macAddress>
	</S:Header>
	<S:Body>
		<ns2:getServerName xmlns:ns2="http://ws.mkyong.com/"/>
	</S:Body>
</S:Envelope>
Client : handleMessage()......
Client : close()......
mkyong server

2.无效的MAC地址

从上到下显示了具有无效计算机MAC地址的客户端,该客户端向已发布的服务发送请求,并获得SOAPFaultException

Client : getHeaders()......
Client : getHeaders()......
Client : handleMessage()......
Current IP address : 192.168.0.2
Current MAC address : 90-4C-E5-44-B9-00
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
	<S:Header>
		<macAddress xmlns="http://ws.mkyong.com/" 
			xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" 
			SOAP-ENV:actor="http://schemas.xmlsoap.org/soap/actor/next">
				90-4C-E5-44-B9-00
		</macAddress>
	</S:Header>
	<S:Body>
		<ns2:getServerName xmlns:ns2="http://ws.mkyong.com/"/>
	</S:Body>
</S:Envelope>
Server : handleMessage()......
Server : close()......
Client : handleFault()......
Client : close()......
Exception in thread "main" javax.xml.ws.soap.SOAPFaultException: Invalid mac address, access is denied.
        at com.sun.xml.internal.ws.fault.SOAP11Fault.getProtocolException(Unknown Source)
        at com.sun.xml.internal.ws.fault.SOAPFaultBuilder.createException(Unknown Source)
        at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(Unknown Source)
        at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(Unknown Source)
        at com.sun.xml.internal.ws.client.sei.SEIStub.invoke(Unknown Source)
        at $Proxy29.getServerName(Unknown Source)
        at com.mkyong.client.WsClient.main(WsClient.java:13)
Caused by: javax.xml.ws.soap.SOAPFaultException: Invalid mac address, access is denied.
       //...

做完了

结论

简而言之,Web服务处理程序只是在客户端或服务器端拦截传入和传出SOAP消息的拦截器,它还能够操纵SOAP消息值。

下载源代码

下载它– JAX-WS-Handler-Example.zip (21KB)

翻译自: https://mkyong.com/webservices/jax-ws/jax-ws-soap-handler-testing-for-client-and-server-side/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值