Why interceptor does run three times?

Lce Man
 public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object object) {
    String jwt = request.getHeader("auth");
    String payloadKey = "apitest";
    HandlerMethod handlerMethod=(HandlerMethod)object;
    Class type = handlerMethod.getBeanType();
    if (type.isAnnotationPresent(Auth.class)) {
        try {
            if (jwt == null || !Objects.equals(payloadKey, JwtUtil.parseJWT(jwt).get("info", String.class))) {
                return false;
            }
        }catch (ExpiredJwtException | SignatureException | MalformedJwtException e){
            return false;
        }
    }
    log.info("1");
    return true;
}

when jwt is true, but i see log.info("1") run 3 times, why it run 3 times?

my interceptorConfig:

@Override
public void addInterceptors(InterceptorRegistry registry) {
    registry.addInterceptor(authenticationInterceptor())
            .addPathPatterns("/**");
}
@Bean
public AuthenticationInterceptor authenticationInterceptor() {
    return new AuthenticationInterceptor();
}

i set @Auth on my controller class: @Auth public class ApiController

And when i clear my preHandle exclude "log.info("1") return true" that run 3 times

gavincook

Updated

You can debug into AuthenticationInterceptor, to confirm somethings:

  1. if the handlerMethod point different object in total 3 times?

  2. if the AuthenticationInterceptor, that is this variable, is different or not?

  3. If there has some redirect for your request?

I tried use some code like yours, it has correct behavior. Can you show more code or a simply way to reproduce the issue?

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Why does onCreateOptionsMenu run multiple times?

Why does adding 1.0/3.0 numeric literal three times evaluates to exactly 1 in Golang?

Why does my tableView function run three times?

JQuery - Why does Trigger method call it three times?

Why is SHGetPathFromIDList function exported three times

Why does Google Cloud Function run a global function multiple times after deploy?

Why is the font awesome showing up three times?

Why labels are mentioned three times in a single deployment

Why does this loop run infinite times? Comma separated conditions in for loop

Why does make run one specific rule 3 times in a loop?

Why is my python script executed three times?

why is the combine function called three times?

why does this thread pool deadlock or run too many times?

Why does my udev rule run several times?

Why do i need to press '\n' three times for this to run?

Why is PyQt executing my actions three times?

Spring MVC Handler Interceptor does not run

Why is my udev rule executed three times

Why is the second list in this code printing three times?

Why does my interceptor that is defined on two modules get run twice?

Why does the 'init' method run in two times by the same object?

Why does interceptor not return data to subscriber?

why print 'hello' three times in my centos?

Why does Mybatis Interceptor get duplicate parameters

Why does not 'while(csv.Read())' work two / three times in CsvHelper?

Why does Spring @schedule annotation not run at exact times each day?

Why does the interceptor not get the route parameters?

why does my event run multiple times in useEffect?

Why does sizeof(array) return three times more than indexes in the array?

TOP Ranking

HotTag

Archive