我想记录我的传入/传出消息。目前,我能够记录整个消息,只是将其org.springframework.ws.client.MessageTracing.sent
添加到我的 log4j2 属性文件中。此日志如下:
[TRACE] TIMESTAMP received - Received response [full message, very long and hard to read]
我想按如下方式记录消息:
[TRACE] TIMESTAMP - GetMyLoggingRequest(name: Mike, phone: 5444393)
[TRACE] TIMESTAMP - GetMyLoggingResponse(surname: Apple, status:"good")
在这里,它只是用参数记录请求和响应,它们被发送/接收。更容易阅读!
怎么做?
使用拦截器:
@Component
public class CustomEndpointInterceptor implements EndpointInterceptor {
private static final Log LOG = LogFactory.getLog(CustomEndpointInterceptor.class);
@Override
public boolean handleRequest(MessageContext messageContext, Object endpoint) throws Exception {
LOG.info("Endpoint Request Handling");
return true;
}
@Override
public boolean handleResponse(MessageContext messageContext, Object endpoint) throws Exception {
LOG.info("Endpoint Response Handling");
return true;
}
@Override
public boolean handleFault(MessageContext messageContext, Object endpoint) throws Exception {
LOG.info("Endpoint Exception Handling");
return true;
}
@Override
public void afterCompletion(MessageContext messageContext, Object endpoint, Exception ex) throws Exception {
LOG.info("Execute code after completion");
}
}
通过以下方式将其添加到您的配置中:
@EnableWs
@Configuration
public class SoapServerConfig extends WsConfigurerAdapter {
@Override
public void addInterceptors(List<EndpointInterceptor> interceptors) {
// register global interceptor
interceptors.add(new CustomEndpointInterceptor());
}
...
}