@Override protected AbstractBeanDefinition parseConsumer(Element element, ParserContext parserContext) { BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(AmqpOutboundEndpoint.class); String amqpTemplateRef = element.getAttribute("amqp-template"); if (!StringUtils.hasText(amqpTemplateRef)) { amqpTemplateRef = "amqpTemplate"; } builder.addConstructorArgReference(amqpTemplateRef); IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "exchange-name", true); IntegrationNamespaceUtils.setValueIfAttributeDefined( builder, element, "exchange-name-expression"); IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "routing-key", true); IntegrationNamespaceUtils.setValueIfAttributeDefined( builder, element, "routing-key-expression"); IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "default-delivery-mode"); IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "lazy-connect"); IntegrationNamespaceUtils.configureHeaderMapper( element, builder, parserContext, DefaultAmqpHeaderMapper.class, null); IntegrationNamespaceUtils.setValueIfAttributeDefined( builder, element, "confirm-correlation-expression"); IntegrationNamespaceUtils.setReferenceIfAttributeDefined( builder, element, "confirm-ack-channel"); IntegrationNamespaceUtils.setReferenceIfAttributeDefined( builder, element, "confirm-nack-channel"); IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "return-channel"); return builder.getBeanDefinition(); }
@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)) { parserContext .getReaderContext() .error("a '" + inputChannelAttributeName + "' reference is required", element); } builder.addPropertyReference("requestChannel", inputChannelRef); 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"); } IntegrationNamespaceUtils.setValueIfAttributeDefined( builder, element, "supported-methods", "supportedMethodNames"); IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "request-payload-type"); IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "view-name"); IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "errors-key"); IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "error-code"); IntegrationNamespaceUtils.setReferenceIfAttributeDefined( builder, element, "message-converters"); IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "header-mapper"); }
@Override protected BeanDefinitionBuilder parseHandler(Element element, ParserContext parserContext) { final BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(ContentEnricher.class); IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "request-channel"); IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "reply-channel"); IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "request-timeout"); IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "reply-timeout"); IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "requires-reply"); List<Element> subElements = DomUtils.getChildElementsByTagName(element, "property"); if (!CollectionUtils.isEmpty(subElements)) { ManagedMap<String, Object> expressions = new ManagedMap<String, Object>(); for (Element subElement : subElements) { String name = subElement.getAttribute("name"); BeanDefinition beanDefinition = IntegrationNamespaceUtils.createExpressionDefinitionFromValueOrExpression( "value", "expression", parserContext, subElement, true); expressions.put(name, beanDefinition); } builder.addPropertyValue("propertyExpressions", expressions); } subElements = DomUtils.getChildElementsByTagName(element, "header"); if (!CollectionUtils.isEmpty(subElements)) { ManagedMap<String, Object> expressions = new ManagedMap<String, Object>(); for (Element subElement : subElements) { String name = subElement.getAttribute("name"); BeanDefinition expressionDefinition = IntegrationNamespaceUtils.createExpressionDefinitionFromValueOrExpression( "value", "expression", parserContext, subElement, true); BeanDefinitionBuilder valueProcessorBuilder = BeanDefinitionBuilder.genericBeanDefinition( IntegrationNamespaceUtils.BASE_PACKAGE + ".transformer.support.ExpressionEvaluatingHeaderValueMessageProcessor"); valueProcessorBuilder .addConstructorArgValue(expressionDefinition) .addConstructorArgValue(subElement.getAttribute("type")); IntegrationNamespaceUtils.setValueIfAttributeDefined( valueProcessorBuilder, subElement, "overwrite"); expressions.put(name, valueProcessorBuilder.getBeanDefinition()); } builder.addPropertyValue("headerExpressions", expressions); } IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "should-clone-payload"); String requestPayloadExpression = element.getAttribute("request-payload-expression"); if (StringUtils.hasText(requestPayloadExpression)) { BeanDefinitionBuilder expressionBuilder = BeanDefinitionBuilder.genericBeanDefinition(ExpressionFactoryBean.class); expressionBuilder.addConstructorArgValue(requestPayloadExpression); builder.addPropertyValue("requestPayloadExpression", expressionBuilder.getBeanDefinition()); } return builder; }
@Override protected BeanDefinitionBuilder parseHandler(Element element, ParserContext parserContext) { BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition( "org.springframework.integration.http.outbound.HttpRequestExecutingMessageHandler"); builder.addConstructorArgValue(element.getAttribute("url")); IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "http-method"); String restTemplate = element.getAttribute("rest-template"); if (StringUtils.hasText(restTemplate)) { HttpAdapterParsingUtils.verifyNoRestTemplateAttributes(element, parserContext); builder.addConstructorArgReference(restTemplate); } else { for (String referenceAttributeName : HttpAdapterParsingUtils.REST_TEMPLATE_REFERENCE_ATTRIBUTES) { IntegrationNamespaceUtils.setReferenceIfAttributeDefined( builder, element, referenceAttributeName); } } String headerMapper = element.getAttribute("header-mapper"); String mappedRequestHeaders = element.getAttribute("mapped-request-headers"); String mappedResponseHeaders = element.getAttribute("mapped-response-headers"); if (StringUtils.hasText(headerMapper)) { if (StringUtils.hasText(mappedRequestHeaders) || StringUtils.hasText(mappedResponseHeaders)) { parserContext .getReaderContext() .error( "Neither 'mappped-request-headers' or 'mapped-response-headers' " + "attributes are allowed when a 'header-mapper' has been specified.", parserContext.extractSource(element)); return null; } builder.addPropertyReference("headerMapper", headerMapper); } else { BeanDefinitionBuilder headerMapperBuilder = BeanDefinitionBuilder.genericBeanDefinition( "org.springframework.integration.http.support.DefaultHttpHeaderMapper"); headerMapperBuilder.setFactoryMethod("outboundMapper"); IntegrationNamespaceUtils.setValueIfAttributeDefined( headerMapperBuilder, element, "mapped-request-headers", "outboundHeaderNames"); IntegrationNamespaceUtils.setValueIfAttributeDefined( headerMapperBuilder, element, "mapped-response-headers", "inboundHeaderNames"); builder.addPropertyValue("headerMapper", headerMapperBuilder.getBeanDefinition()); } IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "charset"); IntegrationNamespaceUtils.setValueIfAttributeDefined( builder, element, "extract-request-payload", "extractPayload"); IntegrationNamespaceUtils.setValueIfAttributeDefined( builder, element, "expected-response-type"); IntegrationNamespaceUtils.setValueIfAttributeDefined( builder, element, "reply-timeout", "sendTimeout"); IntegrationNamespaceUtils.setReferenceIfAttributeDefined( builder, element, "reply-channel", "outputChannel"); HttpAdapterParsingUtils.configureUriVariableExpressions(builder, element); IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "transfer-cookies"); return builder; }
@Override protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) { BeanDefinitionBuilder metadataBuilder = BeanDefinitionBuilder.genericBeanDefinition(PollerMetadata.class); if (element.hasAttribute("ref")) { parserContext .getReaderContext() .error( "the 'ref' attribute must not be present on the top-level 'poller' element", element); } configureTrigger(element, metadataBuilder, parserContext); IntegrationNamespaceUtils.setValueIfAttributeDefined( metadataBuilder, element, "max-messages-per-poll"); IntegrationNamespaceUtils.setValueIfAttributeDefined( metadataBuilder, element, "receive-timeout"); IntegrationNamespaceUtils.setReferenceIfAttributeDefined( metadataBuilder, element, "task-executor"); Element txElement = DomUtils.getChildElementByTagName(element, "transactional"); Element adviceChainElement = DomUtils.getChildElementByTagName(element, "advice-chain"); IntegrationNamespaceUtils.configureAndSetAdviceChainIfPresent( adviceChainElement, txElement, metadataBuilder.getRawBeanDefinition(), parserContext); if (txElement != null) { IntegrationNamespaceUtils.setReferenceIfAttributeDefined( metadataBuilder, txElement, "synchronization-factory", "transactionSynchronizationFactory"); } else if (adviceChainElement != null) { IntegrationNamespaceUtils.setReferenceIfAttributeDefined( metadataBuilder, adviceChainElement, "synchronization-factory", "transactionSynchronizationFactory"); } String errorChannel = element.getAttribute("error-channel"); if (StringUtils.hasText(errorChannel)) { BeanDefinitionBuilder errorHandler = BeanDefinitionBuilder.genericBeanDefinition(MessagePublishingErrorHandler.class); errorHandler.addPropertyReference("defaultErrorChannel", errorChannel); metadataBuilder.addPropertyValue("errorHandler", errorHandler.getBeanDefinition()); } return metadataBuilder.getBeanDefinition(); }
/** * Builds and configures a {@link BeanDefinitionBuilder} for {@link * HdfsStoreMessageHandlerFactoryBean}. * * @param element The element. * @param parserContext The parser context. * @return The bean definition builder */ static BeanDefinitionBuilder configure(Element element, ParserContext parserContext) { BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(HdfsStoreMessageHandlerFactoryBean.class); IntegrationNamespaceUtils.setReferenceIfAttributeDefined( builder, element, "writer", "storeWriter"); IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "auto-startup"); return builder; }
@Override protected AbstractBeanDefinition doParse( Element element, ParserContext parserContext, String channelName) { BeanDefinitionBuilder builder = ReactorNamespaceUtils.createBeanDefinitionBuilder( SyslogInboundChannelAdapter.class, element); IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "host", "host"); IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "port", "port"); IntegrationNamespaceUtils.setReferenceIfAttributeDefined( builder, element, "channel", "outputChannel"); IntegrationNamespaceUtils.setReferenceIfAttributeDefined( builder, element, "error-channel", "errorChannel"); return builder.getBeanDefinition(); }
@Override protected BeanMetadataElement parseSource(Element element, ParserContext parserContext) { final BeanDefinitionBuilder jpaPollingChannelAdapterBuilder = BeanDefinitionBuilder.genericBeanDefinition(JpaPollingChannelAdapter.class); final BeanDefinitionBuilder jpaExecutorBuilder = JpaParserUtils.getJpaExecutorBuilder(element, parserContext); String maxNumberOfResults = element.getAttribute("max-number-of-results"); boolean hasMaxNumberOfResults = StringUtils.hasText(maxNumberOfResults); String maxResults = element.getAttribute("max-results"); boolean hasMaxResults = StringUtils.hasText(maxResults); if (hasMaxNumberOfResults) { parserContext .getReaderContext() .warning("'max-number-of-results' is deprecated in favor of 'max-results'", element); if (hasMaxResults) { parserContext .getReaderContext() .error("'max-number-of-results' and 'max-results' are mutually exclusive", element); } else { element.setAttribute("max-results", maxNumberOfResults); } } BeanDefinition definition = IntegrationNamespaceUtils.createExpressionDefinitionFromValueOrExpression( "max-results", "max-results-expression", parserContext, element, false); if (definition != null) { jpaExecutorBuilder.addPropertyValue("maxResultsExpression", definition); } IntegrationNamespaceUtils.setValueIfAttributeDefined( jpaExecutorBuilder, element, "delete-after-poll"); IntegrationNamespaceUtils.setValueIfAttributeDefined( jpaExecutorBuilder, element, "flush-after-delete", "flush"); IntegrationNamespaceUtils.setValueIfAttributeDefined( jpaExecutorBuilder, element, "delete-in-batch"); IntegrationNamespaceUtils.setValueIfAttributeDefined( jpaExecutorBuilder, element, "expect-single-result"); IntegrationNamespaceUtils.setReferenceIfAttributeDefined( jpaExecutorBuilder, element, "parameter-source"); final BeanDefinition jpaExecutorBuilderBeanDefinition = jpaExecutorBuilder.getBeanDefinition(); final String channelAdapterId = this.resolveId( element, jpaPollingChannelAdapterBuilder.getRawBeanDefinition(), parserContext); final String jpaExecutorBeanName = channelAdapterId + ".jpaExecutor"; parserContext.registerBeanComponent( new BeanComponentDefinition(jpaExecutorBuilderBeanDefinition, jpaExecutorBeanName)); jpaPollingChannelAdapterBuilder.addConstructorArgReference(jpaExecutorBeanName); return jpaPollingChannelAdapterBuilder.getBeanDefinition(); }
@Override protected BeanDefinitionBuilder buildBeanDefinition( Element element, ParserContext parserContext) { BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(AmqpChannelFactoryBean.class); String messageDriven = element.getAttribute("message-driven"); if (StringUtils.hasText(messageDriven)) { builder.addConstructorArgValue(messageDriven); } String connectionFactory = element.getAttribute("connection-factory"); if (!StringUtils.hasText(connectionFactory)) { connectionFactory = "rabbitConnectionFactory"; } builder.addPropertyReference("connectionFactory", connectionFactory); if ("channel".equals(element.getLocalName())) { builder.addPropertyValue("pubSub", false); } else if ("publish-subscribe-channel".equals(element.getLocalName())) { builder.addPropertyValue("pubSub", true); } IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "acknowledge-mode"); IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "advice-chain"); IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "amqp-admin"); IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "auto-startup"); IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "channel-transacted"); IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "concurrent-consumers"); IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "encoding"); IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "error-handler"); IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "exchange"); IntegrationNamespaceUtils.setValueIfAttributeDefined( builder, element, "expose-listener-channel"); IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "message-converter"); IntegrationNamespaceUtils.setReferenceIfAttributeDefined( builder, element, "message-properties-converter"); IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "phase"); IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "prefetch-count"); IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "queue-name"); IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "receive-timeout"); IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "recovery-interval"); IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "shutdown-timeout"); IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "task-executor"); IntegrationNamespaceUtils.setReferenceIfAttributeDefined( builder, element, "transaction-attribute"); IntegrationNamespaceUtils.setReferenceIfAttributeDefined( builder, element, "transaction-manager"); IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "tx-size"); return builder; }
@Override protected BeanDefinitionBuilder buildBeanDefinition( Element element, ParserContext parserContext) { BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(SubscribableRedisChannel.class); String connectionFactory = element.getAttribute("connection-factory"); if (!StringUtils.hasText(connectionFactory)) { connectionFactory = "redisConnectionFactory"; } builder.addConstructorArgReference(connectionFactory); String topicName = element.getAttribute("topic-name"); builder.addConstructorArgValue(topicName); IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "task-executor"); IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "message-converter"); IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "serializer"); // The following 2 attributes should be added once configurable on the // RedisMessageListenerContainer // IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "phase"); // IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "auto-startup"); return builder; }
/** Utility method to configure HeaderMapper for Inbound and Outbound channel adapters/gateway */ public static void configureHeaderMapper( Element element, BeanDefinitionBuilder rootBuilder, ParserContext parserContext, Class<?> headerMapperClass, String replyHeaderValue) { String defaultMappedReplyHeadersAttributeName = "mapped-reply-headers"; if (!StringUtils.hasText(replyHeaderValue)) { replyHeaderValue = defaultMappedReplyHeadersAttributeName; } boolean hasHeaderMapper = element.hasAttribute("header-mapper"); boolean hasMappedRequestHeaders = element.hasAttribute("mapped-request-headers"); boolean hasMappedReplyHeaders = element.hasAttribute(replyHeaderValue); if (hasHeaderMapper && (hasMappedRequestHeaders || hasMappedReplyHeaders)) { parserContext .getReaderContext() .error( "The 'header-mapper' attribute is mutually exclusive with" + " 'mapped-request-headers' or 'mapped-reply-headers'. " + "You can only use one or the others", element); } IntegrationNamespaceUtils.setReferenceIfAttributeDefined(rootBuilder, element, "header-mapper"); if (hasMappedRequestHeaders || hasMappedReplyHeaders) { BeanDefinitionBuilder headerMapperBuilder = BeanDefinitionBuilder.genericBeanDefinition(headerMapperClass); if (hasMappedRequestHeaders) { headerMapperBuilder.addPropertyValue( "requestHeaderNames", element.getAttribute("mapped-request-headers")); } if (hasMappedReplyHeaders) { headerMapperBuilder.addPropertyValue( "replyHeaderNames", element.getAttribute(replyHeaderValue)); } rootBuilder.addPropertyValue("headerMapper", headerMapperBuilder.getBeanDefinition()); } }
/** * Configures the provided bean definition builder with a property reference to a bean. The bean * reference is identified by the value from the attribute whose name is provided if that * attribute is defined in the given element. * * <p>The property name will be the camel-case equivalent of the lower case hyphen separated * attribute (e.g. the "foo-bar" attribute would match the "fooBar" property). * * @see Conventions#attributeNameToPropertyName(String) * @param builder the bean definition builder to be configured * @param element - the XML element where the attribute should be defined * @param attributeName - the name of the attribute whose value will be used as a bean reference * to populate the property * @see Conventions#attributeNameToPropertyName(String) */ public static void setReferenceIfAttributeDefined( BeanDefinitionBuilder builder, Element element, String attributeName) { setReferenceIfAttributeDefined( builder, element, attributeName, Conventions.attributeNameToPropertyName(attributeName)); }