org.springframework.aop.framework.ProxyFactory

Here are the examples of the java api org.springframework.aop.framework.ProxyFactory taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

273 Examples 7

19 View Source File : GroovyAspectTests.java
License : MIT License
Project Creator : Vip-Augus

private void testAdvice(Advisor advisor, LogUserAdvice logAdvice, TestService target, String message, boolean proxyTargetClreplaced) throws Exception {
    logAdvice.reset();
    ProxyFactory factory = new ProxyFactory(target);
    factory.setProxyTargetClreplaced(proxyTargetClreplaced);
    factory.addAdvisor(advisor);
    TestService bean = (TestService) factory.getProxy();
    replacedertEquals(0, logAdvice.getCountThrows());
    try {
        bean.sayHello();
        fail("Expected exception");
    } catch (TestException ex) {
        replacedertEquals(message, ex.getMessage());
    }
    replacedertEquals(1, logAdvice.getCountThrows());
}

19 View Source File : LocalSlsbInvokerInterceptorTests.java
License : MIT License
Project Creator : Vip-Augus

private void testException(Exception expected) throws Exception {
    LocalInterfaceWithBusinessMethods ejb = mock(LocalInterfaceWithBusinessMethods.clreplaced);
    given(ejb.targetMethod()).willThrow(expected);
    String jndiName = "foobar";
    Context mockContext = mockContext(jndiName, ejb);
    LocalSlsbInvokerInterceptor si = configuredInterceptor(mockContext, jndiName);
    ProxyFactory pf = new ProxyFactory(new Clreplaced<?>[] { LocalInterfaceWithBusinessMethods.clreplaced });
    pf.addAdvice(si);
    LocalInterfaceWithBusinessMethods target = (LocalInterfaceWithBusinessMethods) pf.getProxy();
    try {
        target.targetMethod();
        fail("Should have thrown exception");
    } catch (Exception thrown) {
        replacedertTrue(thrown == expected);
    }
    verify(mockContext).close();
}

19 View Source File : AbstractAutoProxyCreator.java
License : MIT License
Project Creator : Vip-Augus

/**
 * Subclreplacedes may choose to implement this: for example,
 * to change the interfaces exposed.
 * <p>The default implementation is empty.
 * @param proxyFactory a ProxyFactory that is already configured with
 * TargetSource and interfaces and will be used to create the proxy
 * immediately after this method returns
 */
protected void customizeProxyFactory(ProxyFactory proxyFactory) {
}

19 View Source File : GroovyAspectTests.java
License : Apache License 2.0
Project Creator : SourceHot

private void testAdvice(Advisor advisor, LogUserAdvice logAdvice, TestService target, String message, boolean proxyTargetClreplaced) throws Exception {
    logAdvice.reset();
    ProxyFactory factory = new ProxyFactory(target);
    factory.setProxyTargetClreplaced(proxyTargetClreplaced);
    factory.addAdvisor(advisor);
    TestService bean = (TestService) factory.getProxy();
    replacedertThat(logAdvice.getCountThrows()).isEqualTo(0);
    replacedertThatExceptionOfType(TestException.clreplaced).isThrownBy(bean::sayHello).withMessage(message);
    replacedertThat(logAdvice.getCountThrows()).isEqualTo(1);
}

19 View Source File : LocalSlsbInvokerInterceptorTests.java
License : Apache License 2.0
Project Creator : SourceHot

private void testException(Exception expected) throws Exception {
    LocalInterfaceWithBusinessMethods ejb = mock(LocalInterfaceWithBusinessMethods.clreplaced);
    given(ejb.targetMethod()).willThrow(expected);
    String jndiName = "foobar";
    Context mockContext = mockContext(jndiName, ejb);
    LocalSlsbInvokerInterceptor si = configuredInterceptor(mockContext, jndiName);
    ProxyFactory pf = new ProxyFactory(new Clreplaced<?>[] { LocalInterfaceWithBusinessMethods.clreplaced });
    pf.addAdvice(si);
    LocalInterfaceWithBusinessMethods target = (LocalInterfaceWithBusinessMethods) pf.getProxy();
    replacedertThatExceptionOfType(Exception.clreplaced).isThrownBy(target::targetMethod).satisfies(ex -> replacedertThat(ex).isSameAs(expected));
    verify(mockContext).close();
}

