I have a WSDL URL that i used to create a web service client using wsimpot command
now i want to log all the in-going and the outgoing XML
so i think to user SOAP Handler but it did not works with this service
but it works with another service client . So my question here is this the right way to log the calls as i need to log all the parameters and log the response also or there is another way .
and why the handler did not work with this client but works with other clients ?
It depends on how you implemented your handlers - a normal way to achieve such functionality is just to add a handlerChain, similar to this:
bindingProvider.getBinding().setHandlerChain(CollectionUtils.toList(new Handler[]{new SimpleHandler()}));
Within the SimpleHandler (that obviously must implement: SOAPHandler<SOAPMessageContext>
), you'll basically do something like this:
@Override
public boolean handleMessage(final SOAPMessageContext messageContext) {
if (messageContext == null) {
LOG.warning("The messageContext was nilled. Unable to handle the soapMessage.");
return false;
}
if (Boolean.FALSE.equals(messageContext.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY))) {
LOG.finest("Some cool incoming message");
} else {
LOG.finest("Some cool outgoing message");
}
return true;
}
The bindingProvider
mentioned earlier, you'll snap from the initialization of the WebService itself. Most likely something like this:
final SomeCoolService someService = new SomeCoolService("my/path/to/service.wsdl", new QName(.., ..));
coolServicePort = remedyService.getCoolServicePort();
if (coolServicePort != null) {
final BindingProvider bindingProvider = (BindingProvider) coolServicePort;
In your case, the handler you added didnt work - did it even get initialized during the init of the handler-chain?
The less obvious way to log these things, is by using other tools such as Wireshark, however I doubt that is suffient for you - unless you'll just want to trace whatever being sent back/forth.