Home Spring interceptor not working for partial REST endpoints
Reply: 0

Spring interceptor not working for partial REST endpoints

user1601
1#
user1601 Published in June 20, 2018, 10:55 pm

I have a Spring Boot application with REST endpoints defined like this

/usermanagement/v1/access/ldap
/usermanagement/v1/access/db

I have created a Spring Interceptor to intercept all incoming request with following pattern

@Override
public void addInterceptors(InterceptorRegistry registry) {
   registry.addInterceptor(new RequestInterceptor()).addPathPatterns("/usermanagement/v1/**");
}

RequestInterceptor

@Component
public class RequestInterceptor extends HandlerInterceptorAdapter {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
        throws Exception {
        return true;
    }

    @Override
    public void postHandle(
        HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView)
        throws Exception {
        System.out.println("This is Post Handling the request");
    }
}

This interceptor works only if client accesses the complete endpoint i.e

/usermanagement/v1/access/ldap

In case a partial endpoint is accessed,

/usermanagement/v1/access

interceptor is not called and a 404 is returned to the client.

Is there a way to change this behavior? The reason I am doing this is because I don't want to expose specific endpoints but common endpoints and make internal calls to services and return result through common endpoints.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.313365 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO