JAX-WS : SOAP handler testing for client and server side

This is the part 3 of JAX-WS SOAP handler. A testing result for part 1 : SOAP handler in server side and part 2 : SOAP handler in client side. See following use cases

1. Valid MAC Address

From top to bottom showing a client with valid computer’s MAC address sending a request to published service.


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. Invalid MAC Address

From top to bottom showing a client with invalid computer’s MAC address sending a request to published service, and get a 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.
       //...

Done.

Conclusion

In short, web service handler is just a interceptor to intercept incoming and outgoing SOAP message, both in client or server side, and it’s able to manipulate the SOAP message values as well.

Download Source Code

Download It – JAX-WS-Handler-Example.zip (21KB)

7 comments on “JAX-WS : SOAP handler testing for client and server side

  1. how to parse a web service through java using soap libraries?

    Reply
  2. when i match the macaddress,it reports error

    Caused by: java.io.IOException: ????????????????????
    at sun.nio.ch.SocketDispatcher.write0(Native Method)
    at sun.nio.ch.SocketDispatcher.write(SocketDispatcher.java:33)
    at sun.nio.ch.IOUtil.writeFromNativeBuffer(IOUtil.java:69)
    at sun.nio.ch.IOUtil.write(IOUtil.java:40)
    at sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:334)
    at sun.net.httpserver.Request$WriteStream.write(Request.java:392)
    at sun.net.httpserver.ChunkedOutputStream.writeChunk(ChunkedOutputStream.java:108)
    at sun.net.httpserver.ChunkedOutputStream.flush(ChunkedOutputStream.java:138)
    at sun.net.httpserver.PlaceholderOutputStream.flush(ExchangeImpl.java:380)
    at java.io.FilterOutputStream.flush(FilterOutputStream.java:123)
    at com.sun.xml.internal.stream.writers.UTF8OutputStreamWriter.flush(UTF8OutputStreamWriter.java:140)
    at com.sun.xml.internal.stream.writers.XMLStreamWriterImpl.flush(XMLStreamWriterImpl.java:386)
    … 20 more

    Reply
  3. when i use soapUI to test any webservice with this handler i receive

    S:Server
    No header block for next actor.

    and the stacktrace, but i need use soapui to test my webservice, what i do to set this ACTOR NEXT in the soapui

    Reply
  4. I have create the server and client side handler correctly and working fine but when I run the publisher or the client code I get below error message.

    Exception in thread “main” javax.xml.stream.FactoryFinder$ConfigurationError: Provider com.ctc.wstx.stax.WstxInputFactory not found

    Please assist

    Reply
  5. class GoodExample {
      public static void main(String args[]) {
       System.out.println("Nice Tutorial");
     }
    }
    
    Reply
  6. Helow sir ,, it’s very nice tutorial posted by you.. can you please post one tutorial with with combination of EJB 3.0(session bean ,JMS) and JAX-ws 2.0, with security details .

    Thanks in Advance

    Ajit Singh

    Reply

Leave a Comment

Your email address will not be published. Required fields are marked *