19 View Source File : TrickyAspectJPointcutExpressionTests.java
License : Apache License 2.0
Project Creator : SourceHot

private void testAdvice(Advisor advisor, LogUserAdvice logAdvice, TestService target, String message, boolean proxyTargetClreplaced) throws Exception {
    logAdvice.reset();
    ProxyFactory factory = new ProxyFactory(target);
    factory.setProxyTargetClreplaced(proxyTargetClreplaced);
    factory.addAdvisor(advisor);
    TestService bean = (TestService) factory.getProxy();
    replacedertThat(logAdvice.getCountThrows()).isEqualTo(0);
    replacedertThatExceptionOfType(TestException.clreplaced).isThrownBy(bean::sayHello).withMessageContaining(message);
    replacedertThat(logAdvice.getCountThrows()).isEqualTo(1);
}

19 View Source File : AbstractAutoProxyCreator.java
License : Apache License 2.0
Project Creator : SourceHot

/**
 * Subclreplacedes may choose to implement this: for example, to change the interfaces exposed.
 * <p>The default implementation is empty.
 *
 * @param proxyFactory a ProxyFactory that is already configured with TargetSource and
 *                     interfaces and will be used to create the proxy immediately after this
 *                     method returns
 */
protected void customizeProxyFactory(ProxyFactory proxyFactory) {
}

19 View Source File : RestClientRetryConfigurer.java
License : MIT License
Project Creator : polysantiago

void configure(ProxyFactory proxyFactory, RestClientInterceptor restClientInterceptor) {
    proxyFactory.addAdvice(retryOperationsInterceptor);
    restClientInterceptor.setRetryEnabled(true);
}

19 View Source File : ThrowsAdviceDemo.java
License : Apache License 2.0
Project Creator : mercyblitz

public static void main(String[] args) throws Exception {
    ThrowsAdviceDemo instance = new ThrowsAdviceDemo();
    ProxyFactory proxyFactory = new ProxyFactory(instance);
    proxyFactory.addAdvice(new MyThrowsAdvice());
    ThrowsAdviceDemo proxy = (ThrowsAdviceDemo) proxyFactory.getProxy();
    proxy.execute();
    proxy.execute();
}

19 View Source File : ProxyFactoryDemo.java
License : Apache License 2.0
Project Creator : mercyblitz

public static void main(String[] args) {
    DefaultEchoService defaultEchoService = new DefaultEchoService();
    // 注入目标对象(被代理)
    ProxyFactory proxyFactory = new ProxyFactory(defaultEchoService);
    proxyFactory.setTargetClreplaced(DefaultEchoService.clreplaced);
    // 添加 Advice 实现 MethodInterceptor < Interceptor < Advice
    proxyFactory.addAdvice(new EchoServiceMethodInterceptor());
    // 获取代理对象
    EchoService echoService = (EchoService) proxyFactory.getProxy();
    System.out.println(echoService.echo("Hello,World"));
}

19 View Source File : TrickyAspectJPointcutExpressionTests.java
License : Apache License 2.0
Project Creator : langtianya

private void testAdvice(Advisor advisor, LogUserAdvice logAdvice, TestService target, String message, boolean proxyTargetClreplaced) throws Exception {
    logAdvice.reset();
    ProxyFactory factory = new ProxyFactory(target);
    factory.setProxyTargetClreplaced(proxyTargetClreplaced);
    factory.addAdvisor(advisor);
    TestService bean = (TestService) factory.getProxy();
    replacedertEquals(0, logAdvice.getCountThrows());
    try {
        bean.sayHello();
        fail("Expected exception");
    } catch (TestException e) {
        replacedertEquals(message, e.getMessage());
    }
    replacedertEquals(1, logAdvice.getCountThrows());
}

19 View Source File : AbstractAutoProxyCreator.java
License : Apache License 2.0
Project Creator : langtianya

