After enabling Zuul proxy for the Spring boot app (We have set of miroservices), spring mvc interceptor doesnot work -


below application.java. has code invoke interceptor

@enableeurekaclient @springbootapplication @enablezuulproxy public class application extends webmvcconfigureradapter {      public static void main(string[] args) {         springapplication.run(application.class, args);     }      @bean     public tokenvalidateinterceptor tokenvalidateinterceptor() {         tokenvalidateinterceptor localechangeinterceptor = new tokenvalidateinterceptor();         system.out.println("in web mvc intereptor, interceptor returned");         return localechangeinterceptor;     }      @override     public void addinterceptors(interceptorregistry registry) {         system.out.println("in web mvc intereptor");         // registry.addinterceptor(tokenvalidateinterceptor()).addpathpatterns("/");         registry.addinterceptor(tokenvalidateinterceptor()).addpathpatterns("/api/**");         // registry.addinterceptor(new         // tokenvalidateinterceptor()).addpathpatterns("/api/**");     }  } 

below snippet of interceptor code:

@component public class tokenvalidateinterceptor extends handlerinterceptoradapter {      private static final logger log = logger.getlogger(tokenvalidateinterceptor.class);      // before actual handler executed ..     public boolean prehandle(httpservletrequest request, httpservletresponse response, object handler) {         string apikey = request.getheader("apikey");         // if (log.isdebugenabled()) {         log.info("#### starting tokenvalidateinterceptor.prehandle ####");         log.info("apikey-->" + apikey);         // }         if (stringutils.isblank(apikey) || apikey == null || apikey.isempty()) {                 return true;         } } } 

but call not reach prehandle of interceptor.

afaik, requests defined in zuul routing handled zuulservlet. spring mvc doesn't handle these requests, spring handlerinterceptor not called these requests. if need preprocessing api requests, should implement in zuul prefilter or servlet filter.


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -