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

后端 未结 3 545
迷失自我
迷失自我 2020-12-13 15:08

I created an implementation of LoggingHandler that implements SOAPHandler

It should log whenever handleMess

相关标签:
3条回答
  • 2020-12-13 15:40

    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();
    
    0 讨论(0)
  • 2020-12-13 15:44

    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>
    
    0 讨论(0)
  • 2020-12-13 15:56

    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.

    0 讨论(0)
提交回复
热议问题