I am able to get plain json request by using interceptor in spring rest controller for logging purpose. But once the json is read from inputstream of my httpservletrequest, it become null in my controller layer. Is there a way to Set back the json in input stream of my httpservletrequest in the interceptor laye? TIA.
Asked
Active
Viewed 1,710 times
0
-
I think you should *clone* your Stream. [See here](https://stackoverflow.com/a/5924132/7176906) – PinqPonq Mar 29 '18 at 04:42
1 Answers
0
Yes, it's because how the spring handle HttpServletRequest
.
(once read inputstream from client inputstream will be empty.)
So, there can be a solution below.
- Read bytes from inputstream (from client side)
- Use the bytes data. (parse to JSON and use as your business logic)
- Make inputstream from the bytes (to pass to reverse proxy)
- Pass this to back-end.

Roshana Pitigala
- 8,437
- 8
- 49
- 80
-
-
-
-
`ByteArrayInputStream bis = new ByteArrayInputStream(byteArr);` // 3. byte array to input stream – Joonsun Baek Mar 29 '18 at 10:18
-
`httpEntity.setContent(bis);` // 4. use this inputStream for setting a content of HttpEntity instance (i'm using apache library) – Joonsun Baek Mar 29 '18 at 10:18