Tomcat 7:RequestDumperFilter未记录HTTP请求/响应正文

4

RequestDumperFilter是一个Tomcat日志过滤器,用于记录HTTP请求和响应。

我已按照此文档设置了Tomcat的org.apache.catalina.filters.RequestDumperFilter

如日志所示,消息头被记录在日志中,但是消息正文被省略在日志中,对于HTTP请求和响应都是如此(使用各种消息进行测试)。

文档提到了需要设置logging.properties以记录正文:

## 级别必须至少设置为INFO。如果还要转储正文,请将其设置为FINEST

Apache SVN仓库中的org.apache.catalina.filters.RequestDumperFilter似乎没有记录消息正文的功能。

${catalina.base}/conf/logging.properties:

handlers = 1catalina.org.apache.juli.FileHandler, 2localhost.org.apache.juli.FileHandler, 3manager.org.apache.juli.FileHandler, 4host-manager.org.apache.juli.FileHandler, java.util.logging.ConsoleHandler, 1request-dumper.org.apache.juli.FileHandler

...

# To this configuration below, 1request-dumper.org.apache.juli.FileHandler
# also needs to be added to the handlers property near the top of the file

1request-dumper.org.apache.juli.FileHandler.level = FINEST
1request-dumper.org.apache.juli.FileHandler.directory = ${catalina.base}/logs
1request-dumper.org.apache.juli.FileHandler.prefix = request-dumper.
1request-dumper.org.apache.juli.FileHandler.formatter = org.apache.juli.VerbatimFormatter
org.apache.catalina.filters.RequestDumperFilter.level = FINEST
org.apache.catalina.filters.RequestDumperFilter.handlers = \
  1request-dumper.org.apache.juli.FileHandler

${catalina.base}/conf/web.xml:

  ...
  <filter>
    <filter-name>requestdumper</filter-name>
    <filter-class>
        org.apache.catalina.filters.RequestDumperFilter
    </filter-class>
  </filter>
  <filter-mapping>
      <filter-name>requestdumper</filter-name>
      <url-pattern>*</url-pattern>
  </filter-mapping>
  ...

${catalina.base}/logs/request-dumper.log:

http-bio-8080-exec-9 START TIME        =13-Jul-2017 15:08:40
http-bio-8080-exec-9         requestURI=/manager/html/upload
http-bio-8080-exec-9           authType=BASIC
http-bio-8080-exec-9  characterEncoding=UTF-8
http-bio-8080-exec-9      contentLength=615391
http-bio-8080-exec-9        contentType=multipart/form-data; boundary=----WebKitFormBoundaryP2bE0aVydgRqWbXP
http-bio-8080-exec-9        contextPath=/manager
http-bio-8080-exec-9             cookie=JSESSIONID=144935F6B43B3CB48AAD7E2980DC1E69
http-bio-8080-exec-9             header=host=localhost:8080
http-bio-8080-exec-9             header=connection=keep-alive
http-bio-8080-exec-9             header=content-length=615391
http-bio-8080-exec-9             header=cache-control=max-age=0
http-bio-8080-exec-9             header=authorization=Basic YWRtaW46Z29WYWx1ZTEyMyE=
http-bio-8080-exec-9             header=origin=http://localhost:8080
http-bio-8080-exec-9             header=upgrade-insecure-requests=1
http-bio-8080-exec-9             header=user-agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36
http-bio-8080-exec-9             header=content-type=multipart/form-data; boundary=----WebKitFormBoundaryP2bE0aVydgRqWbXP
http-bio-8080-exec-9             header=accept=text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
http-bio-8080-exec-9             header=referer=http://localhost:8080/manager/html/undeploy?path=/ReqRespDumpFilter&org.apache.catalina.filters.CSRF_NONCE=DDA08F1F9D404EE9E5631E9CA9528401
http-bio-8080-exec-9             header=accept-encoding=gzip, deflate, br
http-bio-8080-exec-9             header=accept-language=en-US,en;q=0.8
http-bio-8080-exec-9             header=cookie=JSESSIONID=144935F6B43B3CB48AAD7E2980DC1E69
http-bio-8080-exec-9             locale=en_US
http-bio-8080-exec-9             method=POST
http-bio-8080-exec-9          parameter=org.apache.catalina.filters.CSRF_NONCE=80714B6B625B708F2BB416747BEFB87E
http-bio-8080-exec-9           pathInfo=/upload
http-bio-8080-exec-9           protocol=HTTP/1.1
http-bio-8080-exec-9        queryString=org.apache.catalina.filters.CSRF_NONCE=80714B6B625B708F2BB416747BEFB87E
http-bio-8080-exec-9         remoteAddr=0:0:0:0:0:0:0:1
http-bio-8080-exec-9         remoteHost=0:0:0:0:0:0:0:1
http-bio-8080-exec-9         remoteUser=admin
http-bio-8080-exec-9 requestedSessionId=144935F6B43B3CB48AAD7E2980DC1E69
http-bio-8080-exec-9             scheme=http
http-bio-8080-exec-9         serverName=localhost
http-bio-8080-exec-9         serverPort=8080
http-bio-8080-exec-9        servletPath=/html
http-bio-8080-exec-9           isSecure=false
http-bio-8080-exec-9 ------------------=--------------------------------------------
http-bio-8080-exec-9 ------------------=--------------------------------------------
http-bio-8080-exec-9           authType=BASIC
http-bio-8080-exec-9        contentType=text/html;charset=utf-8
http-bio-8080-exec-9             header=Content-Type=text/html;charset=utf-8
http-bio-8080-exec-9             header=Transfer-Encoding=chunked
http-bio-8080-exec-9             header=Date=Thu, 13 Jul 2017 13:08:40 GMT
http-bio-8080-exec-9         remoteUser=admin
http-bio-8080-exec-9             status=200
http-bio-8080-exec-9 END TIME          =13-Jul-2017 15:08:40
http-bio-8080-exec-9 ===============================================================
2个回答

2

正如你所说:

Apache SVN存储库中的org.apache.catalina.filters.RequestDumperFilter类似乎没有记录消息体的功能。

Tomcat不记录消息体(我也找不到该功能)。我认为OpenEdge安装目录中包含的Tomcat是由OpenEdge开发人员定制的。

Tomcat官方文档没有提到:

级别必须至少设置为INFO。如果您还想转储主体,请将其设置为FINEST

因此,如果您想要Tomcat记录消息体,则可能需要自定义RequestDumperFilter类。


0

我使用logback记录完整的请求和响应以进行调试和分析。它可以记录到日志文件或数据库中。


你能举个例子吗? - StackzOfZtuff

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接