Search code examples
springspring-boottomcatspring-securitymultipart

How to avoid redundant traffic in Spring Boot application?


I have Spring-Boot 2.x application, and some rest controller endpoint that uploads multipart file, like this

    @PostMapping("/somePath")
    public ResponseEntity someController(@RequestParam MultipartFile file) )

also we have jwtFilter in security filter chain, that checks jwt token for validity;
and we have a situation when token is not valid, but tomcat consumes traffic

how can I check this?:
I use spring boot actuator and make request:
GET http://localhost:8080/actuator/metrics/tomcat.global.received

It possible abort traffic until filter checked token?
Is there a way to avoid redundant traffic?

I tried HttpServletRequest and InputStream as controller param, but result is the same.


Solution

  • Given how expensive the file uploads are and not having any better solution, I would in the meantime:

    • Determine the extension of time needed to be added on top of the token expiry
    • Have the client to make a call to validate token before expensive uploads and renew the token as needed
    • Having the server, when token is expired to allow for the extension of time during which the expired token would be still considered valid

    The other option would be for the client to renew the token before expensive uploads. The client could look at the size of the uploads to make a determination whether to renew or not.