/**
 * Subclreplacedes may choose to implement this: for example,
 * to change the interfaces exposed.
 * <p>The default implementation is empty.
 * @param proxyFactory ProxyFactory that is already configured with
 * TargetSource and interfaces and will be used to create the proxy
 * immediately after this method returns
 */
protected void customizeProxyFactory(ProxyFactory proxyFactory) {
}

19 View Source File : RepositoryMethodEntityGraphExtractor.java
License : MIT License
Project Creator : Cosium

@Override
public void postProcess(ProxyFactory factory, RepositoryInformation repositoryInformation) {
    factory.addAdvice(new JpaEnreplacedyGraphMethodInterceptor(enreplacedyManager, repositoryInformation.getDomainType()));
}

19 View Source File : CountQueryDetector.java
License : MIT License
Project Creator : Cosium

static JPQLQuery<?> proxy(JPQLQuery<?> countQuery) {
    ProxyFactory proxyFactory = new ProxyFactory(countQuery);
    proxyFactory.addAdvice(INSTANCE);
    return (JPQLQuery<?>) proxyFactory.getProxy();
}

18 View Source File : JaxWsPortProxyFactoryBean.java
License : MIT License
Project Creator : Vip-Augus

@Override
public void afterPropertiesSet() {
    super.afterPropertiesSet();
    Clreplaced<?> ifc = getServiceInterface();
    replacedert.notNull(ifc, "Property 'serviceInterface' is required");
    // Build a proxy that also exposes the JAX-WS BindingProvider interface.
    ProxyFactory pf = new ProxyFactory();
    pf.addInterface(ifc);
    pf.addInterface(BindingProvider.clreplaced);
    pf.addAdvice(this);
    this.serviceProxy = pf.getProxy(getBeanClreplacedLoader());
}

18 View Source File : PersistenceExceptionTranslationAdvisorTests.java
License : MIT License
Project Creator : Vip-Augus

protected void addPersistenceExceptionTranslation(ProxyFactory pf, PersistenceExceptionTranslator pet) {
    pf.addAdvisor(new PersistenceExceptionTranslationAdvisor(pet, Repository.clreplaced));
}

18 View Source File : TransactionProxyFactoryBean.java
License : MIT License
Project Creator : Vip-Augus

/**
 * As of 4.2, this method adds {@link TransactionalProxy} to the set of
 * proxy interfaces in order to avoid re-processing of transaction metadata.
 */
@Override
protected void postProcessProxyFactory(ProxyFactory proxyFactory) {
    proxyFactory.addInterface(TransactionalProxy.clreplaced);
}

18 View Source File : AopTestUtilsTests.java
License : MIT License
Project Creator : Vip-Augus

private Foo cglibProxy(Foo foo) {
    ProxyFactory pf = new ProxyFactory();
    pf.setTarget(foo);
    pf.setProxyTargetClreplaced(true);
    Foo proxy = (Foo) pf.getProxy();
    replacedertTrue("Proxy is a CGLIB proxy", AopUtils.isCglibProxy(proxy));
    replacedertThat(proxy, instanceOf(FooImpl.clreplaced));
    return proxy;
}

18 View Source File : AopTestUtilsTests.java
License : MIT License
Project Creator : Vip-Augus

private Foo jdkProxy(Foo foo) {
    ProxyFactory pf = new ProxyFactory();
    pf.setTarget(foo);
    pf.addInterface(Foo.clreplaced);
    Foo proxy = (Foo) pf.getProxy();
    replacedertTrue("Proxy is a JDK dynamic proxy", AopUtils.isJdkDynamicProxy(proxy));
    replacedertThat(proxy, instanceOf(Foo.clreplaced));
    return proxy;
}

18 View Source File : MethodValidationTests.java
License : MIT License
Project Creator : Vip-Augus

@Test
public void testMethodValidationInterceptor() {
    MyValidBean bean = new MyValidBean();
    ProxyFactory proxyFactory = new ProxyFactory(bean);
    proxyFactory.addAdvice(new MethodValidationInterceptor());
    proxyFactory.addAdvisor(new AsyncAnnotationAdvisor());
    doTestProxyValidation((MyValidInterface) proxyFactory.getProxy());
}

