gervais.b
gervais.b

Reputation: 2347

Spring-webflux, how to get the request as parameter in @ExceptionHandler

With spring webflux and the @RestController model, I have a @RestControllerAdvice with some @ExceptionHandler methods.

I would like to get the original request as parameter because I want to log it and use it in my response.

However I have tried all the possible types for an handler method in the classic MVC model but none of them was accepted (HttpServletRequest, WebRequest and ServerRequest).

What type can I use to access the original request in a webflux annotated handler method ?

Upvotes: 12

Views: 8300

Answers (1)

Brian Clozel
Brian Clozel

Reputation: 59086

You should use org.springframework.http.server.reactive.ServerHttpRequest, because:

  • HttpServletRequest and WebRequest are Servlet/Spring MVC specific
  • ServerRequest belongs to Spring WebFlux, but the functional variant

Upvotes: 25

Related Questions