Showing posts with label SOAPHandler. Show all posts
Showing posts with label SOAPHandler. Show all posts

Tuesday, March 19, 2013

Create a JAX-WS Handler for Logging


This is a quick post about how to create a JAX-WS Handler for a client... actually it's really the same for a provider as well. I show how to get at the body to print it out... of course I'd recommend you use a logging framework instead of System.out.print*... Enjoy...

Create a java class that implements SOAPHandler<SOAPMessageContext>…


Implement the appropriate method (usually handleMessage())…


Create an xml file to hold the handler configuration and make sure the <handler-class> has the fully qualified name of you new Handler class.
<?xml version="1.0" encoding="UTF-8"?>
<handler-chains xmlns="http://java.sun.com/xml/ns/javaee">
<handler-chain>
<handler>
<handler-class>com.nationwide.handler.LogHandler</handler-class>
</handler>
</handler-chain>
</handler-chains>

Save this handler config xml file at the same location as the Service class, that is the generated class that extends javax.xml.ws.Service.
Now update this service class to add the @javax.jws.HandlerChain annotation and set it’s “file” attribute equal to the name of your config file.