18 View Source File : SimpleRemoteSlsbInvokerInterceptorTests.java
License : MIT License
Project Creator : Vip-Augus

protected Object configuredProxy(SimpleRemoteSlsbInvokerInterceptor si, Clreplaced<?> ifc) throws NamingException {
    si.afterPropertiesSet();
    ProxyFactory pf = new ProxyFactory(new Clreplaced<?>[] { ifc });
    pf.addAdvice(si);
    return pf.getProxy();
}

18 View Source File : LocalSlsbInvokerInterceptorTests.java
License : MIT License
Project Creator : Vip-Augus

@Test
public void testInvokesMethodOnEjbInstanceWithSeparateBusinessMethods() throws Exception {
    Object retVal = new Object();
    LocalInterface ejb = mock(LocalInterface.clreplaced);
    given(ejb.targetMethod()).willReturn(retVal);
    String jndiName = "foobar";
    Context mockContext = mockContext(jndiName, ejb);
    LocalSlsbInvokerInterceptor si = configuredInterceptor(mockContext, jndiName);
    ProxyFactory pf = new ProxyFactory(new Clreplaced<?>[] { BusinessMethods.clreplaced });
    pf.addAdvice(si);
    BusinessMethods target = (BusinessMethods) pf.getProxy();
    replacedertTrue(target.targetMethod() == retVal);
    verify(mockContext).close();
    verify(ejb).remove();
}

18 View Source File : LocalSlsbInvokerInterceptorTests.java
License : MIT License
Project Creator : Vip-Augus

@Test
public void testInvokesMethodOnEjbInstance() throws Exception {
    Object retVal = new Object();
    LocalInterfaceWithBusinessMethods ejb = mock(LocalInterfaceWithBusinessMethods.clreplaced);
    given(ejb.targetMethod()).willReturn(retVal);
    String jndiName = "foobar";
    Context mockContext = mockContext(jndiName, ejb);
    LocalSlsbInvokerInterceptor si = configuredInterceptor(mockContext, jndiName);
    ProxyFactory pf = new ProxyFactory(new Clreplaced<?>[] { BusinessMethods.clreplaced });
    pf.addAdvice(si);
    BusinessMethods target = (BusinessMethods) pf.getProxy();
    replacedertTrue(target.targetMethod() == retVal);
    verify(mockContext).close();
    verify(ejb).remove();
}

18 View Source File : NameMatchMethodPointcutTests.java
License : MIT License
Project Creator : Vip-Augus

/**
 * Create an empty pointcut, populating instance variables.
 */
@Before
public void setup() {
    ProxyFactory pf = new ProxyFactory(new SerializablePerson());
    nop = new SerializableNopInterceptor();
    pc = new NameMatchMethodPointcut();
    pf.addAdvisor(new DefaultPointcutAdvisor(pc, nop));
    proxied = (Person) pf.getProxy();
}

18 View Source File : TigerAspectJExpressionPointcutTests.java
License : MIT License
Project Creator : Vip-Augus

@Test
public void testAnnotationOnDynamicProxyMethod() throws Exception {
    String expression = "@annotation(test.annotation.transaction.Tx)";
    AspectJExpressionPointcut ajexp = new AspectJExpressionPointcut();
    ajexp.setExpression(expression);
    ProxyFactory factory = new ProxyFactory(new BeanA());
    factory.setProxyTargetClreplaced(false);
    IBeanA proxy = (IBeanA) factory.getProxy();
    replacedertTrue(ajexp.matches(IBeanA.clreplaced.getMethod("getAge"), proxy.getClreplaced()));
}

18 View Source File : TigerAspectJExpressionPointcutTests.java
License : MIT License
Project Creator : Vip-Augus

