Search in sources :

Example 76 with Advised

use of org.springframework.aop.framework.Advised in project spring-framework by spring-projects.

the class JoinPointMonitorAtAspectJAspect method checkXmlAspect.

private void checkXmlAspect(String appContextFile) {
    ApplicationContext context = new ClassPathXmlApplicationContext(appContextFile, getClass());
    ICounter counter = (ICounter) context.getBean("counter");
    boolean condition = counter instanceof Advised;
    assertThat(condition).as("Proxy didn't get created").isTrue();
    counter.increment();
    JoinPointMonitorAspect callCountingAspect = (JoinPointMonitorAspect) context.getBean("monitoringAspect");
    assertThat(callCountingAspect.beforeExecutions).as("Advise didn't get executed").isEqualTo(1);
    assertThat(callCountingAspect.aroundExecutions).as("Advise didn't get executed").isEqualTo(1);
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Advised(org.springframework.aop.framework.Advised)

Example 77 with Advised

use of org.springframework.aop.framework.Advised in project spring-cloud-stream by spring-cloud.

the class BindingService method bindConsumer.

@SuppressWarnings({ "unchecked", "rawtypes" })
public <T> Collection<Binding<T>> bindConsumer(T input, String inputName) {
    Collection<Binding<T>> bindings = new ArrayList<>();
    Class<?> inputClass = input.getClass();
    if (input instanceof Advised) {
        inputClass = Stream.of(((Advised) input).getProxiedInterfaces()).filter(c -> !c.getName().contains("org.springframework")).findFirst().orElse(inputClass);
    }
    Binder<T, ConsumerProperties, ?> binder = (Binder<T, ConsumerProperties, ?>) getBinder(inputName, inputClass);
    ConsumerProperties consumerProperties = this.bindingServiceProperties.getConsumerProperties(inputName);
    if (binder instanceof ExtendedPropertiesBinder) {
        Object extension = ((ExtendedPropertiesBinder) binder).getExtendedConsumerProperties(inputName);
        ExtendedConsumerProperties extendedConsumerProperties = new ExtendedConsumerProperties(extension);
        BeanUtils.copyProperties(consumerProperties, extendedConsumerProperties);
        consumerProperties = extendedConsumerProperties;
    }
    validate(consumerProperties);
    String bindingTarget = this.bindingServiceProperties.getBindingDestination(inputName);
    if (consumerProperties.isMultiplex()) {
        bindings.add(doBindConsumer(input, inputName, binder, consumerProperties, bindingTarget));
    } else {
        String[] bindingTargets = StringUtils.commaDelimitedListToStringArray(bindingTarget);
        for (String target : bindingTargets) {
            if (!consumerProperties.isPartitioned() || consumerProperties.getInstanceIndexList().isEmpty()) {
                Binding<T> binding = input instanceof PollableSource ? doBindPollableConsumer(input, inputName, binder, consumerProperties, target) : doBindConsumer(input, inputName, binder, consumerProperties, target);
                bindings.add(binding);
            } else {
                for (Integer index : consumerProperties.getInstanceIndexList()) {
                    if (index < 0) {
                        continue;
                    }
                    ConsumerProperties consumerPropertiesTemp = new ExtendedConsumerProperties<>("");
                    BeanUtils.copyProperties(consumerProperties, consumerPropertiesTemp);
                    consumerPropertiesTemp.setInstanceIndex(index);
                    Binding<T> binding = input instanceof PollableSource ? doBindPollableConsumer(input, inputName, binder, consumerPropertiesTemp, target) : doBindConsumer(input, inputName, binder, consumerPropertiesTemp, target);
                    bindings.add(binding);
                }
            }
        }
    }
    bindings = Collections.unmodifiableCollection(bindings);
    this.consumerBindings.put(inputName, new ArrayList<>(bindings));
    return bindings;
}
Also used : Binding(org.springframework.cloud.stream.binder.Binding) PollableConsumerBinder(org.springframework.cloud.stream.binder.PollableConsumerBinder) BinderFactory(org.springframework.cloud.stream.binder.BinderFactory) Advised(org.springframework.aop.framework.Advised) BindingServiceProperties(org.springframework.cloud.stream.config.BindingServiceProperties) HashMap(java.util.HashMap) ExtendedProducerProperties(org.springframework.cloud.stream.binder.ExtendedProducerProperties) ProducerProperties(org.springframework.cloud.stream.binder.ProducerProperties) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) Binding(org.springframework.cloud.stream.binder.Binding) Map(java.util.Map) ExtendedConsumerProperties(org.springframework.cloud.stream.binder.ExtendedConsumerProperties) ExtendedPropertiesBinder(org.springframework.cloud.stream.binder.ExtendedPropertiesBinder) Nullable(org.springframework.lang.Nullable) Collection(java.util.Collection) ConsumerProperties(org.springframework.cloud.stream.binder.ConsumerProperties) DataBinder(org.springframework.validation.DataBinder) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) TaskScheduler(org.springframework.scheduling.TaskScheduler) Date(java.sql.Date) List(java.util.List) Stream(java.util.stream.Stream) Binder(org.springframework.cloud.stream.binder.Binder) CollectionUtils(org.springframework.util.CollectionUtils) PollableSource(org.springframework.cloud.stream.binder.PollableSource) CustomValidatorBean(org.springframework.validation.beanvalidation.CustomValidatorBean) Log(org.apache.commons.logging.Log) LogFactory(org.apache.commons.logging.LogFactory) Collections(java.util.Collections) BeanUtils(org.springframework.beans.BeanUtils) StringUtils(org.springframework.util.StringUtils) ExtendedConsumerProperties(org.springframework.cloud.stream.binder.ExtendedConsumerProperties) ArrayList(java.util.ArrayList) ExtendedConsumerProperties(org.springframework.cloud.stream.binder.ExtendedConsumerProperties) ConsumerProperties(org.springframework.cloud.stream.binder.ConsumerProperties) PollableSource(org.springframework.cloud.stream.binder.PollableSource) PollableConsumerBinder(org.springframework.cloud.stream.binder.PollableConsumerBinder) ExtendedPropertiesBinder(org.springframework.cloud.stream.binder.ExtendedPropertiesBinder) DataBinder(org.springframework.validation.DataBinder) Binder(org.springframework.cloud.stream.binder.Binder) Advised(org.springframework.aop.framework.Advised) ExtendedPropertiesBinder(org.springframework.cloud.stream.binder.ExtendedPropertiesBinder)

