Example usage for org.springframework.aop.framework AdvisedSupport AdvisedSupport

List of usage examples for org.springframework.aop.framework AdvisedSupport AdvisedSupport

Introduction

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

Prototype

public AdvisedSupport() 

Source Link

Document

No-arg constructor for use as a JavaBean.

Usage

From source file:com.yeahmobi.yunit.testutils.MustNotSwallowSpringJUnit4ClassRunner.java

@Override
public void run(RunNotifier notifier) {
    AdvisedSupport config = new AdvisedSupport();
    config.setTarget(notifier);//from  w  w  w .j  a v  a  2  s.com
    config.addAdvice(new org.aopalliance.intercept.MethodInterceptor() {
        public Object invoke(MethodInvocation invocation) throws Throwable {
            if ("fireTestFailure".equals(invocation.getMethod().getName())) {
                Failure failure = (Failure) invocation.getArguments()[0];
                if (failure.getException() instanceof NotSwallowedException) {
                    // We expect this
                    return null;
                }
            }
            return invocation.proceed();
        }
    });
    DefaultAopProxyFactory aopProxyFactory = new DefaultAopProxyFactory();
    RunNotifier runNotifierProxy = (RunNotifier) aopProxyFactory.createAopProxy(config).getProxy();
    super.run(runNotifierProxy);
}

From source file:im.tym.wraop.impl.ProxyCreatorBasedWrapperFactorySpi.java

protected AdvisedSupport getAdvisedSupportFor(final I object) {
    return new AdvisedSupport() {
        {//from   www . j a  v  a2s  .c  om
            copyConfigurationFrom(proxyCreator, new SingletonTargetSource(object),
                    Arrays.asList(proxyCreator.getAdvisors()));
        }
    };
}

From source file:org.piraso.proxy.RegexProxyFactory.java

@SuppressWarnings("unchecked")
public ProxyInterceptorAware<T> getProxyInterceptor(T object) {
    RegexMethodInterceptor<T> wrapper = new RegexMethodInterceptorWrapper(new RegexMethodInterceptor<T>(),
            object);/*  ww w. j ava2  s.  c  om*/
    wrapper.addAllMethodListener(listeners);

    T proxy;

    if (clazz.isInterface()) {
        proxy = ProxyFactory.getProxy(clazz, wrapper);
    } else {
        AdvisedSupport advisedSupport = new AdvisedSupport();
        advisedSupport.setTarget(object);
        advisedSupport.addAdvice(wrapper);
        AopProxy aopProxy = new DefaultAopProxyFactory().createAopProxy(advisedSupport);
        proxy = (T) aopProxy.getProxy();
    }

    return new ProxyInterceptorAware<T>(proxy, wrapper);
}

From source file:jenkins.security.security218.ysoserial.payloads.JSON1.java

/**
 * Will call all getter methods on payload that are defined in the given interfaces
 *//*w  ww  .  j  a  v a  2  s  . c  o  m*/
public static Map makeCallerChain(Object payload, Class... ifaces)
        throws OpenDataException, NoSuchMethodException, InstantiationException, IllegalAccessException,
        InvocationTargetException, Exception, ClassNotFoundException {
    CompositeType rt = new CompositeType("a", "b", new String[] { "a" }, new String[] { "a" },
            new OpenType[] { javax.management.openmbean.SimpleType.INTEGER });
    TabularType tt = new TabularType("a", "b", rt, new String[] { "a" });
    TabularDataSupport t1 = new TabularDataSupport(tt);
    TabularDataSupport t2 = new TabularDataSupport(tt);

    // we need to make payload implement composite data
    // it's very likely that there are other proxy impls that could be used
    AdvisedSupport as = new AdvisedSupport();
    as.setTarget(payload);
    InvocationHandler delegateInvocationHandler = (InvocationHandler) Reflections
            .getFirstCtor("org.springframework.aop.framework.JdkDynamicAopProxy").newInstance(as);
    InvocationHandler cdsInvocationHandler = Gadgets
            .createMemoizedInvocationHandler(Gadgets.createMap("getCompositeType", rt));
    CompositeInvocationHandlerImpl invocationHandler = new CompositeInvocationHandlerImpl();
    invocationHandler.addInvocationHandler(CompositeData.class, cdsInvocationHandler);
    invocationHandler.setDefaultHandler(delegateInvocationHandler);
    final CompositeData cdsProxy = Gadgets.createProxy(invocationHandler, CompositeData.class, ifaces);

    JSONObject jo = new JSONObject();
    Map m = new HashMap();
    m.put("t", cdsProxy);
    Reflections.setFieldValue(jo, "properties", m);
    Reflections.setFieldValue(jo, "properties", m);
    Reflections.setFieldValue(t1, "dataMap", jo);
    Reflections.setFieldValue(t2, "dataMap", jo);
    return Gadgets.makeMap(t1, t2);
}

From source file:org.springframework.aop.framework.AdvisedSupport.java

/**
 * Serializes a copy of the state of this class, ignoring subclass state.
 *///from w  w w .  ja va2s  . c  o  m
protected Object writeReplace() throws ObjectStreamException {
    if (logger.isDebugEnabled()) {
        logger.debug("Disconnecting " + this);
    }

    // Copy state to avoid dependencies on BeanFactory etc that subclasses may have.
    AdvisedSupport copy = this;

    // If we're in a non-serializable subclass, copy into an AdvisedSupport object.
    if (!getClass().equals(AdvisedSupport.class)) {
        copy = new AdvisedSupport();
        copy.copyConfigurationFrom(this);
    }

    // May return this.
    return copy;
}