Example usage for org.springframework.aop.framework ProxyFactoryBean setProxyTargetClass

List of usage examples for org.springframework.aop.framework ProxyFactoryBean setProxyTargetClass

Introduction

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

Prototype

public void setProxyTargetClass(boolean proxyTargetClass) 

Source Link

Document

Set whether to proxy the target class directly, instead of just proxying specific interfaces.

Usage

From source file:org.codehaus.mojo.hibernate3.HibernateExporterMojo.java

/**
 * Builds a proxy that will respect any configured processor instance if configured. This should only be called on subclasses that end up generated java classes.
 *
 * @param delegate the original Exporter
 * @return an Exporter proxy that will correctly give the processor objects a chance to run after the delegate exporters' start() method's been called.
 *//*  w w w.  j a v a  2s.co  m*/
protected Exporter buildProcessorAwareExporter(final Exporter delegate) {

    MethodInterceptor interceptor = new MethodInterceptor() {
        @Override
        public Object invoke(MethodInvocation invocation) throws Throwable {
            Method method = invocation.getMethod();
            Object[] objects = invocation.getArguments();

            Object result;
            try {
                result = method.invoke(delegate, objects);
                if (method.getName().contains("start")) {
                    handleComposites();
                    handleProcessor();
                }
                return result;
            } catch (Throwable throwable) {
                getLog().error(throwable);
            }
            return null;

        }
    };

    ProxyFactoryBean bean = new ProxyFactoryBean();
    bean.addAdvice(interceptor);
    bean.setProxyTargetClass(true);
    bean.setBeanClassLoader(delegate.getClass().getClassLoader());
    bean.setAutodetectInterfaces(true);
    bean.setTarget(delegate);
    return (Exporter) bean.getObject();
}

From source file:org.springframework.amqp.rabbit.test.RabbitListenerTestHarness.java

@Override
protected void processListener(MethodRabbitListenerEndpoint endpoint, RabbitListener rabbitListener,
        Object bean, Object adminTarget, String beanName) {
    Object proxy = bean;/*from   w w w . ja  v a 2  s.  co  m*/
    String id = rabbitListener.id();
    if (StringUtils.hasText(id)) {
        if (this.attributes.getBoolean("spy")) {
            proxy = Mockito.spy(proxy);
            this.listeners.put(id, proxy);
        }
        if (this.attributes.getBoolean("capture")) {
            try {
                ProxyFactoryBean pfb = new ProxyFactoryBean();
                pfb.setProxyTargetClass(true);
                pfb.setTarget(proxy);
                CaptureAdvice advice = new CaptureAdvice();
                pfb.addAdvice(advice);
                proxy = pfb.getObject();
                this.listenerCapture.put(id, advice);
            } catch (Exception e) {
                logger.error("Failed to proxy @RabbitListener with id: " + id);
            }
        }
    } else {
        logger.info("The test harness can only proxy @RabbitListeners with an 'id' attribute");
    }
    super.processListener(endpoint, rabbitListener, proxy, adminTarget, beanName);
}

From source file:org.springframework.cloud.sleuth.instrument.async.ExecutorBeanPostProcessor.java

Object createThreadPoolTaskExecutorProxy(Object bean, boolean cglibProxy, ThreadPoolTaskExecutor executor) {
    ProxyFactoryBean factory = new ProxyFactoryBean();
    factory.setProxyTargetClass(cglibProxy);
    factory.addAdvice(new ExecutorMethodInterceptor<ThreadPoolTaskExecutor>(executor, this.beanFactory) {
        @Override//from  w w w. j  a  v a2s .  c o  m
        Executor executor(BeanFactory beanFactory, ThreadPoolTaskExecutor executor) {
            return new LazyTraceThreadPoolTaskExecutor(beanFactory, executor);
        }
    });
    factory.setTarget(bean);
    return factory.getObject();
}

From source file:org.springframework.cloud.sleuth.instrument.async.ExecutorBeanPostProcessor.java

@SuppressWarnings("unchecked")
Object createProxy(Object bean, boolean cglibProxy, Executor executor) {
    ProxyFactoryBean factory = new ProxyFactoryBean();
    factory.setProxyTargetClass(cglibProxy);
    factory.addAdvice(new ExecutorMethodInterceptor(executor, this.beanFactory));
    factory.setTarget(bean);//w  w  w.  j  ava2 s. c  o  m
    return factory.getObject();
}

From source file:org.springframework.cloud.sleuth.instrument.messaging.TraceMessagingAutoConfiguration.java

@SuppressWarnings("unchecked")
Object createProxy(Object bean) {
    ProxyFactoryBean factory = new ProxyFactoryBean();
    factory.setProxyTargetClass(true);
    factory.addAdvice(new MessageListenerMethodInterceptor(this.kafkaTracing, this.tracer));
    factory.setTarget(bean);//from   ww w  . j a  v a 2s  .  com
    return factory.getObject();
}

From source file:org.springframework.integration.smpp.util.TestCurrentExecutingMethodAdvice.java

@Test
public void testLoggingTheCurrentlyExecutingMethodName() throws Throwable {
    ProxyFactoryBean proxyFactoryBean = new ProxyFactoryBean();
    proxyFactoryBean.setProxyTargetClass(true);
    proxyFactoryBean.addAdvice(new CurrentMethodExposingMethodInterceptor());
    proxyFactoryBean.setTarget(new TestClassWithAMethod());

    TestClassWithAMethod testClassWithAMethod = (TestClassWithAMethod) proxyFactoryBean.getObject();
    testClassWithAMethod.testMe();/*from  w w w  .ja  v  a2s.co m*/
}