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 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 DefaultRouterParser method postProcess.
@Override
protected void postProcess(BeanDefinitionBuilder builder, Element element, ParserContext parserContext) {
List<Element> mappingElements = DomUtils.getChildElementsByTagName(element, "mapping");
if (!CollectionUtils.isEmpty(mappingElements)) {
ManagedMap<String, String> channelMappings = new ManagedMap<String, String>();
for (Element mappingElement : mappingElements) {
channelMappings.put(mappingElement.getAttribute("value"), mappingElement.getAttribute("channel"));
}
builder.addPropertyValue("channelMappings", channelMappings);
}
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "default-output-channel");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "timeout");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "resolution-required");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "apply-sequence");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "ignore-send-failures");
}
use of org.springframework.beans.factory.support.ManagedMap in project spring-integration by spring-projects.
the class GatewayParser method parse.
@Override
@SuppressWarnings("rawtypes")
public BeanDefinition parse(final Element element, ParserContext parserContext) {
boolean isNested = parserContext.isNested();
final Map<String, Object> gatewayAttributes = new HashMap<String, Object>();
gatewayAttributes.put("name", element.getAttribute(AbstractBeanDefinitionParser.ID_ATTRIBUTE));
gatewayAttributes.put("defaultPayloadExpression", element.getAttribute("default-payload-expression"));
gatewayAttributes.put("defaultRequestChannel", element.getAttribute(isNested ? "request-channel" : "default-request-channel"));
gatewayAttributes.put("defaultReplyChannel", element.getAttribute(isNested ? "reply-channel" : "default-reply-channel"));
gatewayAttributes.put("errorChannel", element.getAttribute("error-channel"));
String asyncExecutor = element.getAttribute("async-executor");
if (!element.hasAttribute("async-executor") || StringUtils.hasLength(asyncExecutor)) {
gatewayAttributes.put("asyncExecutor", asyncExecutor);
} else {
gatewayAttributes.put("asyncExecutor", null);
}
gatewayAttributes.put("mapper", element.getAttribute("mapper"));
gatewayAttributes.put("defaultReplyTimeout", element.getAttribute(isNested ? "reply-timeout" : "default-reply-timeout"));
gatewayAttributes.put("defaultRequestTimeout", element.getAttribute(isNested ? "request-timeout" : "default-request-timeout"));
List<Element> headerElements = DomUtils.getChildElementsByTagName(element, "default-header");
if (!CollectionUtils.isEmpty(headerElements)) {
List<Map<String, Object>> headers = new ArrayList<Map<String, Object>>(headerElements.size());
for (Element e : headerElements) {
Map<String, Object> header = new HashMap<String, Object>();
header.put("name", e.getAttribute("name"));
header.put("value", e.getAttribute("value"));
header.put("expression", e.getAttribute("expression"));
headers.add(header);
}
gatewayAttributes.put("defaultHeaders", headers.toArray(new Map[headers.size()]));
}
List<Element> methodElements = DomUtils.getChildElementsByTagName(element, "method");
if (!CollectionUtils.isEmpty(methodElements)) {
Map<String, BeanDefinition> methodMetadataMap = new ManagedMap<String, BeanDefinition>();
for (Element methodElement : methodElements) {
String methodName = methodElement.getAttribute("name");
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"));
Assert.state(!hasMapper || !StringUtils.hasText(element.getAttribute("payload-expression")), "'payload-expression' is not allowed when a 'mapper' is provided");
IntegrationNamespaceUtils.setValueIfAttributeDefined(methodMetadataBuilder, methodElement, "payload-expression");
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<String, Object>();
for (Element headerElement : invocationHeaders) {
BeanDefinition expressionDef = IntegrationNamespaceUtils.createExpressionDefinitionFromValueOrExpression("value", "expression", parserContext, headerElement, true);
headerExpressions.put(headerElement.getAttribute("name"), expressionDef);
}
methodMetadataBuilder.addPropertyValue("headerExpressions", headerExpressions);
}
methodMetadataMap.put(methodName, methodMetadataBuilder.getBeanDefinition());
}
gatewayAttributes.put("methods", methodMetadataMap);
}
gatewayAttributes.put("serviceInterface", element.getAttribute("service-interface"));
BeanDefinitionHolder gatewayHolder = this.registrar.parse(gatewayAttributes);
if (isNested) {
return gatewayHolder.getBeanDefinition();
} else {
BeanDefinitionReaderUtils.registerBeanDefinition(gatewayHolder, parserContext.getRegistry());
return null;
}
}
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<String, Map<?, ?>>();
Map<String, String> payloadExpressionMap = new HashMap<String, String>();
Map<String, Map<String, String>> headersExpressionMap = new HashMap<String, Map<String, String>>();
Map<String, String> channelMap = new HashMap<String, String>();
ManagedMap<String, Object> resolvableChannelMap = new ManagedMap<String, Object>();
if (mappings != null && mappings.size() > 0) {
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
List<Element> headerElements = DomUtils.getChildElementsByTagName(mapping, "header");
Map<String, String> headerExpressions = new HashMap<String, String>();
for (Element headerElement : headerElements) {
String name = headerElement.getAttribute("name");
if (!StringUtils.hasText(name)) {
parserContext.getReaderContext().error("the 'name' attribute is required on the <header> element", parserContext.extractSource(headerElement));
continue;
}
String value = headerElement.getAttribute("value");
String expression = headerElement.getAttribute("expression");
boolean hasValue = StringUtils.hasText(value);
boolean hasExpression = StringUtils.hasText(expression);
if (hasValue == hasExpression) {
parserContext.getReaderContext().error("exactly one of 'value' or 'expression' is required on the <header> element", parserContext.extractSource(headerElement));
continue;
}
if (hasValue) {
expression = "'" + value + "'";
}
headerExpressions.put(name, expression);
}
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;
}
Aggregations