@Test
public void testAnnotationOnCglibProxyMethod() throws Exception {
    String expression = "@annotation(test.annotation.transaction.Tx)";
    AspectJExpressionPointcut ajexp = new AspectJExpressionPointcut();
    ajexp.setExpression(expression);
    ProxyFactory factory = new ProxyFactory(new BeanA());
    factory.setProxyTargetClreplaced(true);
    BeanA proxy = (BeanA) factory.getProxy();
    replacedertTrue(ajexp.matches(BeanA.clreplaced.getMethod("getAge"), proxy.getClreplaced()));
}

18 View Source File : AbstractBeanFactoryAwareAdvisingPostProcessor.java
License : MIT License
Project Creator : Vip-Augus

@Override
protected ProxyFactory prepareProxyFactory(Object bean, String beanName) {
    if (this.beanFactory != null) {
        AutoProxyUtils.exposeTargetClreplaced(this.beanFactory, beanName, bean.getClreplaced());
    }
    ProxyFactory proxyFactory = super.prepareProxyFactory(bean, beanName);
    if (!proxyFactory.isProxyTargetClreplaced() && this.beanFactory != null && AutoProxyUtils.shouldProxyTargetClreplaced(this.beanFactory, beanName)) {
        proxyFactory.setProxyTargetClreplaced(true);
    }
    return proxyFactory;
}

18 View Source File : EclairProxyCreator.java
License : Apache License 2.0
Project Creator : TinkoffCreditSystems

@Override
protected void customizeProxyFactory(ProxyFactory proxyFactory) {
    proxyFactory.setProxyTargetClreplaced(true);
}

18 View Source File : AopTestUtilsTests.java
License : Apache License 2.0
Project Creator : SourceHot

private Foo cglibProxy(Foo foo) {
    ProxyFactory pf = new ProxyFactory();
    pf.setTarget(foo);
    pf.setProxyTargetClreplaced(true);
    Foo proxy = (Foo) pf.getProxy();
    replacedertThat(AopUtils.isCglibProxy(proxy)).as("Proxy is a CGLIB proxy").isTrue();
    replacedertThat(proxy).isInstanceOf(FooImpl.clreplaced);
    return proxy;
}

18 View Source File : AopTestUtilsTests.java
License : Apache License 2.0
Project Creator : SourceHot

private Foo jdkProxy(Foo foo) {
    ProxyFactory pf = new ProxyFactory();
    pf.setTarget(foo);
    pf.addInterface(Foo.clreplaced);
    Foo proxy = (Foo) pf.getProxy();
    replacedertThat(AopUtils.isJdkDynamicProxy(proxy)).as("Proxy is a JDK dynamic proxy").isTrue();
    replacedertThat(proxy).isInstanceOf(Foo.clreplaced);
    return proxy;
}

18 View Source File : MethodValidationTests.java
License : Apache License 2.0
Project Creator : SourceHot

@Test
public void testMethodValidationInterceptor() {
    MyValidBean bean = new MyValidBean();
    ProxyFactory proxyFactory = new ProxyFactory(bean);
    proxyFactory.addAdvice(new MethodValidationInterceptor());
    proxyFactory.addAdvisor(new AsyncAnnotationAdvisor());
    doTestProxyValidation((MyValidInterface<?>) proxyFactory.getProxy());
}

18 View Source File : LocalSlsbInvokerInterceptorTests.java
License : Apache License 2.0
Project Creator : SourceHot

@Test
public void testInvokesMethodOnEjbInstanceWithSeparateBusinessMethods() throws Exception {
    Object retVal = new Object();
    LocalInterface ejb = mock(LocalInterface.clreplaced);
    given(ejb.targetMethod()).willReturn(retVal);
    String jndiName = "foobar";
    Context mockContext = mockContext(jndiName, ejb);
    LocalSlsbInvokerInterceptor si = configuredInterceptor(mockContext, jndiName);
    ProxyFactory pf = new ProxyFactory(new Clreplaced<?>[] { BusinessMethods.clreplaced });
    pf.addAdvice(si);
    BusinessMethods target = (BusinessMethods) pf.getProxy();
    replacedertThat(target.targetMethod() == retVal).isTrue();
    verify(mockContext).close();
    verify(ejb).remove();
}

