private boolean routerAttributesProvided(List<Annotation> annotations) { String defaultOutputChannel = MessagingAnnotationUtils.resolveAttribute(annotations, "defaultOutputChannel", String.class); String[] channelMappings = MessagingAnnotationUtils.resolveAttribute(annotations, "channelMappings", String[].class); String prefix = MessagingAnnotationUtils.resolveAttribute(annotations, "prefix", String.class); String suffix = MessagingAnnotationUtils.resolveAttribute(annotations, "suffix", String.class); String resolutionRequired = MessagingAnnotationUtils.resolveAttribute(annotations, "resolutionRequired", String.class); String applySequence = MessagingAnnotationUtils.resolveAttribute(annotations, "applySequence", String.class); String ignoreSendFailures = MessagingAnnotationUtils.resolveAttribute(annotations, "ignoreSendFailures", String.class); return StringUtils.hasText(defaultOutputChannel) || !ObjectUtils.isEmpty(channelMappings) || StringUtils.hasText(prefix) || StringUtils.hasText(suffix) || StringUtils.hasText(resolutionRequired) || StringUtils.hasText(applySequence) || StringUtils.hasText(ignoreSendFailures); }
protected String generateHandlerBeanName(String originalBeanName, Method method) { String name = MessagingAnnotationUtils.endpointIdValue(method); if (!StringUtils.hasText(name)) { String baseName = originalBeanName + "." + method.getName() + "." + ClassUtils.getShortNameAsProperty(this.annotationType); name = baseName; int count = 1; while (this.beanFactory.containsBean(name)) { name = baseName + "#" + (++count); } } return name + IntegrationConfigUtils.HANDLER_ALIAS_SUFFIX; }
Method releaseStrategyMethod = MessagingAnnotationUtils.findAnnotatedMethod(bean, ReleaseStrategy.class); if (releaseStrategyMethod != null) { releaseStrategy = new MethodInvokingReleaseStrategy(bean, releaseStrategyMethod); Method correlationStrategyMethod = MessagingAnnotationUtils.findAnnotatedMethod(bean, CorrelationStrategy.class); if (correlationStrategyMethod != null) { correlationStrategy = new MethodInvokingCorrelationStrategy(bean, correlationStrategyMethod); correlationStrategy, releaseStrategy); String discardChannelName = MessagingAnnotationUtils.resolveAttribute(annotations, "discardChannel", String.class); if (StringUtils.hasText(discardChannelName)) { handler.setDiscardChannelName(discardChannelName); String outputChannelName = MessagingAnnotationUtils.resolveAttribute(annotations, "outputChannel", String.class); if (StringUtils.hasText(outputChannelName)) { handler.setOutputChannelName(outputChannelName); String sendPartialResultsOnExpiry = MessagingAnnotationUtils.resolveAttribute(annotations, "sendPartialResultsOnExpiry", String.class); if (sendPartialResultsOnExpiry != null) {
String sendTimeout = MessagingAnnotationUtils.resolveAttribute(annotations, "sendTimeout", String.class); if (sendTimeout != null) { String resolvedValue = this.beanFactory.resolveEmbeddedValue(sendTimeout); String handlerBeanName = generateHandlerBeanName(beanName, method); if (handler instanceof ReplyProducingMessageHandlerWrapper && StringUtils.hasText(MessagingAnnotationUtils.endpointIdValue(method))) { handlerBeanName = handlerBeanName + ".wrapper";
/** * TODO until SPR-11709 will be resolved. * For any empty values, traverses back up the meta-annotation hierarchy to * see if a value has been overridden to empty, and replaces the first such value found. * @param valuesHierarchy The values hierarchy in order. * @param annotationAttributes The current attribute values. */ private void replaceEmptyOverrides(List<MultiValueMap<String, Object>> valuesHierarchy, Map<String, Object> annotationAttributes) { for (Entry<String, Object> entry : annotationAttributes.entrySet()) { Object value = entry.getValue(); if (!MessagingAnnotationUtils.hasValue(value)) { // see if we overrode a value that was higher in the annotation chain for (MultiValueMap<String, Object> metaAttributesMap : valuesHierarchy) { Object newValue = metaAttributesMap.getFirst(entry.getKey()); if (MessagingAnnotationUtils.hasValue(newValue)) { annotationAttributes.put(entry.getKey(), newValue); break; } } } } }
@Override public void afterPropertiesSet() throws Exception { if (this.target instanceof ReleaseStrategy && !StringUtils.hasText(this.methodName)) { this.strategy = (ReleaseStrategy) this.target; return; } if (this.target != null) { if (StringUtils.hasText(this.methodName)) { this.strategy = new MethodInvokingReleaseStrategy(this.target, this.methodName); } else { Method method = MessagingAnnotationUtils.findAnnotatedMethod(this.target, org.springframework.integration.annotation.ReleaseStrategy.class); if (method != null) { this.strategy = new MethodInvokingReleaseStrategy(this.target, method); } else { if (logger.isWarnEnabled()) { logger.warn("No ReleaseStrategy annotated method found on " + this.target.getClass().getSimpleName() + "; falling back to SimpleSequenceSizeReleaseStrategy, target: " + this.target + ", methodName: " + this.methodName); } } } } else { logger.warn("No target supplied; falling back to SimpleSequenceSizeReleaseStrategy"); } }
MethodParameter methodParameter = GatewayMethodInboundMessageMapper.this.parameterList.get(i); Annotation annotation = MessagingAnnotationUtils.findMessagePartAnnotation(methodParameter.getParameterAnnotations(), false); if (annotation != null) {
public static Method findAnnotatedMethod(Object target, final Class<? extends Annotation> annotationType) { final AtomicReference<Method> reference = new AtomicReference<Method>(); ReflectionUtils.doWithMethods(getTargetClass(target), method -> reference.compareAndSet(null, method), method -> ReflectionUtils.USER_DECLARED_METHODS.matches(method) && AnnotatedElementUtils.isAnnotated(method, annotationType.getName())); return reference.get(); }
String sendTimeout = MessagingAnnotationUtils.resolveAttribute(annotations, "sendTimeout", String.class); if (sendTimeout != null) { String resolvedValue = this.beanFactory.resolveEmbeddedValue(sendTimeout); String handlerBeanName = generateHandlerBeanName(beanName, method); if (handler instanceof ReplyProducingMessageHandlerWrapper && StringUtils.hasText(MessagingAnnotationUtils.endpointIdValue(method))) { handlerBeanName = handlerBeanName + ".wrapper";
/** * Get the attribute value from the annotation hierarchy, returning the first non-empty * value closest to the annotated method. While traversing up the hierarchy, for string-valued * attributes, an empty string is ignored. For array-valued attributes, an empty * array is ignored. * The overridden attribute must be the same type. * @param annotations The meta-annotations in order (closest first). * @param name The attribute name. * @param requiredType The expected type. * @param <T> The type. * @return The value. */ @SuppressWarnings("unchecked") public static <T> T resolveAttribute(List<Annotation> annotations, String name, Class<T> requiredType) { for (Annotation annotation : annotations) { if (annotation != null) { Object value = AnnotationUtils.getValue(annotation, name); if (value != null && value.getClass() == requiredType && hasValue(value)) { return (T) value; } } } return null; }
@Override public void afterPropertiesSet() throws Exception { if (this.target instanceof CorrelationStrategy && !StringUtils.hasText(this.methodName)) { this.strategy = (CorrelationStrategy) this.target; return; } if (this.target != null) { if (StringUtils.hasText(this.methodName)) { this.strategy = new MethodInvokingCorrelationStrategy(this.target, this.methodName); } else { Method method = MessagingAnnotationUtils.findAnnotatedMethod(this.target, org.springframework.integration.annotation.CorrelationStrategy.class); if (method != null) { this.strategy = new MethodInvokingCorrelationStrategy(this.target, method); } } } }
Class<?> parameterType = parameterTypeDescriptor.getObjectType(); Annotation mappingAnnotation = MessagingAnnotationUtils.findMessagePartAnnotation(parameterAnnotations[i], true); if (mappingAnnotation != null) { Class<? extends Annotation> annotationType = mappingAnnotation.annotationType();
public static Method findAnnotatedMethod(Object target, final Class<? extends Annotation> annotationType) { final AtomicReference<Method> reference = new AtomicReference<Method>(); ReflectionUtils.doWithMethods(getTargetClass(target), method -> reference.compareAndSet(null, method), method -> ReflectionUtils.USER_DECLARED_METHODS.matches(method) && AnnotatedElementUtils.isAnnotated(method, annotationType.getName())); return reference.get(); }
protected void setOutputChannelIfPresent(List<Annotation> annotations, AbstractReplyProducingMessageHandler handler) { String outputChannelName = MessagingAnnotationUtils.resolveAttribute(annotations, "outputChannel", String.class); if (StringUtils.hasText(outputChannelName)) { handler.setOutputChannelName(outputChannelName); } }
Method releaseStrategyMethod = MessagingAnnotationUtils.findAnnotatedMethod(bean, ReleaseStrategy.class); if (releaseStrategyMethod != null) { releaseStrategy = new MethodInvokingReleaseStrategy(bean, releaseStrategyMethod); Method correlationStrategyMethod = MessagingAnnotationUtils.findAnnotatedMethod(bean, CorrelationStrategy.class); if (correlationStrategyMethod != null) { correlationStrategy = new MethodInvokingCorrelationStrategy(bean, correlationStrategyMethod); correlationStrategy, releaseStrategy); String discardChannelName = MessagingAnnotationUtils.resolveAttribute(annotations, "discardChannel", String.class); if (StringUtils.hasText(discardChannelName)) { handler.setDiscardChannelName(discardChannelName); String outputChannelName = MessagingAnnotationUtils.resolveAttribute(annotations, "outputChannel", String.class); if (StringUtils.hasText(outputChannelName)) { handler.setOutputChannelName(outputChannelName); String sendPartialResultsOnExpiry = MessagingAnnotationUtils.resolveAttribute(annotations, "sendPartialResultsOnExpiry", String.class); if (sendPartialResultsOnExpiry != null) {
protected String generateBeanName(String originalBeanName, Method method, Class<? extends Annotation> annotationType) { String name = MessagingAnnotationUtils.endpointIdValue(method); if (!StringUtils.hasText(name)) { String baseName = originalBeanName + "." + method.getName() + "." + ClassUtils.getShortNameAsProperty(annotationType); name = baseName; int count = 1; while (this.beanFactory.containsBean(name)) { name = baseName + "#" + (++count); } } return name; }
protected void checkMessageHandlerAttributes(String handlerBeanName, List<Annotation> annotations) { for (String attribute : this.messageHandlerAttributes) { for (Annotation annotation : annotations) { Object value = AnnotationUtils.getValue(annotation, attribute); if (MessagingAnnotationUtils.hasValue(value)) { throw new BeanDefinitionValidationException("The MessageHandler [" + handlerBeanName + "] can not be populated because of ambiguity with annotation attributes " + this.messageHandlerAttributes + " which are not allowed when an integration annotation " + "is used with a @Bean definition for a MessageHandler." + "\nThe attribute causing the ambiguity is: [" + attribute + "]." + "\nUse the appropriate setter on the MessageHandler directly when configuring an " + "endpoint this way."); } } } }
@Override public void afterPropertiesSet() throws Exception { if (this.target instanceof CorrelationStrategy && !StringUtils.hasText(this.methodName)) { this.strategy = (CorrelationStrategy) this.target; return; } if (this.target != null) { if (StringUtils.hasText(this.methodName)) { this.strategy = new MethodInvokingCorrelationStrategy(this.target, this.methodName); } else { Method method = MessagingAnnotationUtils.findAnnotatedMethod(this.target, org.springframework.integration.annotation.CorrelationStrategy.class); if (method != null) { this.strategy = new MethodInvokingCorrelationStrategy(this.target, method); } } } }
MethodParameter methodParameter = GatewayMethodInboundMessageMapper.this.parameterList.get(i); Annotation annotation = MessagingAnnotationUtils.findMessagePartAnnotation(methodParameter.getParameterAnnotations(), false); if (annotation != null) {
@Override public boolean shouldCreateEndpoint(Method method, List<Annotation> annotations) { boolean isBean = AnnotatedElementUtils.isAnnotated(method, Bean.class.getName()); Assert.isTrue(isBean, "'@BridgeFrom' is eligible only for '@Bean' methods"); boolean isMessageChannelBean = MessageChannel.class.isAssignableFrom(method.getReturnType()); Assert.isTrue(isMessageChannelBean, "'@BridgeFrom' is eligible only for 'MessageChannel' '@Bean' methods"); String channel = MessagingAnnotationUtils.resolveAttribute(annotations, "value", String.class); Assert.isTrue(StringUtils.hasText(channel), "'@BridgeFrom.value()' (inputChannelName) must not be empty"); boolean hasBridgeTo = AnnotatedElementUtils.isAnnotated(method, BridgeTo.class.getName()); Assert.isTrue(!hasBridgeTo, "'@BridgeFrom' and '@BridgeTo' are mutually exclusive 'MessageChannel' " + "'@Bean' method annotations"); return true; }