Java JAX-WS web-service client: how log request & response xml?
Asked Answered
C

3

20

I created an implementation of LoggingHandler that implements SOAPHandler<SOAPMessageContext>

It should log whenever handleMessage triggers (and it is never called in my case)

MyService service = new MyService();
MyServicePort port = service.getPortType();

now I try this:

BindingProvider bindingProvider = (BindingProvider)port;
bindingProvider.getBinding().getHandlerChain().add(new LoggingHandler());

I do not see any request / response xml though.

Can you suggest any solution? Maybe there's another way to see output and request XML?

Cesena answered 11/5, 2010 at 6:39 Comment(0)
C
27

It starts working if you use this method:

binding.setHandlerChain(handlerList);

So, first initialize this list with

binding.getHandlerChain();

then add your element to the list and after all

setHandlerChain();
Cesena answered 11/5, 2010 at 7:4 Comment(0)
K
3

you can add a logger in you log4j.xml file :

<!-- Log WebService's inputs and outputs -->
<logger name="org.apache.cxf.interceptor">
    <level value="INFO" />
    <appender-ref ref="[YOUR_LOGGER]" />
</logger>
Kesha answered 23/1, 2013 at 11:29 Comment(0)
P
1

If anyone is wondering the 'why' of @EugeneP excellent answer.

In the Interface javax.xml.ws.Binding, there is the following comment.

/**
 * Gets a copy of the handler chain for a protocol binding instance.
 * If the returned chain is modified a call to 
 <code>setHandlerChain</code>
 * is required to configure the binding instance with the new chain.
 *
 *  @return java.util.List&lt;Handler> Handler chain
 */
 public java.util.List<javax.xml.ws.handler.Handler> getHandlerChain();

So the getHandlerChain() method returns a copy of the List not the list itself. So you have to use setHandlerChain to update the actual List.

Prepense answered 9/4, 2018 at 18:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.