Java 在 tomcat 中记录所有请求和响应数据

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21921818/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 11:25:08  来源:igfitidea点击:

Log all request and response data in tomcat

javatomcat

提问by Nick M

At every moment in the world things change, said some guy.

有人说,世界上每时每刻都在发生变化。

We're sitting on a big fat REST API server which is becoming more and more of a burden to maintain because good Java developers are hard to find, expensive, development takes much more time, so we're slowly switching various application parts to Rails, which is... well, nevermind.

我们坐在一个大而胖的 REST API 服务器上,它变得越来越难以维护,因为优秀的 Java 开发人员很难找到,价格昂贵,开发需要更多的时间,所以我们正在慢慢地将各种应用程序部分切换到 Rails ,这是...好吧,没关系。

There are way too many APIs (and some are poorly documented) to just clone functionality by looking at the docs, so my idea is to find a way to log everything that's passing through this service for a while, in a machine-readable format we can later index, process and report, so we can gradually rewrite the code.

有太多的 API(有些没有很好的文档记录)只是通过查看文档来克隆功能,所以我的想法是找到一种方法来记录通过此服务一段时间的所有内容,以机器可读的格式我们可以稍后索引、处理和报告,因此我们可以逐步重写代码。

Is there a "clean" not so "hacky" way of doing this with Tomcat? Or should I go down the wireshark/reverse proxy way?

使用 Tomcat 是否有一种“干净”而不是“hacky”的方式来做到这一点?或者我应该使用wireshark/反向代理方式?

TIA!

蒂亚!

采纳答案by Guy Bouallet

You can create a payload logging filter and configure it in your web.xml. You can also use an output filter for the response. Thisand thisshould be helpful working examples.

您可以创建负载日志过滤器并在您的 web.xml 中配置它。您还可以对响应使用输出过滤器。应该是有用的工作示例。