18 View Source File : LocalSlsbInvokerInterceptorTests.java
License : Apache License 2.0
Project Creator : SourceHot

@Test
public void testInvokesMethodOnEjbInstance() throws Exception {
    Object retVal = new Object();
    LocalInterfaceWithBusinessMethods ejb = mock(LocalInterfaceWithBusinessMethods.clreplaced);
    given(ejb.targetMethod()).willReturn(retVal);
    String jndiName = "foobar";
    Context mockContext = mockContext(jndiName, ejb);
    LocalSlsbInvokerInterceptor si = configuredInterceptor(mockContext, jndiName);
    ProxyFactory pf = new ProxyFactory(new Clreplaced<?>[] { BusinessMethods.clreplaced });
    pf.addAdvice(si);
    BusinessMethods target = (BusinessMethods) pf.getProxy();
    replacedertThat(target.targetMethod() == retVal).isTrue();
    verify(mockContext).close();
    verify(ejb).remove();
}

18 View Source File : NameMatchMethodPointcutTests.java
License : Apache License 2.0
Project Creator : SourceHot

/**
 * Create an empty pointcut, populating instance variables.
 */
@BeforeEach
public void setup() {
    ProxyFactory pf = new ProxyFactory(new SerializablePerson());
    nop = new SerializableNopInterceptor();
    pc = new NameMatchMethodPointcut();
    pf.addAdvisor(new DefaultPointcutAdvisor(pc, nop));
    proxied = (Person) pf.getProxy();
}

18 View Source File : TigerAspectJExpressionPointcutTests.java
License : Apache License 2.0
Project Creator : SourceHot

@Test
public void testAnnotationOnDynamicProxyMethod() throws Exception {
    String expression = "@annotation(test.annotation.transaction.Tx)";
    AspectJExpressionPointcut ajexp = new AspectJExpressionPointcut();
    ajexp.setExpression(expression);
    ProxyFactory factory = new ProxyFactory(new BeanA());
    factory.setProxyTargetClreplaced(false);
    IBeanA proxy = (IBeanA) factory.getProxy();
    replacedertThat(ajexp.matches(IBeanA.clreplaced.getMethod("getAge"), proxy.getClreplaced())).isTrue();
}

18 View Source File : TigerAspectJExpressionPointcutTests.java
License : Apache License 2.0
Project Creator : SourceHot

@Test
public void testAnnotationOnCglibProxyMethod() throws Exception {
    String expression = "@annotation(test.annotation.transaction.Tx)";
    AspectJExpressionPointcut ajexp = new AspectJExpressionPointcut();
    ajexp.setExpression(expression);
    ProxyFactory factory = new ProxyFactory(new BeanA());
    factory.setProxyTargetClreplaced(true);
    BeanA proxy = (BeanA) factory.getProxy();
    replacedertThat(ajexp.matches(BeanA.clreplaced.getMethod("getAge"), proxy.getClreplaced())).isTrue();
}

18 View Source File : AdvisedSupportListenerDemo.java
License : Apache License 2.0
Project Creator : mercyblitz

public static void main(String[] args) {
    DefaultEchoService defaultEchoService = new DefaultEchoService();
    // 注入目标对象(被代理)
    ProxyFactory proxyFactory = new ProxyFactory(defaultEchoService);
    proxyFactory.setTargetClreplaced(DefaultEchoService.clreplaced);
    // 添加 Advice 实现 MethodInterceptor < Interceptor < Advice
    proxyFactory.addAdvice(new EchoServiceMethodInterceptor());
    proxyFactory.addListener(new AdvisedSupportListener() {

        @Override
        public void activated(AdvisedSupport advised) {
            System.out.println("AOP 配置对象:" + advised + " 已激活");
        }

        @Override
        public void adviceChanged(AdvisedSupport advised) {
            System.out.println("AOP 配置对象:" + advised + " 已变化");
        }
    });
    // 获取代理对象
    // 激活事件触发 createAopProxy() <- getProxy()
    EchoService echoService = (EchoService) proxyFactory.getProxy();
    proxyFactory.addAdvice(new Advice() {
    });
}

