How to use Jersey interceptors to get request body

后端 未结 4 1988
一向
一向 2020-12-11 00:48

I am using REST-Jersey in my project. All the POST data is send in JSON format and unmarshalled at server-side into respective beans. Something lik

4条回答
  •  既然无缘
    2020-12-11 01:51

    You can only read the content once, because it's an input stream. If you pick it up in the interceptor then you won't be able to provide it in the main parsing.

    What you need to do is to create a filter which reads the data and makes it available to anyone else who needs it. Basic steps are:

    • in your filter create a new subclass of HttpServletRequestWrapper which reads the input in to a buffer and overrides getInputStream() to provide a new input stream to that buffer
    • pass your new subclass down the chain

提交回复
热议问题