use of org.springframework.beans.factory.support.ManagedMap in project spring-integration by spring-projects.
the class HeaderValueRouterTests method resolveChannelNameFromMap.
@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
public void resolveChannelNameFromMap() {
StaticApplicationContext context = new StaticApplicationContext();
ManagedMap channelMappings = new ManagedMap();
channelMappings.put("testKey", "testChannel");
RootBeanDefinition routerBeanDefinition = new RootBeanDefinition(HeaderValueRouter.class);
routerBeanDefinition.getConstructorArgumentValues().addGenericArgumentValue("testHeaderName");
routerBeanDefinition.getPropertyValues().addPropertyValue("resolutionRequired", "true");
routerBeanDefinition.getPropertyValues().addPropertyValue("channelMappings", channelMappings);
routerBeanDefinition.getPropertyValues().addPropertyValue("beanFactory", context);
context.registerBeanDefinition("router", routerBeanDefinition);
context.registerBeanDefinition("testChannel", new RootBeanDefinition(QueueChannel.class));
context.refresh();
MessageHandler handler = (MessageHandler) context.getBean("router");
Message<?> message = MessageBuilder.withPayload("test").setHeader("testHeaderName", "testKey").build();
handler.handleMessage(message);
QueueChannel channel = (QueueChannel) context.getBean("testChannel");
Message<?> result = channel.receive(1000);
assertNotNull(result);
assertSame(message, result);
context.close();
}
use of org.springframework.beans.factory.support.ManagedMap in project spring-integration by spring-projects.
the class HeaderValueRouterTests method resolveChannelNameFromMapAndCustomeResolver.
@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
public void resolveChannelNameFromMapAndCustomeResolver() {
final StaticApplicationContext context = new StaticApplicationContext();
ManagedMap channelMappings = new ManagedMap();
channelMappings.put("testKey", "testChannel");
RootBeanDefinition routerBeanDefinition = new RootBeanDefinition(HeaderValueRouter.class);
routerBeanDefinition.getConstructorArgumentValues().addGenericArgumentValue("testHeaderName");
routerBeanDefinition.getPropertyValues().addPropertyValue("resolutionRequired", "true");
routerBeanDefinition.getPropertyValues().addPropertyValue("channelMappings", channelMappings);
routerBeanDefinition.getPropertyValues().addPropertyValue("beanFactory", context);
routerBeanDefinition.getPropertyValues().addPropertyValue("channelResolver", (DestinationResolver<MessageChannel>) channelName -> context.getBean("anotherChannel", MessageChannel.class));
context.registerBeanDefinition("router", routerBeanDefinition);
context.registerBeanDefinition("testChannel", new RootBeanDefinition(QueueChannel.class));
context.registerBeanDefinition("anotherChannel", new RootBeanDefinition(QueueChannel.class));
context.refresh();
MessageHandler handler = (MessageHandler) context.getBean("router");
Message<?> message = MessageBuilder.withPayload("test").setHeader("testHeaderName", "testKey").build();
handler.handleMessage(message);
QueueChannel channel = (QueueChannel) context.getBean("anotherChannel");
Message<?> result = channel.receive(1000);
assertNotNull(result);
assertSame(message, result);
context.close();
}
use of org.springframework.beans.factory.support.ManagedMap in project spring-integration by spring-projects.
the class HttpInboundEndpointParser method doParse.
@Override
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
builder.addConstructorArgValue(this.expectReply);
String inputChannelAttributeName = this.getInputChannelAttributeName();
String inputChannelRef = element.getAttribute(inputChannelAttributeName);
if (!StringUtils.hasText(inputChannelRef)) {
if (this.expectReply) {
parserContext.getReaderContext().error("a '" + inputChannelAttributeName + "' reference is required", element);
} else {
inputChannelRef = IntegrationNamespaceUtils.createDirectChannel(element, parserContext);
}
}
builder.addPropertyReference("requestChannel", inputChannelRef);
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "error-channel");
BeanDefinition payloadExpressionDef = IntegrationNamespaceUtils.createExpressionDefIfAttributeDefined("payload-expression", element);
if (payloadExpressionDef != null) {
builder.addPropertyValue("payloadExpression", payloadExpressionDef);
}
List<Element> headerElements = DomUtils.getChildElementsByTagName(element, "header");
if (!CollectionUtils.isEmpty(headerElements)) {
ManagedMap<String, Object> headerElementsMap = new ManagedMap<String, Object>();
for (Element headerElement : headerElements) {
String name = headerElement.getAttribute(NAME_ATTRIBUTE);
BeanDefinition headerExpressionDef = IntegrationNamespaceUtils.createExpressionDefIfAttributeDefined(IntegrationNamespaceUtils.EXPRESSION_ATTRIBUTE, headerElement);
if (headerExpressionDef != null) {
headerElementsMap.put(name, headerExpressionDef);
}
}
builder.addPropertyValue("headerExpressions", headerElementsMap);
}
if (this.expectReply) {
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "reply-channel");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "request-timeout");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "reply-timeout");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "extract-reply-payload");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "reply-key");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "convert-exceptions");
} else {
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "send-timeout", "requestTimeout");
}
BeanDefinition expressionDef = IntegrationNamespaceUtils.createExpressionDefinitionFromValueOrExpression("view-name", "view-expression", parserContext, element, false);
if (expressionDef != null) {
builder.addPropertyValue("viewExpression", expressionDef);
}
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "errors-key");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "error-code");
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "message-converters");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "merge-with-default-converters");
String headerMapper = element.getAttribute("header-mapper");
String mappedRequestHeaders = element.getAttribute("mapped-request-headers");
String mappedResponseHeaders = element.getAttribute("mapped-response-headers");
boolean hasMappedRequestHeaders = StringUtils.hasText(mappedRequestHeaders);
boolean hasMappedResponseHeaders = StringUtils.hasText(mappedResponseHeaders);
if (StringUtils.hasText(headerMapper)) {
if (hasMappedRequestHeaders || hasMappedResponseHeaders) {
parserContext.getReaderContext().error("Neither 'mapped-request-headers' or 'mapped-response-headers' " + "attributes are allowed when a 'header-mapper' has been specified.", parserContext.extractSource(element));
}
builder.addPropertyReference("headerMapper", headerMapper);
} else {
BeanDefinitionBuilder headerMapperBuilder = BeanDefinitionBuilder.genericBeanDefinition(DefaultHttpHeaderMapper.class);
headerMapperBuilder.setFactoryMethod("inboundMapper");
if (hasMappedRequestHeaders) {
headerMapperBuilder.addPropertyValue("inboundHeaderNames", mappedRequestHeaders);
}
if (hasMappedResponseHeaders) {
headerMapperBuilder.addPropertyValue("outboundHeaderNames", mappedResponseHeaders);
}
builder.addPropertyValue("headerMapper", headerMapperBuilder.getBeanDefinition());
}
BeanDefinition requestMappingDef = createRequestMapping(element);
builder.addPropertyValue("requestMapping", requestMappingDef);
Element crossOriginElement = DomUtils.getChildElementByTagName(element, "cross-origin");
if (crossOriginElement != null) {
BeanDefinitionBuilder crossOriginBuilder = BeanDefinitionBuilder.genericBeanDefinition(CrossOrigin.class);
String[] attributes = { "origin", "allowed-headers", "exposed-headers", "max-age", "method" };
for (String crossOriginAttribute : attributes) {
IntegrationNamespaceUtils.setValueIfAttributeDefined(crossOriginBuilder, crossOriginElement, crossOriginAttribute);
}
IntegrationNamespaceUtils.setValueIfAttributeDefined(crossOriginBuilder, crossOriginElement, "allow-credentials", true);
builder.addPropertyValue("crossOrigin", crossOriginBuilder.getBeanDefinition());
}
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "request-payload-type", "requestPayloadTypeClass");
BeanDefinition statusCodeExpressionDef = IntegrationNamespaceUtils.createExpressionDefIfAttributeDefined("status-code-expression", element);
if (statusCodeExpressionDef == null) {
statusCodeExpressionDef = IntegrationNamespaceUtils.createExpressionDefIfAttributeDefined("reply-timeout-status-code-expression", element);
}
if (statusCodeExpressionDef != null) {
builder.addPropertyValue("statusCodeExpression", statusCodeExpressionDef);
}
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, IntegrationNamespaceUtils.AUTO_STARTUP);
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, IntegrationNamespaceUtils.PHASE);
}
use of org.springframework.beans.factory.support.ManagedMap in project spring-integration by spring-projects.
the class SecuredChannelsParser method parseSecurityMetadataSource.
private BeanDefinition parseSecurityMetadataSource(Element element, ParserContext parserContext) {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(ChannelSecurityMetadataSource.class);
List<Element> accessPolicyElements = DomUtils.getChildElementsByTagName(element, "access-policy");
ManagedMap<String, BeanDefinition> patternMappings = new ManagedMap<String, BeanDefinition>();
for (Element accessPolicyElement : accessPolicyElements) {
String sendAccess = accessPolicyElement.getAttribute("send-access");
String receiveAccess = accessPolicyElement.getAttribute("receive-access");
if (!StringUtils.hasText(sendAccess) && !StringUtils.hasText(receiveAccess)) {
parserContext.getReaderContext().error("At least one of 'send-access' or 'receive-access' must be provided.", accessPolicyElement);
}
BeanDefinitionBuilder accessPolicyBuilder = BeanDefinitionBuilder.genericBeanDefinition(DefaultChannelAccessPolicy.class);
accessPolicyBuilder.addConstructorArgValue(sendAccess);
accessPolicyBuilder.addConstructorArgValue(receiveAccess);
accessPolicyBuilder.getBeanDefinition().setRole(BeanDefinition.ROLE_SUPPORT);
patternMappings.put(accessPolicyElement.getAttribute("pattern"), accessPolicyBuilder.getBeanDefinition());
}
builder.addConstructorArgValue(patternMappings);
return builder.getBeanDefinition();
}
use of org.springframework.beans.factory.support.ManagedMap in project BroadleafCommerce by BroadleafCommerce.
the class MetadataOverrideBeanDefinitionParser method parseInternal.
@Override
protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {
AbstractBeanDefinition response = null;
if (parserContext.getRegistry().containsBeanDefinition(ROOT_METADATA_OVERRIDE_BEAN)) {
response = (AbstractBeanDefinition) parserContext.getRegistry().getBeanDefinition(ROOT_METADATA_OVERRIDE_BEAN);
}
Map<String, BeanDefinition> overallMap;
if (response != null) {
overallMap = (Map<String, BeanDefinition>) response.getPropertyValues().get("sourceMap");
} else {
overallMap = new ManagedMap<>();
}
List<Element> overrideItemElements = DomUtils.getChildElementsByTagName(element, "overrideItem");
for (Element overrideItem : overrideItemElements) {
String configKey = overrideItem.getAttribute("configurationKey");
String ceilingEntity = overrideItem.getAttribute("ceilingEntity");
if (StringUtils.isEmpty(configKey) && StringUtils.isEmpty(ceilingEntity)) {
throw new IllegalArgumentException("Must specify either a configurationKey or a ceilingEntity attribute for the overrideItem element");
}
BeanDefinition overrideItemDefinition = null;
if (overallMap.containsKey(StringUtils.isEmpty(configKey) ? ceilingEntity : configKey)) {
overrideItemDefinition = overallMap.get(StringUtils.isEmpty(configKey) ? ceilingEntity : configKey);
}
Map<String, BeanDefinition> overrideItemMap;
if (overrideItemDefinition != null) {
overrideItemMap = (Map<String, BeanDefinition>) overrideItemDefinition.getPropertyValues().get("sourceMap");
} else {
overrideItemMap = new ManagedMap<>();
}
List<Element> fieldElements = DomUtils.getChildElementsByTagName(overrideItem, "field");
for (Element fieldElement : fieldElements) {
String fieldName = fieldElement.getAttribute("name");
BeanDefinition metadataDefinition;
if (overrideItemMap.containsKey(fieldName)) {
metadataDefinition = overrideItemMap.get(fieldName);
} else {
BeanDefinitionBuilder metadataBuilder = BeanDefinitionBuilder.rootBeanDefinition(FieldMetadataOverride.class);
metadataDefinition = metadataBuilder.getBeanDefinition();
overrideItemMap.put(fieldName, metadataDefinition);
}
{
List<Element> propElements = DomUtils.getChildElementsByTagName(fieldElement, "property");
for (Element propElement : propElements) {
String propName = propElement.getAttribute("name");
String propValue = propElement.getAttribute("value");
metadataDefinition.getPropertyValues().addPropertyValue(propName, propValue);
}
}
{
List<Element> validationElements = DomUtils.getChildElementsByTagName(fieldElement, "validation");
Map<String, Map<String, String>> validationConfigMap = new ManagedMap<>();
for (Element validationElement : validationElements) {
Map<String, String> validationMap = new ManagedMap<>();
List<Element> valPropElements = DomUtils.getChildElementsByTagName(validationElement, "property");
for (Element valPropElement : valPropElements) {
String valPropName = valPropElement.getAttribute("name");
String valPropValue = valPropElement.getAttribute("value");
validationMap.put(valPropName, valPropValue);
}
String className = validationElement.getAttribute("className");
validationConfigMap.put(className, validationMap);
}
if (!validationConfigMap.isEmpty()) {
metadataDefinition.getPropertyValues().addPropertyValue("validationConfigurations", validationConfigMap);
}
}
{
List<Element> showIfFieldEqualsElements = DomUtils.getChildElementsByTagName(fieldElement, "showIfFieldEquals");
Map<String, List<String>> valueConfigMap = new ManagedMap<>();
for (Element valueElement : showIfFieldEqualsElements) {
List<String> validationMap = new ArrayList<>();
List<Element> valPropElements = DomUtils.getChildElementsByTagName(valueElement, "property");
for (Element valPropElement : valPropElements) {
String valPropValue = valPropElement.getAttribute("value");
validationMap.add(valPropValue);
}
String className = valueElement.getAttribute("fieldName");
valueConfigMap.put(className, validationMap);
}
if (!valueConfigMap.isEmpty()) {
metadataDefinition.getPropertyValues().addPropertyValue("showIfFieldEquals", valueConfigMap);
}
}
{
List<Element> optionElements = DomUtils.getChildElementsByTagName(fieldElement, "optionFilterValue");
String[][] optionFilterValues = new String[optionElements.size()][3];
int j = 0;
for (Element optionElement : optionElements) {
optionFilterValues[j][0] = optionElement.getAttribute("name");
optionFilterValues[j][1] = optionElement.getAttribute("value");
optionFilterValues[j][2] = optionElement.getAttribute("type");
j++;
}
if (!ArrayUtils.isEmpty(optionFilterValues)) {
metadataDefinition.getPropertyValues().addPropertyValue("optionFilterValues", optionFilterValues);
}
}
{
List<Element> keyElements = DomUtils.getChildElementsByTagName(fieldElement, "mapKey");
String[][] keyValues = new String[keyElements.size()][2];
int j = 0;
for (Element keyElement : keyElements) {
keyValues[j][0] = keyElement.getAttribute("value");
keyValues[j][1] = keyElement.getAttribute("displayValue");
j++;
}
if (!ArrayUtils.isEmpty(keyValues)) {
metadataDefinition.getPropertyValues().addPropertyValue("keys", keyValues);
}
}
{
List<Element> children = DomUtils.getChildElementsByTagName(fieldElement, "customCriteria");
String[] values = new String[children.size()];
int j = 0;
for (Element childElem : children) {
values[j] = childElem.getAttribute("value");
j++;
}
if (!ArrayUtils.isEmpty(values)) {
metadataDefinition.getPropertyValues().addPropertyValue("customCriteria", values);
}
}
{
List<Element> children = DomUtils.getChildElementsByTagName(fieldElement, "maintainedAdornedTargetField");
String[] values = new String[children.size()];
int j = 0;
for (Element childElem : children) {
values[j] = childElem.getAttribute("value");
j++;
}
if (!ArrayUtils.isEmpty(values)) {
metadataDefinition.getPropertyValues().addPropertyValue("maintainedAdornedTargetFields", values);
}
}
{
List<Element> children = DomUtils.getChildElementsByTagName(fieldElement, "gridVisibleField");
String[] values = new String[children.size()];
int j = 0;
for (Element childElem : children) {
values[j] = childElem.getAttribute("value");
j++;
}
if (!ArrayUtils.isEmpty(values)) {
metadataDefinition.getPropertyValues().addPropertyValue("gridVisibleFields", values);
}
}
{
List<Element> propElements = DomUtils.getChildElementsByTagName(fieldElement, "selectizeVisibleField");
for (Element propElement : propElements) {
String propValue = propElement.getAttribute("value");
metadataDefinition.getPropertyValues().addPropertyValue("selectizeVisibleField", propValue);
}
}
}
List<Element> tabElements = DomUtils.getChildElementsByTagName(overrideItem, "tab");
for (Element tabElement : tabElements) {
String overrideName = tabElement.getAttribute("tabName");
BeanDefinition metadataDefinition;
if (overrideItemMap.containsKey(overrideName)) {
metadataDefinition = overrideItemMap.get(overrideName);
} else {
BeanDefinitionBuilder metadataBuilder = BeanDefinitionBuilder.rootBeanDefinition(MetadataOverride.class);
metadataDefinition = metadataBuilder.getBeanDefinition();
overrideItemMap.put(overrideName, metadataDefinition);
}
{
List<Element> propElements = DomUtils.getChildElementsByTagName(tabElement, "property");
for (Element propElement : propElements) {
String propName = propElement.getAttribute("property");
String propValue = propElement.getAttribute("value");
metadataDefinition.getPropertyValues().addPropertyValue(propName, propValue);
}
}
}
List<Element> groupElements = DomUtils.getChildElementsByTagName(overrideItem, "group");
for (Element groupElement : groupElements) {
String overrideName = groupElement.getAttribute("tabName");
overrideName += "-@-" + groupElement.getAttribute("groupName");
BeanDefinition metadataDefinition;
if (overrideItemMap.containsKey(overrideName)) {
metadataDefinition = overrideItemMap.get(overrideName);
} else {
BeanDefinitionBuilder metadataBuilder = BeanDefinitionBuilder.rootBeanDefinition(GroupMetadataOverride.class);
metadataDefinition = metadataBuilder.getBeanDefinition();
overrideItemMap.put(overrideName, metadataDefinition);
}
{
List<Element> propElements = DomUtils.getChildElementsByTagName(groupElement, "property");
for (Element propElement : propElements) {
String propName = propElement.getAttribute("property");
String propValue = propElement.getAttribute("value");
metadataDefinition.getPropertyValues().addPropertyValue(propName, propValue);
}
}
}
if (overrideItemDefinition == null) {
BeanDefinitionBuilder mapBuilder = BeanDefinitionBuilder.rootBeanDefinition(MapFactoryBean.class);
mapBuilder.addPropertyValue("sourceMap", overrideItemMap);
overallMap.put(StringUtils.isEmpty(configKey) ? ceilingEntity : configKey, mapBuilder.getBeanDefinition());
}
}
if (response == null) {
BeanDefinitionBuilder overallMapBuilder = BeanDefinitionBuilder.rootBeanDefinition(MapFactoryBean.class);
overallMapBuilder.addPropertyValue("sourceMap", overallMap);
response = overallMapBuilder.getBeanDefinition();
}
return response;
}
Aggregations