I've managed to enable access logging in Tomcat by editing the conf/server.xml and uncommenting the entry for the org.apache.catalina.valves.AccessLogValve Valve. I'd like to be able to dump the contents of POST's payload. It doesn't seem like any of the options in the pattern will do this. Is there a built in way to do this? Do I use the AccessLogValve?
+2
A:
If the post is a form (application/x-www-urlencoded), you can use ExtendedAccessLogValve,
http://tomcat.apache.org/tomcat-6.0-doc/api/org/apache/catalina/valves/ExtendedAccessLogValve.html
You have to select individual parameters in the pattern like this,
x-P(param_name)
ZZ Coder
2009-10-07 02:36:30
@ZZ: what if it is not a form?
Stephen C
2009-10-07 03:06:45
If it's not a form, you can't really log the post body. The log format is defined by http://www.w3.org/TR/WD-logfile.html. It doesn't support arbitrary post body, which can be binary and huge, in case of file upload.
ZZ Coder
2009-10-07 04:00:59
Unfortunately, this is not the case for me. I'm not posting content as parameters, though the payload size will not likely be more than a few kb.
Tim
2009-10-07 16:37:52
Post payload doesn't belong to logs. You need to dump it somewhere else in your server.
ZZ Coder
2009-10-07 17:15:24
Which is fine, but I want to be able to associate the access information for it. Is there some trick to doing this without writing a custom Valve or the like?
Tim
2009-10-07 21:01:56
I don't think you will find anything inside Tomcat. If this is indeed for logging, you need to come up with a log format and hex-dump the request in your server. If it's for debugging, use Wireshark or Fiddler to watch the post body.
ZZ Coder
2009-10-07 22:32:08
A:
Since there was not a suggestion of a built in way to get the POST payload, I went ahead and wrote a custom filter that dumps the contents of the payload. Specifically:
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse,
FilterChain chain) throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) servletRequest;
LOG.debug("payload: " + requestWrapper.getRequestBody());
and web.xml:
<filter>
<filter-name>PayloadLoggingFilter</filter-name>
<filter-class>com.host.PayloadLoggingFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>PayloadLoggingFilter</filter-name>
<url-pattern>/resources/*</url-pattern>
</filter-mapping>
Tim
2009-10-13 18:07:06