Spring - How can I adapt SoapEnvelopeLoggingInterceptor to log the data more formally than standard outout to log file

混江龙づ霸主 提交于 2019-12-01 12:26:58

问题


I am trying to perform formal auditing of my Spring web services requests/responses.

I have this in place in my Spring configuration:

<ws:interceptors>   
   <bean class="org.springframework.ws.soap.server.endpoint.interceptor.SoapEnvelopeLoggingInterceptor"/>
</ws:interceptors>

This is fine, and logs the requests and responses to my JBoss log file. What I want though, is to be able to adapt this and log these requests/responses a little cleaner and how can I get hold of of the data, so I can write to an audit record in the DB.

How can I adapt this above so I can map to one of my beans or similar and get hold of of the data in the requests and responses?


回答1:


You should just be able to create a subclass of SoapEnvelopeLoggingInterceptor and override logMessage(String) to do what you want. Example:

<ws:interceptors>   
   <bean class="org.mypackage.SysErrLoggingInterceptor"/>
</ws:interceptors>


package org.mypackage;

public class SysErrLoggingInterceptor extends SoapEnvelopeLoggingInterceptor {
    @Override
        protected void logMessage(String message) {
        System.err.println(message); 
        /* Example, here you could be logging to DB or whatever you want */
    }

}


来源:https://stackoverflow.com/questions/14197918/spring-how-can-i-adapt-soapenvelopelogginginterceptor-to-log-the-data-more-for

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!