Java Code Examples for org.springframework.aop.framework.Advised#addAdvice()

The following examples show how to use org.springframework.aop.framework.Advised#addAdvice() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GenericScope.java    From spring-cloud-commons with Apache License 2.0 5 votes vote down vote up
@Override
public void setBeanFactory(BeanFactory beanFactory) {
	super.setBeanFactory(beanFactory);
	Object proxy = getObject();
	if (proxy instanceof Advised) {
		Advised advised = (Advised) proxy;
		advised.addAdvice(0, this);
	}
}
 
Example 2
Source File: AmazonS3ProxyFactory.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
/**
 * Factory-method to create a proxy using the {@link SimpleStorageRedirectInterceptor}
 * that supports redirects for buckets which are in a different region. This proxy
 * uses the amazonS3 parameter as a "prototype" and re-uses the credentials from the
 * passed in {@link AmazonS3} instance. Proxy implementations uses the
 * {@link AmazonS3ClientFactory} to create region specific clients, which are cached
 * by the implementation on a region basis to avoid unnecessary object creation.
 * @param amazonS3 Fully configured AmazonS3 client, the client can be an immutable
 * instance (created by the {@link com.amazonaws.services.s3.AmazonS3ClientBuilder})
 * as this proxy will not change the underlying implementation.
 * @return AOP-Proxy that intercepts all method calls using the
 * {@link SimpleStorageRedirectInterceptor}
 */
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();
}
 
Example 3
Source File: CompletionRegisteringBeanPostProcessor.java    From spring-domain-events with Apache License 2.0 4 votes vote down vote up
private Object createCompletionRegisteringProxy(Object bean) {

			if (bean instanceof Advised) {

				Advised advised = (Advised) bean;
				advised.addAdvice(advised.getAdvisors().length, interceptor);

				return bean;
			}

			ProxyFactory factory = new ProxyFactory(bean);
			factory.setProxyTargetClass(true);
			factory.addAdvice(interceptor);

			return factory.getProxy();
		}