vendredi 21 octobre 2016

JEE: how to pass parameter to an interceptor

In my JEE application, running on glassfish 3, I have the following situation:

MyResource class

@Interceptors(SomeInterceptor.class)
public void delete(Flag somethingForTheInterceptor, int idToDelete) {
    .......
}

@Interceptors(SomeInterceptor.class)
public void update(Flag somethingForTheInterceptor, MyStuff newStuff) {
    .......
}

The variable somethingForTheInterceptor is not used in these methods, it is only used in the interceptor:

SomeInterceptor class

@AroundInvoke
public Object userMayAccessOutlet(InvocationContext ctx) throws Exception {
   Flag flag = extractParameterOfType(Arrays.asList(ctx.getParameters()), Flag.class);
   // some checks on the flag
}

Somehow it doesn't feel good to have a parameter that is not used in the method. Is there another way to "send" somethingForTheInterceptor to the interceptor?

Aucun commentaire:

Enregistrer un commentaire