@Test void verifyBasicAdvice() throws Exception { AmazonS3 amazonS3 = mock(AmazonS3.class); assertThat(AopUtils.isAopProxy(amazonS3)).isFalse(); AmazonS3 proxy = AmazonS3ProxyFactory.createProxy(amazonS3); assertThat(AopUtils.isAopProxy(proxy)).isTrue(); Advised advised = (Advised) proxy; assertThat(advised.getAdvisors().length).isEqualTo(1); assertThat(advised.getAdvisors()[0].getAdvice()).isInstanceOf( AmazonS3ProxyFactory.SimpleStorageRedirectInterceptor.class); assertThat(AopUtils.isAopProxy(advised.getTargetSource().getTarget())).isFalse(); }
public static AmazonS3 createProxy(AmazonS3 amazonS3) { Assert.notNull(amazonS3, "AmazonS3 client must not be null"); if (AopUtils.isAopProxy(amazonS3)) { Advised advised = (Advised) amazonS3; for (Advisor advisor : advised.getAdvisors()) { if (ClassUtils.isAssignableValue(SimpleStorageRedirectInterceptor.class, advisor.getAdvice())) { return amazonS3; } } try { advised.addAdvice(new SimpleStorageRedirectInterceptor( (AmazonS3) advised.getTargetSource().getTarget())); } catch (Exception e) { throw new RuntimeException( "Error adding advice for class amazonS3 instance", e); } return amazonS3; } ProxyFactory factory = new ProxyFactory(amazonS3); factory.setInterfaces(AmazonS3.class); factory.addAdvice(new SimpleStorageRedirectInterceptor(amazonS3)); return (AmazonS3) factory.getProxy(); }
AmazonS3ProxyFactory { public static AmazonS3 createProxy(AmazonS3 amazonS3) { Assert.notNull(amazonS3, "AmazonS3 client must not be null"); if (AopUtils.isAopProxy(amazonS3)) { Advised advised = (Advised) amazonS3; for (Advisor advisor : advised.getAdvisors()) { if (ClassUtils.isAssignableValue(SimpleStorageRedirectInterceptor.class, advisor.getAdvice())) { return amazonS3; } } try { advised.addAdvice(new SimpleStorageRedirectInterceptor( (AmazonS3) advised.getTargetSource().getTarget())); } catch (Exception e) { throw new RuntimeException( "Error adding advice for class amazonS3 instance", e); } return amazonS3; } ProxyFactory factory = new ProxyFactory(amazonS3); factory.setInterfaces(AmazonS3.class); factory.addAdvice(new SimpleStorageRedirectInterceptor(amazonS3)); return (AmazonS3) factory.getProxy(); } }
AmazonS3ProxyFactory { public static AmazonS3 createProxy(AmazonS3 amazonS3) { Assert.notNull(amazonS3, "AmazonS3 client must not be null"); if (AopUtils.isAopProxy(amazonS3)) { Advised advised = (Advised) amazonS3; for (Advisor advisor : advised.getAdvisors()) { if (ClassUtils.isAssignableValue(SimpleStorageRedirectInterceptor.class, advisor.getAdvice())) { return amazonS3; } } try { advised.addAdvice(new SimpleStorageRedirectInterceptor( (AmazonS3) advised.getTargetSource().getTarget())); } catch (Exception e) { throw new RuntimeException( "Error adding advice for class amazonS3 instance", e); } return amazonS3; } ProxyFactory factory = new ProxyFactory(amazonS3); factory.setInterfaces(AmazonS3.class); factory.addAdvice(new SimpleStorageRedirectInterceptor(amazonS3)); return (AmazonS3) factory.getProxy(); } private  AmazonS3ProxyFactory(); }
AmazonS3ProxyFactory { public static AmazonS3 createProxy(AmazonS3 amazonS3) { Assert.notNull(amazonS3, "AmazonS3 client must not be null"); if (AopUtils.isAopProxy(amazonS3)) { Advised advised = (Advised) amazonS3; for (Advisor advisor : advised.getAdvisors()) { if (ClassUtils.isAssignableValue(SimpleStorageRedirectInterceptor.class, advisor.getAdvice())) { return amazonS3; } } try { advised.addAdvice(new SimpleStorageRedirectInterceptor( (AmazonS3) advised.getTargetSource().getTarget())); } catch (Exception e) { throw new RuntimeException( "Error adding advice for class amazonS3 instance", e); } return amazonS3; } ProxyFactory factory = new ProxyFactory(amazonS3); factory.setInterfaces(AmazonS3.class); factory.addAdvice(new SimpleStorageRedirectInterceptor(amazonS3)); return (AmazonS3) factory.getProxy(); } private  AmazonS3ProxyFactory(); static AmazonS3 createProxy(AmazonS3 amazonS3); }
AmazonS3ProxyFactory { public static AmazonS3 createProxy(AmazonS3 amazonS3) { Assert.notNull(amazonS3, "AmazonS3 client must not be null"); if (AopUtils.isAopProxy(amazonS3)) { Advised advised = (Advised) amazonS3; for (Advisor advisor : advised.getAdvisors()) { if (ClassUtils.isAssignableValue(SimpleStorageRedirectInterceptor.class, advisor.getAdvice())) { return amazonS3; } } try { advised.addAdvice(new SimpleStorageRedirectInterceptor( (AmazonS3) advised.getTargetSource().getTarget())); } catch (Exception e) { throw new RuntimeException( "Error adding advice for class amazonS3 instance", e); } return amazonS3; } ProxyFactory factory = new ProxyFactory(amazonS3); factory.setInterfaces(AmazonS3.class); factory.addAdvice(new SimpleStorageRedirectInterceptor(amazonS3)); return (AmazonS3) factory.getProxy(); } private  AmazonS3ProxyFactory(); static AmazonS3 createProxy(AmazonS3 amazonS3);  }