import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
public class ProxyFactory implements InvocationHandler {
private Object tarjectObject;
public Object creatProxyInstance(Object obj) {
this.tarjectObject = obj;
return Proxy.newProxyInstance(this.tarjectObject.getClass()
.getClassLoader(), this.tarjectObject.getClass()
.getInterfaces(), this);
}
@Override
public Object invoke(Object proxy, Method method, Object[] args)
throws Throwable {
Object result = null;
if (AssessUtils.isAssess()) {
result = method.invoke(this.tarjectObject, args);
}else{
throw new NoAssessException("This server cannot run this service.");
}
return result;
}
}
import java.lang.reflect.Method;
import org.springframework.cglib.proxy.Enhancer;
import org.springframework.cglib.proxy.MethodInterceptor;
import org.springframework.cglib.proxy.MethodProxy;
public class ProxyCglibFactory implements MethodInterceptor {
private Object tarjectObject;
public Object creatProxyInstance(Object obj) {
this.tarjectObject = obj;
Enhancer enhancer=new Enhancer();
enhancer.setSuperclass(this.tarjectObject.getClass());
enhancer.setCallback(this);
return enhancer.create();
}
@Override
public Object intercept(Object obj, Method method, Object[] args,
MethodProxy arg3) throws Throwable {
Object result = null;
if (AssessUtils.isAssess()) {
result = method.invoke(this.tarjectObject, args);
}else{
throw new NoAssessException("This server cannot run this service.");
}
return result;
}
}
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
@Aspect
public class AssessInterceptor {
@Pointcut(value="execution (* com..*.*(..))")
private void anyMethod(){};
@Before("anyMethod()")
public void doBefore(JoinPoint joinPoint) throws NoAssessException{
if (!AssessUtils.isAssess()) {
throw new NoAssessException("This server cannot run this service.");
}
}
/**
* Around异常的时候调用
* @param pjp
* @throws Throwable
*/
@Around("anyMethod()")
public void invoke(ProceedingJoinPoint pjp) throws Throwable{
pjp.proceed();
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有