Axis2 1.8.2无法打印SOAP请求调试日志问题求助
Axis2 1.8.2 SOAP请求/响应调试日志输出解决方案
Axis2 1.8.x相比1.3版本,在HTTP客户端依赖和日志适配逻辑上有较大变化,原有的commons-logging配置不再适用,可通过以下步骤修复:
1. 替换HTTP客户端日志类别(核心修复)
Axis2 1.3使用的是commons-httpclient 3.x,而1.8.2切换为Apache HttpClient 4.x,对应的日志包路径完全不同。将原VM参数替换为:
-Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.SimpleLog -Dorg.apache.commons.logging.simplelog.showdatetime=true -Dorg.apache.commons.logging.simplelog.log.org.apache.http.wire=debug -Dorg.apache.commons.logging.simplelog.log.org.apache.http.headers=debug -Dorg.apache.commons.logging.simplelog.log.org.apache.http=debug -Dorg.apache.commons.logging.simplelog.log.org.apache.axis2.transport.http=debug
- 重点替换原
httpclient.wire和org.apache.commons.httpclient为org.apache.http开头的日志类别 - 新增
org.apache.axis2.transport.http日志级别,捕获Axis2传输层的处理细节
2. 解决日志框架冲突
如果项目中同时存在SLF4J与commons-logging依赖,可能导致SimpleLog不生效。此时可切换为SLF4J的SimpleLogger配置:
-Dorg.slf4j.simpleLogger.defaultLogLevel=debug -Dorg.slf4j.simpleLogger.showDateTime=true -Dorg.slf4j.simpleLogger.log.org.apache.http.wire=debug -Dorg.slf4j.simpleLogger.log.org.apache.http.headers=debug -Dorg.slf4j.simpleLogger.log.org.apache.axis2.transport.http=debug
若使用Maven,需确保引入SLF4J的简单实现依赖:
<dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-simple</artifactId> <version>1.7.36</version> <scope>runtime</scope> </dependency>
3. 同步Tomcat日志配置
Tomcat默认使用java.util.logging,若应用日志被Tomcat的全局配置过滤,需在TOMCAT_HOME/conf/logging.properties中添加:
org.apache.http.wire.level = FINE org.apache.http.headers.level = FINE org.apache.axis2.transport.http.level = FINE
确保Tomcat不对debug级别的日志做拦截。
验证效果
重启应用后发起SOAP请求,控制台或日志文件应能输出类似如下的请求细节:
2023/03/10 08:27:22:518 CET [DEBUG] header - ->> "Content-Type: text/xml; charset=UTF-8[\r][\n]"
2023/03/10 08:27:22:519 CET [DEBUG] content - ->> "<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">[...]"
内容的提问来源于stack exchange,提问作者Flo Feil
相关产品推荐
相关产品推荐

