Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 405
dReAmEr Avatar asked May 26 '26 10:05

dReAmEr


1 Answers

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;


 }
like image 89
Sudheep Vallipoyil Avatar answered May 30 '26 05:05

Sudheep Vallipoyil



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!