Tomcat 7: RequestDumperFilter not logging HTTP Request/Response body

Viewed 5121

The RequestDumperFilter is a Tomcat log filter used to log HTTP Requests and Responses.

I have set up the org.apache.catalina.filters.RequestDumperFilter for Tomcat according to this documentation.

As the log shows, the message headers are being logged, but the message body is omitted in the log for both HTTP Requests and Responses (tested with various messages)

The documentation mentions the logging.properties setting needed to log the body:

## The level must be set at least to INFO. If you want to dump the body also, set it to FINEST

The org.apache.catalina.filters.RequestDumperFilter class in the Apache SVN repository does not appear to have the functionality to log message body.

${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 Answers

I use logback to log both full request and response for debugging and analysis. It can log to log files or database.

Related