1

added Interceptor and validating headers in prehandle() method of HandlerInterceptor interface and then with the help of WebMvcConfigurer interface adding this intercept and if success we are passing the control to the base url Controller class. Else it will return false and will not passing to the Controller class.

Same thing how we can achieve in Spring WebFlux ? in WebFlux there is similar interface like WebFluxConfigurer , but here is no such method add interceptor?

Also with the help of RouterFunction in WebFlux we can route , but how we can check and validate the headers in common section like HandlerInterceptor in Spring Mvc?**

Here is the below code snippet in Spring MVC :

@Configuration
public class InterceptorConfig implements WebMvcConfigurer {   

@Autowired
CommonInterceptor CommonInterceptor;

@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(CommonInterceptor).addPathPatterns("/api/v1/**");
}


 @Component
public class CommonInterceptor implements HandlerInterceptor {

private static final Logger LOGGER = LoggerFactory.getLogger(CommonInterceptor.class);

@Autowired
private CommonRequest CommonRequest;

@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
        throws CommonException {
    String tenantContext = request.getHeader(CommonFrameworkConstants.TENANT_CONTEXT);
    String authToken = request.getHeader(CommonFrameworkConstants.AUTHORIZATION);
    LOGGER.trace("Handling Request for Tenant Context {}", tenantContext);
    CommonHeader CommonHeader = new CommonHeader(authToken, tenantContext);
    CommonRequest.setCommonHeader(commonHeader);
    CommonRequest.setUserName("api");
    return true;
}
 }
M. Deinum
  • 115,695
  • 22
  • 220
  • 224
Debu Paul
  • 11
  • 1
  • 2
  • Have you seen the answer to this question: https://stackoverflow.com/questions/47091717/interceptor-in-spring-reactor – MuratOzkan Apr 22 '19 at 11:11
  • Possible duplicate of [Interceptor in spring reactor](https://stackoverflow.com/questions/47091717/interceptor-in-spring-reactor) – MuratOzkan Apr 22 '19 at 11:11

0 Answers0