No.
The servlet does not provide such an API, and it would be difficult to implement, because (basically) you cannot read the same data from Socket twice. It is easy to obtain header information, but source headers cannot be captured in the servlet container. To get bodies, you need to capture them yourself, as your application reads / writes the corresponding streams.
Your alternatives:
Write your own server-side implementation of the HTTP protocol. (May not be suitable for your application.)
You can get the header information you need with filters, although they do not show raw requests.
Some servlet containers have query logging; for example, with Tomcat there is a beast called RequestDumperValve, which you can configure in the file "server.xml".
Implement a proxy server that is located between the client and your "real" server.
Sniffing packages.
Which best depends on what you are really trying to achieve.
Followup:
If "badness" is in the headers, the RequestDumperValve approach is probably best for debugging. Go to $ CATALINA_HOME / conf / server.xml, find "RequestDumperValve" and uncomment the item. Then restart Tomcat. You can also make an equivalent in the webapp file "context.xml". Reset requests and responses end in "logs / catalina.out" by default. Please note that this will give a lot of results, so you do not want to do this in production ... except as a last resort.
If the error is related to the content of the POST or PUT request, you need to modify the application to save a copy of the content when it reads it from the input stream. I do not know any shortcuts for this.
Also, if you want to leave the log for a long period of time, you probably have to solve the problem yourself by calling the HttpServletRequest API and logging headers, etc. RequestDumperValve generates too large a result and discards ALL requests, not only bad ones.
source share