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.

2 comments:

  1. Thanks for this post. It gave me the direction I was looking for.

    ReplyDelete
  2. I think this is one of the most significant information for me. And i’m glad reading your article. But should remark on some general things, The web site style is perfect, the articles is really great : D. Good job, cheers
    The Web Handlers

    ReplyDelete