org.springframework.cglib.proxy.MethodProxy Java Examples
The following examples show how to use
org.springframework.cglib.proxy.MethodProxy.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CglibAopProxy.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Override public Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) { Object other = args[0]; if (proxy == other) { return true; } if (other instanceof Factory) { Callback callback = ((Factory) other).getCallback(INVOKE_EQUALS); if (!(callback instanceof EqualsInterceptor)) { return false; } AdvisedSupport otherAdvised = ((EqualsInterceptor) callback).advised; return AopProxyUtils.equalsInProxy(this.advised, otherAdvised); } else { return false; } }
Example #2
Source File: CglibAopProxy.java From java-technology-stack with MIT License | 6 votes |
@Override @Nullable public Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) throws Throwable { Object oldProxy = null; Object target = this.targetSource.getTarget(); try { oldProxy = AopContext.setCurrentProxy(proxy); Object retVal = methodProxy.invoke(target, args); return processReturnType(proxy, target, method, retVal); } finally { AopContext.setCurrentProxy(oldProxy); if (target != null) { this.targetSource.releaseTarget(target); } } }
Example #3
Source File: AbstractCglibConfigurationMethodInterceptor.java From conf4j with MIT License | 6 votes |
@Override public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable { String methodName = method.getName(); switch (methodName) { case "equals": Class<?>[] methodParameterTypes = method.getParameterTypes(); if (methodParameterTypes.length == 1 && methodParameterTypes[0] == Object.class) { return proxy.invokeSuper(obj, args); } break; case "hashCode": case "toString": if (method.getParameterTypes().length == 0) { return proxy.invokeSuper(obj, args); } break; default: break; } return interceptInternal(obj, method, args, proxy); }
Example #4
Source File: CglibStaticConfigurationMethodInterceptor.java From conf4j with MIT License | 6 votes |
@Override protected Object interceptInternal(Object obj, Method method, Object[] args, MethodProxy proxy) { String propertyName = getPropertyName(method); if (subConfigurationProperties.contains(propertyName)) { // returns sub-configuration return getSubConfigurationProperty(propertyName); } if (subConfigurationListProperties.contains(propertyName)) { // returns sub-configuration list Integer size = (Integer) getValueProperty(propertyName + COLLECTION_SIZE_SUFFIX); SubConfigurationList list = getSubConfigurationListProperty(propertyName); return list.asUnmodifiableList(size); } // returns value property return getValueProperty(propertyName); }
Example #5
Source File: CglibAopProxy.java From java-technology-stack with MIT License | 6 votes |
@Override public Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) { Object other = args[0]; if (proxy == other) { return true; } if (other instanceof Factory) { Callback callback = ((Factory) other).getCallback(INVOKE_EQUALS); if (!(callback instanceof EqualsInterceptor)) { return false; } AdvisedSupport otherAdvised = ((EqualsInterceptor) callback).advised; return AopProxyUtils.equalsInProxy(this.advised, otherAdvised); } else { return false; } }
Example #6
Source File: MvcUriComponentsBuilder.java From lams with GNU General Public License v2.0 | 6 votes |
@Override public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) { if (getControllerMethod.equals(method)) { return this.controllerMethod; } else if (getArgumentValues.equals(method)) { return this.argumentValues; } else if (getControllerType.equals(method)) { return this.controllerType; } else if (ReflectionUtils.isObjectMethod(method)) { return ReflectionUtils.invokeMethod(method, obj, args); } else { this.controllerMethod = method; this.argumentValues = args; Class<?> returnType = method.getReturnType(); return (void.class == returnType ? null : returnType.cast(initProxy(returnType, this))); } }
Example #7
Source File: EagleTraceCglibProxy.java From eagle with Apache License 2.0 | 6 votes |
@Override public Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) { Object other = args[0]; if (proxy == other) { return true; } if (other instanceof Factory) { Callback callback = ((Factory) other).getCallback(INVOKE_EQUALS); if (!(callback instanceof EagleTraceCglibProxy.EqualsInterceptor)) { return false; } AdvisedSupport otherAdvised = ((EagleTraceCglibProxy.EqualsInterceptor) callback).advised; return AopProxyUtils.equalsInProxy(this.advised, otherAdvised); } else { return false; } }
Example #8
Source File: EnhancerUtil.java From specification-arg-resolver with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") static <T> T wrapWithIfaceImplementation(final Class<T> iface, final Specification<Object> targetSpec) { Enhancer enhancer = new Enhancer(); enhancer.setInterfaces(new Class[] { iface }); enhancer.setCallback(new MethodInterceptor() { @Override public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable { if ("toString".equals(method.getName())) { return iface.getSimpleName() + "[" + proxy.invoke(targetSpec, args) + "]"; } return proxy.invoke(targetSpec, args); } }); return (T) enhancer.create(); }
Example #9
Source File: CglibAopProxy.java From lams with GNU General Public License v2.0 | 6 votes |
@Override public Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) { Object other = args[0]; if (proxy == other) { return true; } if (other instanceof Factory) { Callback callback = ((Factory) other).getCallback(INVOKE_EQUALS); if (!(callback instanceof EqualsInterceptor)) { return false; } AdvisedSupport otherAdvised = ((EqualsInterceptor) callback).advised; return AopProxyUtils.equalsInProxy(this.advised, otherAdvised); } else { return false; } }
Example #10
Source File: MainRecordProxy.java From COLA with GNU Lesser General Public License v2.1 | 6 votes |
public Object invokeMethod(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable { Object result = null; method.setAccessible(true); if(ColaMockito.g().getCurrentTestModel() != null && ColaMockito.g().getCurrentTestModel().getTestClazz().isAssignableFrom(mapperInterface)){ ColaMockito.g().getFileDataEngine().clean(); } Method oriMethod = instance.getClass().getDeclaredMethod(method.getName(), method.getParameterTypes()); result = oriMethod.invoke(instance, objects); //result = method.invoke(instance, objects); if(!MockHelper.isMonitorMethod(method.getName())){ return result; } //if(mapperInterface.getName().indexOf("CustomerStatHandler") > 0){ // System.out.println("===" + mapperInterface); //} if(ColaMockito.g().getCurrentTestModel() != null && ColaMockito.g().getCurrentTestModel().getTestClazz().isAssignableFrom(mapperInterface)){ ColaMockito.g().getFileDataEngine().flushOutputData(); ColaMockito.g().getFileDataEngine().flushInputParamsFile(); } return result; }
Example #11
Source File: CglibAopProxy.java From spring-analysis-note with MIT License | 6 votes |
@Override public Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) { Object other = args[0]; if (proxy == other) { return true; } if (other instanceof Factory) { Callback callback = ((Factory) other).getCallback(INVOKE_EQUALS); if (!(callback instanceof EqualsInterceptor)) { return false; } AdvisedSupport otherAdvised = ((EqualsInterceptor) callback).advised; return AopProxyUtils.equalsInProxy(this.advised, otherAdvised); } else { return false; } }
Example #12
Source File: CglibAopProxy.java From spring-analysis-note with MIT License | 6 votes |
@Override @Nullable public Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) throws Throwable { Object oldProxy = null; Object target = this.targetSource.getTarget(); try { oldProxy = AopContext.setCurrentProxy(proxy); Object retVal = methodProxy.invoke(target, args); return processReturnType(proxy, target, method, retVal); } finally { AopContext.setCurrentProxy(oldProxy); if (target != null) { this.targetSource.releaseTarget(target); } } }
Example #13
Source File: MvcUriComponentsBuilder.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Override public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) { if (getControllerMethod.equals(method)) { return this.controllerMethod; } else if (getArgumentValues.equals(method)) { return this.argumentValues; } else if (getControllerType.equals(method)) { return this.controllerType; } else if (ReflectionUtils.isObjectMethod(method)) { return ReflectionUtils.invokeMethod(method, obj, args); } else { this.controllerMethod = method; this.argumentValues = args; Class<?> returnType = method.getReturnType(); return (void.class == returnType ? null : returnType.cast(initProxy(returnType, this))); } }
Example #14
Source File: CglibAopProxy.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) throws Throwable { MethodInvocation invocation = new CglibMethodInvocation(proxy, this.target, method, args, this.targetClass, this.adviceChain, methodProxy); // If we get here, we need to create a MethodInvocation. Object retVal = invocation.proceed(); retVal = processReturnType(proxy, this.target, method, retVal); return retVal; }
Example #15
Source File: CglibAopProxy.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Override public Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) throws Throwable { Object target = this.targetSource.getTarget(); try { Object retVal = methodProxy.invoke(target, args); return processReturnType(proxy, target, method, retVal); } finally { this.targetSource.releaseTarget(target); } }
Example #16
Source File: CglibAopProxy.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Override public Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) throws Throwable { MethodInvocation invocation = new CglibMethodInvocation(proxy, this.target, method, args, this.targetClass, this.adviceChain, methodProxy); // If we get here, we need to create a MethodInvocation. Object retVal = invocation.proceed(); retVal = processReturnType(proxy, this.target, method, retVal); return retVal; }
Example #17
Source File: CglibAopProxy.java From lams with GNU General Public License v2.0 | 5 votes |
public CglibMethodInvocation(Object proxy, Object target, Method method, Object[] arguments, Class<?> targetClass, List<Object> interceptorsAndDynamicMethodMatchers, MethodProxy methodProxy) { super(proxy, target, method, arguments, targetClass, interceptorsAndDynamicMethodMatchers); this.methodProxy = methodProxy; this.publicMethod = Modifier.isPublic(method.getModifiers()); }
Example #18
Source File: CglibAopProxy.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) throws Throwable { Object oldProxy = null; try { oldProxy = AopContext.setCurrentProxy(proxy); Object retVal = methodProxy.invoke(this.target, args); return processReturnType(proxy, this.target, method, retVal); } finally { AopContext.setCurrentProxy(oldProxy); } }
Example #19
Source File: CglibAopProxy.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Override public Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) throws Throwable { Object oldProxy = null; try { oldProxy = AopContext.setCurrentProxy(proxy); Object retVal = methodProxy.invoke(this.target, args); return processReturnType(proxy, this.target, method, retVal); } finally { AopContext.setCurrentProxy(oldProxy); } }
Example #20
Source File: CglibSubclassingInstantiationStrategy.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Override public Object intercept(Object obj, Method method, Object[] args, MethodProxy mp) throws Throwable { // Cast is safe, as CallbackFilter filters are used selectively. LookupOverride lo = (LookupOverride) getBeanDefinition().getMethodOverrides().getOverride(method); Object[] argsToUse = (args.length > 0 ? args : null); // if no-arg, don't insist on args at all if (StringUtils.hasText(lo.getBeanName())) { return this.owner.getBean(lo.getBeanName(), argsToUse); } else { return this.owner.getBean(method.getReturnType(), argsToUse); } }
Example #21
Source File: EagleTraceCglibProxy.java From eagle with Apache License 2.0 | 5 votes |
@Override public Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) throws Throwable { Object target = this.targetSource.getTarget(); try { Object retVal = methodProxy.invoke(target, args); return processReturnType(proxy, target, method, retVal); } finally { this.targetSource.releaseTarget(target); } }
Example #22
Source File: BladeFeignFallback.java From blade-tool with GNU Lesser General Public License v3.0 | 5 votes |
@Nullable @Override public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable { String errorMessage = cause.getMessage(); log.error("BladeFeignFallback:[{}.{}] serviceId:[{}] message:[{}]", targetType.getName(), method.getName(), targetName, errorMessage); Class<?> returnType = method.getReturnType(); // 暂时不支持 flux,rx,异步等,返回值不是 R,直接返回 null。 if (R.class != returnType) { return null; } // 非 FeignException if (!(cause instanceof FeignException)) { return R.fail(ResultCode.INTERNAL_SERVER_ERROR, errorMessage); } FeignException exception = (FeignException) cause; byte[] content = exception.content(); // 如果返回的数据为空 if (ObjectUtil.isEmpty(content)) { return R.fail(ResultCode.INTERNAL_SERVER_ERROR, errorMessage); } // 转换成 jsonNode 读取,因为直接转换,可能 对方放回的并 不是 R 的格式。 JsonNode resultNode = JsonUtil.readTree(content); // 判断是否 R 格式 返回体 if (resultNode.has(code)) { return JsonUtil.getInstance().convertValue(resultNode, R.class); } return R.fail(resultNode.toString()); }
Example #23
Source File: FactoryBeanProxy.java From COLA with GNU Lesser General Public License v2.1 | 5 votes |
public Object invokeMethod(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable { Object result = null; //实现处理 if(instance instanceof FactoryBean){ if("getObject".equals(method.getName())){ Object target = ((FactoryBean)instance).getObject(); Class targetType = ((FactoryBean)instance).getObjectType(); DataRecordProxy mapperProxy; if(online){ mapperProxy = new OnlineDataRecordProxy(targetType, target); }else{ mapperProxy = new DataRecordProxy(targetType, target); } //Enhancer enhancer = new Enhancer(); //enhancer.setSuperclass(this.mapperInterface); //enhancer.setCallback(mapperProxy); //Object proxy = enhancer.create(); Object proxy = MockHelper.createMockFor(this.mapperInterface, mapperProxy); //MainRecordProxy mainRecordProxy = new MainRecordProxy(targetType, proxy); //proxy = ColaMockito.g().createMockFor(this.mapperInterface, mainRecordProxy); ColaMockito.g().getContext().putMonitorMock(new MockServiceModel(this.mapperInterface, beanName, target, proxy)); return proxy; } } method.setAccessible(true); result = method.invoke(instance, objects); return result; }
Example #24
Source File: OnlineDataRecordProxy.java From COLA with GNU Lesser General Public License v2.1 | 5 votes |
@Override public Object invokeMethod(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable{ if(isTestFront()){ try{ return super.invokeMethod(o, method, objects, methodProxy); }finally { ColaRecordController.mainRecord.remove(); } }else{ return super.invokeMethod(o, method, objects, methodProxy); } }
Example #25
Source File: OnlineDataRecordProxy.java From COLA with GNU Lesser General Public License v2.1 | 5 votes |
@Override protected void beforeMethod(Object o, Method method, Object[] objects, MethodProxy methodProxy){ if(isTestFront()){ ColaMockito colaMockito = initColaMockito(); ColaRecordController.mainRecord.set(colaMockito); colaMockito.getFileDataEngine().clean(); } super.beforeMethod(o, method, objects, methodProxy); }
Example #26
Source File: MockDataProxy.java From COLA with GNU Lesser General Public License v2.1 | 5 votes |
public Object invokeMethod(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable { //检查本次要mock的对象 if(isMockService(method)){ return exceuteMock(method, objects); } if (isDataManufacture()) { return manufactureDataIfNotExists(method); } method.setAccessible(true); if(instance == null){ return null; } return method.invoke(instance, objects); }
Example #27
Source File: MockDataProxy.java From COLA with GNU Lesser General Public License v2.1 | 5 votes |
@Override public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable { try{ return invokeMethod(o, method, objects, methodProxy); }catch (InvocationTargetException e){ throw e.getTargetException(); } }
Example #28
Source File: ShardedJedisCallback.java From spring-redis-plugin with Apache License 2.0 | 5 votes |
@Override public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable { ShardedJedis jedis; boolean status = jedisHolder.hasShardJedis(); if (!status) { throw new UnsupportedOperationException("ShardedJedis proxy need use @Redis annotation."); } try { jedis = jedisHolder.getShardedJedis(); return methodProxy.invoke(jedis, objects); } catch (Exception e) { LOGGER.error(e.getMessage()); throw e; } }
Example #29
Source File: CglibAopProxy.java From spring4-understanding with Apache License 2.0 | 5 votes |
public CglibMethodInvocation(Object proxy, Object target, Method method, Object[] arguments, Class<?> targetClass, List<Object> interceptorsAndDynamicMethodMatchers, MethodProxy methodProxy) { super(proxy, target, method, arguments, targetClass, interceptorsAndDynamicMethodMatchers); this.methodProxy = methodProxy; this.publicMethod = Modifier.isPublic(method.getModifiers()); }
Example #30
Source File: CglibAopProxy.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Override public Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) throws Throwable { Object oldProxy = null; Object target = this.targetSource.getTarget(); try { oldProxy = AopContext.setCurrentProxy(proxy); Object retVal = methodProxy.invoke(target, args); return processReturnType(proxy, target, method, retVal); } finally { AopContext.setCurrentProxy(oldProxy); this.targetSource.releaseTarget(target); } }