Example 78 with Advised

use of org.springframework.aop.framework.Advised in project spring-cloud-stream by spring-cloud.

the class BindingService method bindProducer.

@SuppressWarnings({ "unchecked", "rawtypes" })
public <T> Binding<T> bindProducer(T output, String outputName, boolean cache, @Nullable Binder<T, ?, ProducerProperties> binder) {
    String bindingTarget = this.bindingServiceProperties.getBindingDestination(outputName);
    Class<?> outputClass = output.getClass();
    if (output instanceof Advised) {
        outputClass = Stream.of(((Advised) output).getProxiedInterfaces()).filter(c -> !c.getName().contains("org.springframework")).findFirst().orElse(outputClass);
    }
    if (binder == null) {
        binder = (Binder<T, ?, ProducerProperties>) getBinder(outputName, outputClass);
    }
    ProducerProperties producerProperties = this.bindingServiceProperties.getProducerProperties(outputName);
    if (binder instanceof ExtendedPropertiesBinder) {
        Object extension = ((ExtendedPropertiesBinder) binder).getExtendedProducerProperties(outputName);
        ExtendedProducerProperties extendedProducerProperties = new ExtendedProducerProperties<>(extension);
        BeanUtils.copyProperties(producerProperties, extendedProducerProperties);
        producerProperties = extendedProducerProperties;
    }
    validate(producerProperties);
    Binding<T> binding = doBindProducer(output, bindingTarget, binder, producerProperties);
    if (cache) {
        this.producerBindings.put(outputName, binding);
    }
    return binding;
}
Also used : PollableConsumerBinder(org.springframework.cloud.stream.binder.PollableConsumerBinder) BinderFactory(org.springframework.cloud.stream.binder.BinderFactory) Advised(org.springframework.aop.framework.Advised) BindingServiceProperties(org.springframework.cloud.stream.config.BindingServiceProperties) HashMap(java.util.HashMap) ExtendedProducerProperties(org.springframework.cloud.stream.binder.ExtendedProducerProperties) ProducerProperties(org.springframework.cloud.stream.binder.ProducerProperties) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) Binding(org.springframework.cloud.stream.binder.Binding) Map(java.util.Map) ExtendedConsumerProperties(org.springframework.cloud.stream.binder.ExtendedConsumerProperties) ExtendedPropertiesBinder(org.springframework.cloud.stream.binder.ExtendedPropertiesBinder) Nullable(org.springframework.lang.Nullable) Collection(java.util.Collection) ConsumerProperties(org.springframework.cloud.stream.binder.ConsumerProperties) DataBinder(org.springframework.validation.DataBinder) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) TaskScheduler(org.springframework.scheduling.TaskScheduler) Date(java.sql.Date) List(java.util.List) Stream(java.util.stream.Stream) Binder(org.springframework.cloud.stream.binder.Binder) CollectionUtils(org.springframework.util.CollectionUtils) PollableSource(org.springframework.cloud.stream.binder.PollableSource) CustomValidatorBean(org.springframework.validation.beanvalidation.CustomValidatorBean) Log(org.apache.commons.logging.Log) LogFactory(org.apache.commons.logging.LogFactory) Collections(java.util.Collections) BeanUtils(org.springframework.beans.BeanUtils) StringUtils(org.springframework.util.StringUtils) ExtendedProducerProperties(org.springframework.cloud.stream.binder.ExtendedProducerProperties) ProducerProperties(org.springframework.cloud.stream.binder.ProducerProperties) Advised(org.springframework.aop.framework.Advised) ExtendedPropertiesBinder(org.springframework.cloud.stream.binder.ExtendedPropertiesBinder) ExtendedProducerProperties(org.springframework.cloud.stream.binder.ExtendedProducerProperties)

Aggregations

Advised (org.springframework.aop.framework.Advised)78 Advisor (org.springframework.aop.Advisor)21 Test (org.junit.jupiter.api.Test)20 Test (org.junit.Test)18 ITestBean (org.springframework.beans.testfixture.beans.ITestBean)16 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)13 ProxyFactory (org.springframework.aop.framework.ProxyFactory)10 Advice (org.aopalliance.aop.Advice)8 JoinPoint (org.aspectj.lang.JoinPoint)6 ProceedingJoinPoint (org.aspectj.lang.ProceedingJoinPoint)6 TargetSource (org.springframework.aop.TargetSource)6 BeanCreationException (org.springframework.beans.factory.BeanCreationException)6 MessageChannel (org.springframework.messaging.MessageChannel)6 TestBean (org.springframework.beans.testfixture.beans.TestBean)4 ChannelAccessPolicy (org.springframework.integration.security.channel.ChannelAccessPolicy)4 ChannelSecurityInterceptor (org.springframework.integration.security.channel.ChannelSecurityInterceptor)4 ConfigAttribute (org.springframework.security.access.ConfigAttribute)4 ArrayList (java.util.ArrayList)3 Collections (java.util.Collections)3 List (java.util.List)3