I'm trying to access the SOAP request and response via client side so that I can calculate the execution time for each call. I've implemented a SOAPHandler
to achieve this but the handleMessage
method is not being invoked (breakpoint doesn't get hit or no log gets logged). I am using wsimport to create the client side classes/stubs and also passing a binding file in as a parameter to wsimport command.
This is what I have done so far:
My binding file - handler-chain.xml
<jaxws:bindings
xmlns:jaxws="http://java.sun.com/xml/ns/jaxws"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:jxb="http://java.sun.com/xml/ns/jaxb">
<handler-chains xmlns="http://java.sun.com/xml/ns/javaee">
<handler-chain>
<handler>
<handler-name>LoggingSOAPHandler</handler-name>
<handler-class>com.handler.LoggingSOAPHandler</handler-class>
</handler>
</handler-chain>
</handler-chains>
</jaxws:bindings>
wsimport command:
<property name="package" value="com.ws"/>
<property name="src" value="docroot/WEB-INF/src"/>
<property name="classes" value="docroot/WEB-INF/classes"/>
<property name="bindingfile" value="docroot/WEB-INF/src/com/handler/handler-chain.xml"/>
<target name="wsimport">
<exec executable="${jdk.home}/bin/wsimport">
<arg line="-keep -s ${src} -p ${package} -d ${classes} -b ${bindingfile} ${wsdl}"/>
</exec>
</target>
When I run above wsimport command, all the stubs are created and the @HandlerChain
annotation gets added to the stub service class as noted below:
@WebServiceClient(name = "TestService", targetNamespace = "http://webservice.com/", wsdlLocation = "http://test:8290/TEST/services/test?wsdl")
@HandlerChain(file = "TestService_Service_handler.xml")
public class TestService_Service
extends Service
{
...
}
Here is the generated TestService_Service_handler.xml:
<?xml version="1.0" encoding="UTF-8"?><handler-chains xmlns="http://java.sun.com/xml/ns/javaee">
<handler-chain>
<handler>
<handler-name>LoggingSOAPHandler</handler-name>
<handler-class>com.handler.LoggingSOAPHandler</handler-class>
</handler>
</handler-chain>
</handler-chains>
Here is my SOAPHandler
:
public class LoggingSOAPHandler implements SOAPHandler<SOAPMessageContext> {
private static Logger _logger = LoggerFactory.getLogger(LoggingSOAPHandler.class);
@Override
public boolean handleMessage(SOAPMessageContext messageContext) {
Boolean outboundProperty = (Boolean) messageContext.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
if (outboundProperty.booleanValue()) {
_logger.info("\nOutbound message:");
} else {
_logger.info("\nInbound message:");
}
return true;
}
@Override
public boolean handleFault(SOAPMessageContext context) {
_logger.info("Client : handleFault()......");
return false;
}
@Override
public void close(MessageContext context) {
_logger.info("Client : close()......");
}
@Override
public Set<QName> getHeaders() {
_logger.info("Client : getHeaders()......");
return null;
}
}
When the webservice is called, handleMessage method doesn't get invoked at all.
Any idea?
I'm using JAX-WS RI 2.2.4-b01 to generate the stubs.