use of org.springframework.beans.factory.support.ManagedMap in project spring-integration by spring-projects.
the class GatewayParser method methods.
private void methods(final Element element, ParserContext parserContext, final Map<String, Object> gatewayAttributes) {
List<Element> methodElements = DomUtils.getChildElementsByTagName(element, "method");
if (!CollectionUtils.isEmpty(methodElements)) {
Map<String, BeanDefinition> methodMetadataMap = new ManagedMap<>();
for (Element methodElement : methodElements) {
String methodName = methodElement.getAttribute(AbstractBeanDefinitionParser.NAME_ATTRIBUTE);
BeanDefinitionBuilder methodMetadataBuilder = BeanDefinitionBuilder.genericBeanDefinition(GatewayMethodMetadata.class);
methodMetadataBuilder.addPropertyValue("requestChannelName", methodElement.getAttribute("request-channel"));
methodMetadataBuilder.addPropertyValue("replyChannelName", methodElement.getAttribute("reply-channel"));
methodMetadataBuilder.addPropertyValue("requestTimeout", methodElement.getAttribute("request-timeout"));
methodMetadataBuilder.addPropertyValue("replyTimeout", methodElement.getAttribute("reply-timeout"));
boolean hasMapper = StringUtils.hasText(element.getAttribute("mapper"));
String payloadExpression = methodElement.getAttribute("payload-expression");
Assert.state(!hasMapper || !StringUtils.hasText(payloadExpression), "'payload-expression' is not allowed when a 'mapper' is provided");
if (StringUtils.hasText(payloadExpression)) {
methodMetadataBuilder.addPropertyValue("payloadExpression", BeanDefinitionBuilder.genericBeanDefinition(ExpressionFactoryBean.class).addConstructorArgValue(payloadExpression).getBeanDefinition());
}
List<Element> invocationHeaders = DomUtils.getChildElementsByTagName(methodElement, "header");
if (!CollectionUtils.isEmpty(invocationHeaders)) {
Assert.state(!hasMapper, "header elements are not allowed when a 'mapper' is provided");
Map<String, Object> headerExpressions = new ManagedMap<>();
for (Element headerElement : invocationHeaders) {
BeanDefinition expressionDef = IntegrationNamespaceUtils.createExpressionDefinitionFromValueOrExpression("value", "expression", parserContext, headerElement, true);
headerExpressions.put(headerElement.getAttribute(AbstractBeanDefinitionParser.NAME_ATTRIBUTE), expressionDef);
}
methodMetadataBuilder.addPropertyValue("headerExpressions", headerExpressions);
}
methodMetadataMap.put(methodName, methodMetadataBuilder.getBeanDefinition());
}
gatewayAttributes.put("methods", methodMetadataMap);
}
}
use of org.springframework.beans.factory.support.ManagedMap in project spring-integration by spring-projects.
the class HeaderEnricherParserSupport method parseTransformer.
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
protected void parseTransformer(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
ManagedMap headers = new ManagedMap();
this.processHeaders(element, headers, parserContext);
builder.addConstructorArgValue(headers);
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "default-overwrite");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "should-skip-nulls");
this.postProcessHeaderEnricher(builder, element, parserContext);
}
use of org.springframework.beans.factory.support.ManagedMap in project spring-integration by spring-projects.
the class PublishingInterceptorParser method getMappings.
private Map<String, Map<?, ?>> getMappings(Element element, String defaultChannel, ParserContext parserContext) {
List<Element> mappings = DomUtils.getChildElementsByTagName(element, "method");
Map<String, Map<?, ?>> interceptorMappings = new HashMap<>();
Map<String, String> payloadExpressionMap = new HashMap<>();
Map<String, Map<String, String>> headersExpressionMap = new HashMap<>();
Map<String, String> channelMap = new HashMap<>();
ManagedMap<String, Object> resolvableChannelMap = new ManagedMap<>();
if (!CollectionUtils.isEmpty(mappings)) {
for (Element mapping : mappings) {
// set payloadMap
String methodPattern = StringUtils.hasText(mapping.getAttribute("pattern")) ? mapping.getAttribute("pattern") : "*";
String payloadExpression = StringUtils.hasText(mapping.getAttribute(PAYLOAD)) ? mapping.getAttribute(PAYLOAD) : "#return";
payloadExpressionMap.put(methodPattern, payloadExpression);
// set headersMap
Map<String, String> headerExpressions = headerExpressions(parserContext, mapping);
if (headerExpressions.size() > 0) {
headersExpressionMap.put(methodPattern, headerExpressions);
}
// set channelMap
String tmpChannel = mapping.getAttribute("channel");
String channel = StringUtils.hasText(tmpChannel) ? tmpChannel : defaultChannel;
channelMap.put(methodPattern, channel);
resolvableChannelMap.put(channel, new RuntimeBeanReference(channel));
}
}
if (payloadExpressionMap.size() == 0) {
payloadExpressionMap.put("*", "#return");
}
interceptorMappings.put(PAYLOAD, payloadExpressionMap);
if (headersExpressionMap.size() > 0) {
interceptorMappings.put("headers", headersExpressionMap);
}
if (channelMap.size() > 0) {
interceptorMappings.put("channels", channelMap);
interceptorMappings.put("resolvableChannels", resolvableChannelMap);
}
return interceptorMappings;
}
use of org.springframework.beans.factory.support.ManagedMap in project spring-integration by spring-projects.
the class AbstractRouterParser method parseRouter.
protected final BeanDefinition parseRouter(Element element, ParserContext parserContext) {
BeanDefinition beanDefinition = this.doParseRouter(element, parserContext);
if (beanDefinition != null) {
// check if mapping is provided otherwise returned values will be treated as channel names
List<Element> mappingElements = DomUtils.getChildElementsByTagName(element, "mapping");
if (!CollectionUtils.isEmpty(mappingElements)) {
ManagedMap<String, String> channelMappings = new ManagedMap<String, String>();
for (Element mappingElement : mappingElements) {
String key = mappingElement.getAttribute(this.getMappingKeyAttributeName());
channelMappings.put(key, mappingElement.getAttribute("channel"));
}
beanDefinition.getPropertyValues().add("channelMappings", channelMappings);
}
}
return beanDefinition;
}
use of org.springframework.beans.factory.support.ManagedMap in project spring-integration by spring-projects.
the class IdempotentReceiverAutoProxyCreatorInitializer method annotated.
private void annotated(ConfigurableListableBeanFactory beanFactory, List<Map<String, String>> idempotentEndpointsMapping, String beanName, BeanDefinition beanDefinition) throws LinkageError {
if (beanDefinition.getSource() instanceof MethodMetadata) {
MethodMetadata beanMethod = (MethodMetadata) beanDefinition.getSource();
String annotationType = IdempotentReceiver.class.getName();
if (beanMethod.isAnnotated(annotationType)) {
// NOSONAR never null
// NOSONAR
Object value = beanMethod.getAnnotationAttributes(annotationType).get("value");
if (value != null) {
Class<?> returnType;
if (beanMethod instanceof StandardMethodMetadata) {
returnType = ((StandardMethodMetadata) beanMethod).getIntrospectedMethod().getReturnType();
} else {
try {
returnType = ClassUtils.forName(beanMethod.getReturnTypeName(), beanFactory.getBeanClassLoader());
} catch (ClassNotFoundException e) {
throw new CannotLoadBeanClassException(beanDefinition.getDescription(), beanName, beanMethod.getReturnTypeName(), e);
}
}
String endpoint = beanName;
if (!MessageHandler.class.isAssignableFrom(returnType)) {
/*
MessageHandler beans, populated from @Bean methods, have a complex id,
including @Configuration bean name, method name and the Messaging annotation name.
The following pattern matches the bean name, regardless of the annotation name.
*/
endpoint = beanDefinition.getFactoryBeanName() + "." + beanName + ".*" + IntegrationConfigUtils.HANDLER_ALIAS_SUFFIX;
}
String[] interceptors = (String[]) value;
for (String interceptor : interceptors) {
Map<String, String> idempotentEndpoint = new ManagedMap<>();
idempotentEndpoint.put(interceptor, endpoint);
idempotentEndpointsMapping.add(idempotentEndpoint);
}
}
}
}
}
Aggregations