禁用一项Web服务的CXF日志记录 [英] Disable CXF logging for one web service
问题描述
在我的应用程序中,我想使用业务逻辑记录请求和响应。应用程序通过SOAP通信执行一些后端逻辑,这就是我要记录的内容。
In my application I would like to log request and response with business logic. Application does some backend logic with SOAP communication and this is what I want to log.
不幸的是,在同一应用程序中,我必须提供数据(平均为4个请求/秒)
假设此服务名称为PlatformDataService。
Unfornatly in this same application I must serve data ( avg. is 4 request/s) Let's say this service name is PlatformDataService.
如何仅关闭一项Web服务的cxf日志记录?
How to turn off cxf logging for only one web service?
环境:
- JDK 8
- cxf 2.7.14
- AS:Jboss EAP 6.4
我通过以下方式打开服务器登录:
I turn on login on server by:
- 添加记录器组织.apache.cxf信息
- 和系统属性org.apache.cxf.logging.enabled = true
推荐答案
您可以扩展 LoggingInInterceptor
和 LoggingOutInterceptor
。根据 soapAction
,您只能忽略一项服务的日志记录。
You can extend LoggingInInterceptor
and LoggingOutInterceptor
. Based on the soapAction
you can ignore only logging for one service.
扩展 LoggingOutInterceptor
用于所有出站请求和覆盖方法 handleMessage
这样。
Extend LoggingOutInterceptor
for all the outbound requests and override method handleMessage
like this.
private boolean doNotLog=false;
public void handleMessage(Message message) throws Fault {
TreeMap<String,List> protocolHeaders =
(TreeMap<String, List>) message.get("org.apache.cxf.message.Message.PROTOCOL_HEADERS");
if (protocolHeaders != null) {
List value = protocolHeaders.get("SOAPAction");
String soapAction = value != null ? (String)value.get(0) : "";
if (soapAction.equalIgnoreCase(YOUR_SERVICE_SOAP_ACTION)) {
doNotLog=true;
}
}
super.handleMessage(message);
}
现在,您必须在同一类中重写另一种方法。 / p>
Now there is one more method you have to override in the same class.
@Override
protected String transform(String originalLogString) {
if (doNotLog) {
return null;
}
return originalLogString;
}
对于所有入站响应,请扩展 LoggingInInterceptor
并且仅重写变换方法。您只需从originalLogString检查responseType并忽略它即可。
For all inbound responses, extend LoggingInInterceptor
and only override transform method. You can just check the responseType from the originalLogString and ignore it.
这篇关于禁用一项Web服务的CXF日志记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!