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)

About the Author

author image
mkyong
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter, or befriend him on Facebook or Google Plus. If you like my tutorials, consider make a donation to these charities.

Comments

Leave a Reply

avatar
newest oldest most voted
Prakash Sahu
Guest
Prakash Sahu

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

jose david villanueva villalob
Guest
jose david villanueva villalob

Hi friends, please help me with this case, I’m trying to consume a web service that has that format resquest:

sasasasas
asasasas
tel:222222222
tel:22222222

dsdsdsdasd
asdsadsadedwed=
sadasdasdasdsada==
2010-03-22T20:03:49

, I’m using spring, as it should inject these service security header. Thanks.

change
Guest
change

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

Marcos Filho
Guest
Marcos Filho

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

Wrushasen Dakhane
Guest
Wrushasen Dakhane

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

trackback
JAX-WS : SOAP handler in server side

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

Abc
Guest
Abc
class GoodExample {
  public static void main(String args[]) {
   System.out.println("Nice Tutorial");
 }
}
Ajit Kumar
Guest
Ajit Kumar

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

Levan
Guest
Levan

Fantastic tutorial.
Thank you )

trackback
JAX-WS : SOAP handler in client side

[…] Done, please proceed on next article – Part 3 : JAX-WS – SOAP handler testing for client and server side. […]