18 View Source File : JaxWsPortProxyFactoryBean.java
License : Apache License 2.0
Project Creator : langtianya

@Override
public void afterPropertiesSet() {
    super.afterPropertiesSet();
    // Build a proxy that also exposes the JAX-WS BindingProvider interface.
    ProxyFactory pf = new ProxyFactory();
    pf.addInterface(getServiceInterface());
    pf.addInterface(BindingProvider.clreplaced);
    pf.addAdvice(this);
    this.serviceProxy = pf.getProxy(getBeanClreplacedLoader());
}

18 View Source File : NameMatchMethodPointcutTests.java
License : Apache License 2.0
Project Creator : langtianya

/**
 * Create an empty pointcut, populating instance variables.
 */
@Before
public void setUp() {
    ProxyFactory pf = new ProxyFactory(new SerializablePerson());
    nop = new SerializableNopInterceptor();
    pc = new NameMatchMethodPointcut();
    pf.addAdvisor(new DefaultPointcutAdvisor(pc, nop));
    proxied = (Person) pf.getProxy();
}

18 View Source File : AOPProxyTest.java
License : MIT License
Project Creator : hellokoding

@Test
public void callOnProxy() {
    ProxyFactory factory = new ProxyFactory(new Foo());
    // factory.addInterface(FooInterface.clreplaced);
    // factory.addAdvisor(new LoggingAspect());
    Foo pojo = (Foo) factory.getProxy();
    String s = pojo.fooBar();
    replacedertThat(s).isEqualTo("foobar");
}

18 View Source File : RepositoryEntityManagerEntityGraphInjector.java
License : MIT License
Project Creator : Cosium

/**
 * Builds a proxy on enreplacedy manager which is aware of methods that can make use of query hints.
 *
 * @param enreplacedyManager The enreplacedy manager to proxy
 * @return The proxied enreplacedy manager
 */
static EnreplacedyManager proxy(EnreplacedyManager enreplacedyManager) {
    ProxyFactory proxyFactory = new ProxyFactory(enreplacedyManager);
    proxyFactory.addAdvice(new RepositoryEnreplacedyManagerEnreplacedyGraphInjector());
    return (EnreplacedyManager) proxyFactory.getProxy();
}

18 View Source File : EmbeddedVelocityToolboxView.java
License : Apache License 2.0
Project Creator : alibaba

private ServletContext getToolboxConfigFileAwareServletContext() {
    ProxyFactory factory = new ProxyFactory();
    factory.setTarget(getServletContext());
    factory.addAdvice(new GetResourceMethodInterceptor(getToolboxConfigLocation()));
    return (ServletContext) factory.getProxy(getClreplaced().getClreplacedLoader());
}

18 View Source File : EntityManagerAopProxyFactory.java
License : Apache License 2.0
Project Creator : adgadev

public static EnreplacedyManager createProxy(EnreplacedyManager target, StateListener stateListener, Identifier identifier) {
    ProxyFactory proxyFactory = new ProxyFactory(target);
    proxyFactory.addAdvice(new EnreplacedyManagerMethodInterceptor(stateListener, identifier));
    // TODO: switch to use cglib proxy via setTargetClreplaced/setProxyTargetClreplaced
    return (EnreplacedyManager) proxyFactory.getProxy();
}

17 View Source File : StandardBeanLifecycleDecorator.java
License : Apache License 2.0
Project Creator : zouzhirong

/**
 * Apply a lock (preferably a read lock allowing multiple concurrent access) to the bean. Callers should replace the
 * bean input with the output.
 *
 * @param bean the bean to lock
 * @param lock the lock to apply
 * @return a proxy that locks while its methods are executed
 */
private Object getDisposalLockProxy(Object bean, final Lock lock) {
    ProxyFactory factory = new ProxyFactory(bean);
    factory.setProxyTargetClreplaced(proxyTargetClreplaced);
    factory.addAdvice(new MethodInterceptor() {

        public Object invoke(MethodInvocation invocation) throws Throwable {
            lock.lock();
            try {
                return invocation.proceed();
            } finally {
                lock.unlock();
            }
        }
    });
    return factory.getProxy();
}

