这是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/