0

I am looking for a way to process incoming requests in my Spring Boot application to check specific request headers and calculate a hash based on the incoming request data. I have found several solutions to create a filter but these do not match on the Servlet 3.0 spec.

The solution needs to read the incoming data from the input stream without affecting the filter chain. When i try to read the incoming data i get an error messages in other filters that the content was already consumed.

How can this be done without interfering with other filters?

I prefer a solution without using Spring Security, this to learn how this can be done.

Marco
  • 15,101
  • 33
  • 107
  • 174
  • As I am not sure whether I got your question right, posting my idea as a reply instead of Answer. Did you try implementing HttpServletRequestWrapper. In your doFilter read your httpRequest and store in your HttpServletRequestWrapper implementation. Then you can call the chain.doFilter(request, response). When you say read incoming request data, if the data comes by queryString you can use getQueryString. Give it a try and let me know. – Narain Mar 20 '15 at 16:51
  • I need the actual content in the posted body, not only the headers. Could you give an example on how i can use the HttpServletRequestWrapper? – Marco Mar 20 '15 at 16:54
  • You will have just extend javax.servlet.http.HttpServletRequestWrapper. it is wrapper implementation over HttpServletRequest. As you going to just read data I am not sure now whether you will have to use this. I used in the past to add header info – Narain Mar 20 '15 at 17:06
  • In the HttpServletRequestWrapper i can only read the content once after that it will not be available to other servlets. – Marco Mar 20 '15 at 17:24
  • I see a similar question. check here http://stackoverflow.com/questions/10210645/http-servlet-request-lose-params-from-post-body-after-read-it-once – Narain Mar 20 '15 at 17:27
  • Indeed that seemed to work for Servlet 2.5 spec but not for 3.0 – Marco Mar 20 '15 at 19:27
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/73474/discussion-between-narain-and-marco). – Narain Mar 21 '15 at 11:09

0 Answers0