Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
记录spring boot web应用程序中的http流量_Spring_Http_Logging - Fatal编程技术网

记录spring boot web应用程序中的http流量

记录spring boot web应用程序中的http流量,spring,http,logging,Spring,Http,Logging,我在tomcat7上安装了一个spring boot web应用程序。我正在寻找一种记录http传入和传出请求(头和正文)的方法。 您能帮忙吗?您可以实现自己的过滤器,如: @Component public class SimpleFilter implements Filter { public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException,

我在tomcat7上安装了一个spring boot web应用程序。我正在寻找一种记录http传入和传出请求(头和正文)的方法。
您能帮忙吗?

您可以实现自己的过滤器,如:

@Component
public class SimpleFilter implements Filter {

    public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
        HttpServletResponse response = (HttpServletResponse) res;
        HttpServletRequest request = (HttpServletRequest) req;
        // logic...
        chain.doFilter(req, res);
    }

    public void init(FilterConfig filterConfig) {}

    public void destroy() {}

}

这也是一个很好的解决方案,可以满足您拦截请求和响应的需求…

您是要记录每个Http请求和每个Http响应,还是通过登录/注销、特殊请求映射等方式将它们分开?使用
AbstractRequestLoggingFilter
子类之一记录请求。您所指向的拦截器是用于web服务的(如果我没有弄错的话)。如果要启用SpringWeb服务的日志记录,可以将
org.springframework.ws.client.MessageTracing
设置为跟踪每个请求。@s.kwiotek/response@M.Deinum感谢您提供的信息。AbstractRequestLoggingFilter为请求做了工作。我需要类似的东西来响应服务器。