Example usage for org.springframework.aop.framework AopProxy getClass

List of usage examples for org.springframework.aop.framework AopProxy getClass

Introduction

In this page you can find the example usage for org.springframework.aop.framework AopProxy getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:net.bubble.common.utils.BeanContextUtil.java

/**
 * ?JDK??</br>/*from w  w  w . ja va 2s . c om*/
 * Spring??AOP?JDK??
 * @param proxy ?
 * @return Object 
 * @throws CommonException jdk???
 */
public Object getJdkDynamicProxyTargetObject(Object proxy) throws CommonException {
    try {
        Field field = proxy.getClass().getSuperclass().getDeclaredField("h");
        field.setAccessible(true);
        AopProxy aopProxy = (AopProxy) field.get(proxy);
        Field advised = aopProxy.getClass().getDeclaredField("advised");
        advised.setAccessible(true);
        Object target = ((AdvisedSupport) advised.get(aopProxy)).getTargetSource().getTarget();
        return target;
    } catch (SecurityException e) {
        logger.error(e.getMessage(), e);
        throw new CommonException("The method of object with Dynamic jdk proxy can't be read !", e);
    } catch (NoSuchFieldException e) {
        logger.error(e.getMessage(), e);
        throw new CommonException("Can't find field in Dynamic jdk proxy object !", e);
    } catch (IllegalArgumentException e) {
        logger.error(e.getMessage(), e);
        throw new CommonException("Inject parameter to Dynamic jdk proxy object has error !", e);
    } catch (IllegalAccessException e) {
        logger.error(e.getMessage(), e);
        throw new CommonException("Access Dynamic jdk proxy object has error !", e);
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        throw new CommonException("Get Dynamic jdk proxy target object has error !", e);
    }

}