Refine search
@Nullable public Object invoke(final MethodInvocation invocation) throws Throwable { Class<?> targetClass = (invocation.getThis() != null ? AopUtils.getTargetClass(invocation.getThis()) : null); Method specificMethod = ClassUtils.getMostSpecificMethod(invocation.getMethod(), targetClass); final Method userDeclaredMethod = BridgeMethodResolver.findBridgedMethod(specificMethod);
/** * Get the <em>target</em> object of the supplied {@code candidate} object. * <p>If the supplied {@code candidate} is a Spring * {@linkplain AopUtils#isAopProxy proxy}, the target of the proxy will * be returned; otherwise, the {@code candidate} will be returned * <em>as is</em>. * @param candidate the instance to check (potentially a Spring AOP proxy; * never {@code null}) * @return the target object or the {@code candidate} (never {@code null}) * @throws IllegalStateException if an error occurs while unwrapping a proxy * @see Advised#getTargetSource() * @see #getUltimateTargetObject */ @SuppressWarnings("unchecked") public static <T> T getTargetObject(Object candidate) { Assert.notNull(candidate, "Candidate must not be null"); try { if (AopUtils.isAopProxy(candidate) && candidate instanceof Advised) { Object target = ((Advised) candidate).getTargetSource().getTarget(); if (target != null) { return (T) target; } } } catch (Throwable ex) { throw new IllegalStateException("Failed to unwrap proxied object", ex); } return (T) candidate; }
protected <T> T getTargetObject(Object proxy, Class<T> targetClass) throws Exception { if (AopUtils.isJdkDynamicProxy(proxy)) { return (T) ((Advised) proxy).getTargetSource().getTarget(); } else if (AopUtils.isCglibProxy(proxy)) { return (T) ((Advised) proxy).getTargetSource().getTarget(); } else { return (T) proxy; } } }
public CglibMethodInvocation(Object proxy, @Nullable Object target, Method method, Object[] arguments, @Nullable Class<?> targetClass, List<Object> interceptorsAndDynamicMethodMatchers, MethodProxy methodProxy) { super(proxy, target, method, arguments, targetClass, interceptorsAndDynamicMethodMatchers); // Only use method proxy for public methods not derived from java.lang.Object this.methodProxy = (Modifier.isPublic(method.getModifiers()) && method.getDeclaringClass() != Object.class && !AopUtils.isEqualsMethod(method) && !AopUtils.isHashCodeMethod(method) && !AopUtils.isToStringMethod(method) ? methodProxy : null); }
@Override protected Class getServiceClass(T ref) { if (AopUtils.isAopProxy(ref)) { return AopUtils.getTargetClass(ref); } return super.getServiceClass(ref); }
@Override public Object invoke(MethodInvocation invocation) throws Throwable { Method method = invocation.getMethod(); if (AopUtils.isEqualsMethod(method) || AopUtils.isToStringMethod(method) || AopUtils.isHashCodeMethod(method) || isScopedObjectGetTargetObject(method)) { return invocation.proceed(); ReflectionUtils.makeAccessible(method); return ReflectionUtils.invokeMethod(method, advised.getTargetSource().getTarget(), invocation.getArguments()); return invocation.proceed();
/** * Apply the given AOP method invocation to the given {@link RmiInvocationHandler}. * <p>The default implementation delegates to {@link #createRemoteInvocation}. * @param methodInvocation the current AOP method invocation * @param invocationHandler the RmiInvocationHandler to apply the invocation to * @return the invocation result * @throws RemoteException in case of communication errors * @throws NoSuchMethodException if the method name could not be resolved * @throws IllegalAccessException if the method could not be accessed * @throws InvocationTargetException if the method invocation resulted in an exception * @see org.springframework.remoting.support.RemoteInvocation */ @Nullable protected Object doInvoke(MethodInvocation methodInvocation, RmiInvocationHandler invocationHandler) throws RemoteException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { if (AopUtils.isToStringMethod(methodInvocation.getMethod())) { return "RMI invoker proxy for service URL [" + getServiceUrl() + "]"; } return invocationHandler.invoke(createRemoteInvocation(methodInvocation)); }
private void addArgumentsAsVariables() { Object[] args = mi.getArguments(); if (args.length == 0) { return; } Object targetObject = mi.getThis(); // SEC-1454 Class<?> targetClass = AopProxyUtils.ultimateTargetClass(targetObject); if (targetClass == null) { // TODO: Spring should do this, but there's a bug in ultimateTargetClass() // which returns null targetClass = targetObject.getClass(); } Method method = AopUtils.getMostSpecificMethod(mi.getMethod(), targetClass); String[] paramNames = parameterNameDiscoverer.getParameterNames(method); if (paramNames == null) { logger.warn("Unable to resolve method parameter names for method: " + method + ". Debug symbol information is required if you are using parameter names in expressions."); return; } for (int i = 0; i < args.length; i++) { if (paramNames[i] != null) { setVariable(paramNames[i], args[i]); } } }
@Override public Object invoke(MethodInvocation invocation) throws Throwable { Method method = invocation.getMethod(); if (method == null) { return invocation.proceed(); } Method mostSpecificMethod = AopUtils.getMostSpecificMethod(method, invocation.getThis().getClass()); NewSpan newSpan = SleuthAnnotationUtils.findAnnotation(mostSpecificMethod, NewSpan.class); ContinueSpan continueSpan = SleuthAnnotationUtils .findAnnotation(mostSpecificMethod, ContinueSpan.class); if (newSpan == null && continueSpan == null) { return invocation.proceed(); } return methodInvocationProcessor().process(invocation, newSpan, continueSpan); }
@Override @Nullable public Object invoke(MethodInvocation invocation) throws Throwable { // Work out the target class: may be {@code null}. // The TransactionAttributeSource should be passed the target class // as well as the method, which may be from an interface. Class<?> targetClass = (invocation.getThis() != null ? AopUtils.getTargetClass(invocation.getThis()) : null); // Adapt to TransactionAspectSupport's invokeWithinTransaction... return invokeWithinTransaction(invocation.getMethod(), targetClass, invocation::proceed); }
@Override public Object invoke(MethodInvocation invocation) throws Throwable { if (AopUtils.isToStringMethod(invocation.getMethod())) { return String.format("Function Proxy for interface [%s]", this.functionExecutionInterface.getName()); } if (logger.isDebugEnabled()) { logger.debug("Invoking method {}", invocation.getMethod().getName()); } return invokeFunction(invocation.getMethod(), invocation.getArguments()); }
/** * Return the actual bean class of the given bean instance. * This is the class exposed to description-style JMX properties. * <p>Default implementation returns the target class for an AOP proxy, * and the plain bean class else. * @param managedBean the bean instance (might be an AOP proxy) * @return the bean class to expose * @see org.springframework.aop.support.AopUtils#getTargetClass(Object) */ protected Class<?> getTargetClass(Object managedBean) { return AopUtils.getTargetClass(managedBean); }
private void assertCacheProxying(AnnotationConfigApplicationContext ctx) { FooRepository repo = ctx.getBean(FooRepository.class); boolean isCacheProxy = false; if (AopUtils.isAopProxy(repo)) { for (Advisor advisor : ((Advised)repo).getAdvisors()) { if (advisor instanceof BeanFactoryCacheOperationSourceAdvisor) { isCacheProxy = true; break; } } } assertTrue("FooRepository is not a cache proxy", isCacheProxy); }
@Test public void testCustomPrototypeTargetSource() throws Exception { CountingTestBean.count = 0; BeanFactory bf = new ClassPathXmlApplicationContext(CUSTOM_TARGETSOURCE_CONTEXT, CLASS); ITestBean test = (ITestBean) bf.getBean("prototypeTest"); assertTrue(AopUtils.isAopProxy(test)); Advised advised = (Advised) test; assertTrue(advised.getTargetSource() instanceof PrototypeTargetSource); assertEquals("Rod", test.getName()); // Check that references survived prototype creation assertEquals("Kerry", test.getSpouse().getName()); assertEquals("Only 2 CountingTestBeans instantiated", 2, CountingTestBean.count); CountingTestBean.count = 0; }
/** * Retrieve the Spring proxy object's target object * @param proxy * @param clazz * @param <T> * @return * @throws Exception */ public static <T> T getTargetObject(Object proxy, Class<T> clazz) throws Exception { while( (AopUtils.isJdkDynamicProxy(proxy))) { return clazz.cast(getTargetObject(((Advised)proxy).getTargetSource().getTarget(), clazz)); } return clazz.cast(proxy); } }
@Test public void testInlineJsr223FromTagWithInterface() throws Exception { ApplicationContext ctx = new ClassPathXmlApplicationContext("jsr223-with-xsd.xml", getClass()); assertTrue(Arrays.asList(ctx.getBeanNamesForType(Messenger.class)).contains("inlineMessengerWithInterface")); Messenger messenger = (Messenger) ctx.getBean("inlineMessengerWithInterface"); assertFalse(AopUtils.isAopProxy(messenger)); assertEquals("Hello World!", messenger.getMessage()); }
private Class<?> findTargetClass(Object proxy) throws Exception { if (AopUtils.isAopProxy(proxy)) { AdvisedSupport advised = getAdvisedSupport(proxy); Object target = advised.getTargetSource().getTarget(); return findTargetClass(target); } else { return proxy.getClass(); } }
/** * Throws an IllegalArgumentException if it encounters a JDK dynamic proxy. * Metadata can only be read from target classes and CGLIB proxies! */ @Override protected void checkManagedBean(Object managedBean) throws IllegalArgumentException { if (AopUtils.isJdkDynamicProxy(managedBean)) { throw new IllegalArgumentException( "MetadataMBeanInfoAssembler does not support JDK dynamic proxies - " + "export the target beans directly or use CGLIB proxies instead"); } }
@Nullable public Method getMostSpecificMethod() { if (this.mostSpecificMethod != null) { return this.mostSpecificMethod; } Method method = getMethod(); if (method != null) { Object bean = getBean(); if (AopUtils.isAopProxy(bean)) { Class<?> targetClass = AopProxyUtils.ultimateTargetClass(bean); method = AopUtils.getMostSpecificMethod(method, targetClass); } } return method; }
if (!advised.isFrozen() && isEligible(AopUtils.getTargetClass(bean))) { advised.addAdvisor(0, this.advisor); advised.addAdvisor(this.advisor);