17 View Source File : ReactiveTransactionInterceptorTests.java
License : MIT License
Project Creator : Vip-Augus

@Override
protected Object advised(Object target, ReactiveTransactionManager ptm, TransactionAttributeSource[] tas) {
    TransactionInterceptor ti = new TransactionInterceptor();
    ti.setTransactionManager(ptm);
    ti.setTransactionAttributeSources(tas);
    ProxyFactory pf = new ProxyFactory(target);
    pf.addAdvice(0, ti);
    return pf.getProxy();
}

17 View Source File : ReactiveTransactionInterceptorTests.java
License : MIT License
Project Creator : Vip-Augus

/**
 * Template method to create an advised object given the
 * target object and transaction setup.
 * Creates a TransactionInterceptor and applies it.
 */
@Override
protected Object advised(Object target, ReactiveTransactionManager ptm, TransactionAttributeSource tas) {
    TransactionInterceptor ti = new TransactionInterceptor();
    ti.setTransactionManager(ptm);
    replacedertThat(ti.getTransactionManager()).isEqualTo(ptm);
    ti.setTransactionAttributeSource(tas);
    replacedertThat(ti.getTransactionAttributeSource()).isEqualTo(tas);
    ProxyFactory pf = new ProxyFactory(target);
    pf.addAdvice(0, ti);
    return pf.getProxy();
}

17 View Source File : AnnotationTransactionInterceptorTests.java
License : MIT License
Project Creator : Vip-Augus

@Test
public void clreplacedLevelOnly() {
    ProxyFactory proxyFactory = new ProxyFactory();
    proxyFactory.setTarget(new TestClreplacedLevelOnly());
    proxyFactory.addAdvice(this.ti);
    TestClreplacedLevelOnly proxy = (TestClreplacedLevelOnly) proxyFactory.getProxy();
    proxy.doSomething();
    replacedertGetTransactionAndCommitCount(1);
    proxy.doSomethingElse();
    replacedertGetTransactionAndCommitCount(2);
    proxy.doSomething();
    replacedertGetTransactionAndCommitCount(3);
    proxy.doSomethingElse();
    replacedertGetTransactionAndCommitCount(4);
}

17 View Source File : AnnotationTransactionInterceptorTests.java
License : MIT License
Project Creator : Vip-Augus

@Test
public void withCommitOnCheckedException() {
    ProxyFactory proxyFactory = new ProxyFactory();
    proxyFactory.setTarget(new TestWithExceptions());
    proxyFactory.addAdvice(this.ti);
    TestWithExceptions proxy = (TestWithExceptions) proxyFactory.getProxy();
    try {
        proxy.doSomethingElseWithCheckedException();
        fail("Should throw Exception");
    } catch (Exception ex) {
        replacedertGetTransactionAndCommitCount(1);
    }
}

17 View Source File : AnnotationTransactionInterceptorTests.java
License : MIT License
Project Creator : Vip-Augus

@Test
public void crossClreplacedInterfaceOnJdkProxy() {
    ProxyFactory proxyFactory = new ProxyFactory();
    proxyFactory.setTarget(new OtherServiceImpl());
    proxyFactory.addInterface(OtherService.clreplaced);
    proxyFactory.addAdvice(this.ti);
    OtherService otherService = (OtherService) proxyFactory.getProxy();
    otherService.foo();
    replacedertGetTransactionAndCommitCount(1);
}

17 View Source File : AnnotationTransactionInterceptorTests.java
License : MIT License
Project Creator : Vip-Augus

@Test
public void withVavrTryCheckedExceptionAndRollbackRule() {
    ProxyFactory proxyFactory = new ProxyFactory();
    proxyFactory.setTarget(new TestWithVavrTry());
    proxyFactory.addAdvice(this.ti);
    TestWithVavrTry proxy = (TestWithVavrTry) proxyFactory.getProxy();
    proxy.doSomethingErroneousWithCheckedExceptionAndRollbackRule();
    replacedertGetTransactionAndRollbackCount(1);
}

See More Examples