This article is a mirror article of machine translation, please click here to jump to the original article.

View: 21620|Reply: 1

[Source] Spring Cloud Filter fetches the requested content via the ContentCachingRequestWrapper

[Copy link]
Posted on 8/9/2021 2:18:46 PM | | | |
Requirements: Record the request content of the interface into the log, which refers to the content submitted by POST, PUT, Delete, etc., and the content can be a form or a json string.

Anyone with some experience knows that if we read the flow of HttpServletRequest or HttpServletResponse in the filter, there is no way to read it again, which will cause the request to be exceptional. Therefore, we need to use the ContentCachingRequestWrapper and ContentCachingRequestWrapper provided by Spring to repeat the reads of the data stream.
Let's take a look at the renderings first, as follows:



To determine whether a request contains the request content information, the code is as follows (Excluded "multipart/form-data" file submissions):

Get the requested content information:

Filter code:


Note:After calling the chain.doFilter method, you can get the requested contentThe principle is that when the controller gets the InputStream, the ContentCachingRequestWrapper will cache the content into a variable.

The hyperlink login is visible.
The hyperlink login is visible.


(End)




Previous:CentOS 7 installation mongodb 5.0.1 tutorial
Next:Maven updatePolicy snapshot update policy
 Landlord| Posted on 8/9/2021 2:27:30 PM |
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com