Можно ли обойти родительский перехватчик в Java EE?JAVA

Программисты JAVA общаются здесь
Anonymous
Можно ли обойти родительский перехватчик в Java EE?

Сообщение Anonymous »

Я работаю над приложением Java EE, где я создал пользовательский перехватчик, который расширяет существующий родительский перехватчик. Моя цель - условно пропустить вызов логики родительского перехвата на основе определенных условий. Родительский перехватчик происходит из структуры и не может быть изменен.import jakarta.annotation.Priority;
import jakarta.interceptor.AroundInvoke;
import jakarta.interceptor.Interceptor;
import jakarta.interceptor.InvocationContext;

@Interceptor
@Priority(Interceptor.Priority.APPLICATION - 1)
public class CustomInterceptor extends ParentInterceptor {

@Override
@AroundInvoke
public Object checkSecurity(InvocationContext ctx) throws Exception {
// Custom logic to determine whether to skip the parent interceptor
if (shouldSkip()) {
return ctx.proceed(); // This still calls the parent intercptor
}
// Call the parent interceptor's logic if not skipping
return super.checkSecurity(ctx);
}

private boolean shouldSkip() {
return true; // Example condition
}
}

@Interceptor
@Priority(Interceptor.Priority.APPLICATION) // Default priority
public class ParentInterceptor {
@AroundInvoke
public Object checkSecurity(InvocationContext ctx) throws Exception {
// Logic for the parent interceptor
return ctx.proceed();
}
}

< /code>
Вопросы: < /p>
  • Можно ли пропустить вызов метода родительского перехватчика (Super.CheckSecurity (CTX)) в этом сценарии? Такие сценарии в цепях перехватчиков Java EE?
Заранее!

Подробнее здесь: https://stackoverflow.com/questions/797 ... in-java-ee

Вернуться в «JAVA»