将POST的有效负载记录到Tomcat

将POST的有效负载记录到Tomcat

本文介绍了将POST的有效负载记录到Tomcat的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经设法通过编辑conf/server.xml并取消注释org.apache.catalina.valves.AccessLogValve Valve的条目来在Tomcat中启用访问日志记录.我希望能够转储POST的有效内容.似乎模式中的任何选项都无法做到这一点.有内置的方法可以做到这一点吗?我是否使用AccessLogValve?

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?

推荐答案

由于没有建议采用内置方法来获取POST有效负载,因此我继续编写了一个自定义过滤器来转储有效负载的内容.具体来说:

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());

和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>

这篇关于将POST的有效负载记录到Tomcat的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 09:26