Example usage for org.springframework.aop.support AopUtils isAopProxy

List of usage examples for org.springframework.aop.support AopUtils isAopProxy

Introduction

In this page you can find the example usage for org.springframework.aop.support AopUtils isAopProxy.

Prototype

public static boolean isAopProxy(@Nullable Object object) 

Source Link

Document

Check whether the given object is a JDK dynamic proxy or a CGLIB proxy.

Usage

From source file:fr.acxio.tools.agia.SpringTestUtils.java

public static final Object unwrapProxy(Object bean) throws Exception {
    /*/*from   w ww  .ja va2 s  . c o m*/
     * If the given object is a proxy, set the return value as the object
     * being proxied, otherwise return the given object.
     */
    if (AopUtils.isAopProxy(bean) && bean instanceof Advised) {
        Advised advised = (Advised) bean;
        bean = advised.getTargetSource().getTarget();
    }
    return bean;
}

From source file:org.web4thejob.util.FieldLocator.java

public static Object getFieldValue(Object object, String fieldName) throws Exception {

    Object target;/*  w  w  w .  j av a 2s  .  c o  m*/
    if (AopUtils.isAopProxy(object)) {
        target = ((Advised) object).getTargetSource().getTarget();
    } else {
        target = object;
    }

    return PropertyAccessorFactory.forDirectFieldAccess(target).getPropertyValue(fieldName);

}

From source file:com.dangdang.ddframe.job.lite.spring.util.AopTargetUtils.java

/**
 * ?./*from  w ww .j av  a  2s .  co  m*/
 * 
 * @param proxy ?
 * @return 
 */
public static Object getTarget(final Object proxy) {
    if (!AopUtils.isAopProxy(proxy)) {
        return proxy;
    }
    if (AopUtils.isJdkDynamicProxy(proxy)) {
        return getProxyTargetObject(proxy, "h");
    } else {
        return getProxyTargetObject(proxy, "CGLIB$CALLBACK_0");
    }
}

From source file:cn.guoyukun.spring.utils.AopProxyUtils.java

/**
 * ??//from ww  w . jav  a 2s  .  c o m
 * see http://jinnianshilongnian.iteye.com/blog/1894465
 * @param proxy
 * @return
 */
public static boolean isMultipleProxy(Object proxy) {
    try {
        ProxyFactory proxyFactory = null;
        if (AopUtils.isJdkDynamicProxy(proxy)) {
            proxyFactory = findJdkDynamicProxyFactory(proxy);
        }
        if (AopUtils.isCglibProxy(proxy)) {
            proxyFactory = findCglibProxyFactory(proxy);
        }
        TargetSource targetSource = (TargetSource) ReflectionUtils.getField(ProxyFactory_targetSource_FIELD,
                proxyFactory);
        return AopUtils.isAopProxy(targetSource.getTarget());
    } catch (Exception e) {
        throw new IllegalArgumentException(
                "proxy args maybe not proxy with cglib or jdk dynamic proxy. this method not support", e);
    }
}

From source file:org.nekorp.workflow.desktop.servicio.imp.ProxyUtil.java

/**
 * recupera el objeto proxeado.//  ww  w  . j a v a2 s  .  c o  m
 * @param proxy el supuesto proxy
 * @return el objeto proxeado
 */
public Object getTarget(Object proxy) {
    Object obj = proxy;
    if (AopUtils.isAopProxy(proxy)) {
        try {
            Advised advised = (Advised) proxy;
            obj = advised.getTargetSource().getTarget();
        } catch (Exception ex) {
            ProxyUtil.LOGGER.error("No se logro recuperar el proxy", ex);
        }
    }
    return obj;
}

From source file:fr.pilato.spring.elasticsearch.xml.AsyncNode4ClientsTest.java

@Test
public void test_node_client() throws Exception {
    Node node = ctx.getBean(Node.class);
    Assert.assertTrue(AopUtils.isAopProxy(node));

    Map<String, Client> clientMap = ctx.getBeansOfType(Client.class);

    for (Map.Entry<String, Client> entry : clientMap.entrySet()) {
        if (entry.getKey().contains("async")) {
            Assert.assertNotNull(Proxy.getInvocationHandler(entry.getValue()));
        } else {/*from w  w  w .ja v  a2s.  c o m*/
            try {
                Proxy.getInvocationHandler(entry.getValue());
                throw new Exception("Must not be proxyfied");
            } catch (IllegalArgumentException e) {
            }
        }
    }
    //wait
    node.isClosed();
}

From source file:fr.pilato.spring.elasticsearch.xml.AsyncNodeClientTest.java

@Test
public void test_node_client() throws ExecutionException, InterruptedException {
    Node node = ctx.getBean(Node.class);
    Assert.assertTrue(AopUtils.isAopProxy(node));
    Client client = checkClient("testNodeClient");
    Assert.assertNotNull(Proxy.getInvocationHandler(client));
    client.admin().cluster().prepareState().execute().get();
}

From source file:com.scf.core.context.spring.InjectAopSelfBeanProcessor.java

/**
 *
 * @param bean/*from  w  w w . ja  v  a2s. co  m*/
 * @param beanName
 * @return
 * @throws BeansException
 */
@Override
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
    if (!(bean instanceof AopSelfBeanAware)) {
        return bean;
    }
    _logger.info("Set self aop proxy object for '" + beanName + "'.");
    if (AopUtils.isAopProxy(bean)) {
        ((AopSelfBeanAware) bean).setSelf(bean);
    } else {
        ((AopSelfBeanAware) bean).setSelf(context.getBean(beanName));
    }
    return bean;
}

From source file:com.ge.predix.acs.testutils.TestUtils.java

public void setField(final Object target, final String name, final Object value) {

    // check if the object is a proxy object
    if (AopUtils.isAopProxy(target) && target instanceof Advised) {
        try {/*  w w  w . j  a v a  2  s  .co  m*/
            ReflectionTestUtils.setField(((Advised) target).getTargetSource().getTarget(), name, value);
        } catch (Exception e) {
            e.printStackTrace();
        }
    } else {
        ReflectionTestUtils.setField(target, name, value);
    }
}

From source file:ru.anr.base.BaseSpringParent.java

/**
 * Exctracts a bean target if it's a aop proxy
 * //from w  ww  .ja  va2  s .c om
 * @param bean
 *            Original (may be proxied) bean
 * @return A target bean instance
 * 
 * @param <S>
 *            Expected bean class
 */
@SuppressWarnings("unchecked")
protected static <S> S target(Object bean) {

    try {
        return (S) (AopUtils.isAopProxy(bean) ? ((Advised) bean).getTargetSource().getTarget() : bean);
    } catch (Exception ex) {
        throw new ApplicationException(ex);
    }
}