java - What Guice MethodInterceptor should return -
i trying find answer should returned guice methodinterceptor. difference between returning methodinvocation.proceed(); , returning null;
here situation: in cases user has right invoke method in not. want implement kind situation using guice aop.
what should return if don't want invoke method? , difference between returning null , other object.
@retention(retentionpolicy.runtime) @target(elementtype.method) public @interface aopestablisher{ } class guicemodule extends abstractmodule{ @override protected void configure() { guiceexampleaop guiceexampleaop = new guiceexampleaop (); requestinjection(guiceexampleaop); bindinterceptor(matchers.any(), matchers.annotatedwith(aopestablisher.class), guiceexampleaop ); } } class commandexecutor{ @aopestablisher public void executeinsomecases(){ //i want execute command in cases } } and here interceptor class:
import org.aopalliance.intercept.methodinterceptor; public class guiceexampleaop implements methodinterceptor { @inject user user; @override public object invoke(methodinvocation methodinvocation) throws throwable { if(user.hasrigths(){ return methodinvocation.proceed(); else{ return null? return methodinvocation? //what should returned here? // difference between returning methodinvocation , null } } } thanks help.
what return result of method. if want prevent invocation, should either throw exception or return sort of "unauthorized" message. here.
if using java8+, i'd recommend best option change method signature return optional instead of whatever type, , return empty.
Comments
Post a Comment