dReAmEr
dReAmEr

Reputation: 7196

Exclude URL mapping by HTTP method in Spring

I have two URL below,both having diff HTTP method.

1. /v1/user/email (POST)

2. /v1/user/email (PUT)

I need to exclude only one URL from interceptor.But below will exclude both.

<mvc:interceptor> 
     <mvc:exclude-mapping path = "/v1/user/email"/>
</mvc:interceptor>

Is there any way, we can allow only one URL to bypass this,on the basis of HTTP method.

Upvotes: 3

Views: 1169

Answers (1)

Sudheep Vallipoyil
Sudheep Vallipoyil

Reputation: 99

The best way you can do write an abstract class that implementing the Handler Interceptor interface and have the implementation for all the 3

afterCompletion

postHandle

preHandle (all the 3 will call the abstract methods internally by checking the request type)

and have the corresponding abstract methods which will be implemented by your Interceptor classes.

The default methods in abstract class will have to check for the request type and proceed accordingly.

public abstract class AbstractHandler implements HandlerInterceptor
{

     @Override
     public void afterCompletion(HttpServletRequest req, HttpServletResponse res, Object handOb, Exception ex) throws Exception
     {
          if (//check the req type)
          {
             afterCompletionMethod(req, res, handler, ex);
          }
     }

     public abstract void afterCompletionMethod(HttpServletRequest req, HttpServletResponse res, Object handOb, Exception ex) throws Exception;


 }

Upvotes: 2

Related Questions