11/*
2- * Copyright 2002-2019 the original author or authors.
2+ * Copyright 2002-2020 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
@@ -84,18 +84,7 @@ protected String resolveId(Element element, AbstractBeanDefinition definition, P
8484 @ Override
8585 protected void doParse (Element element , ParserContext parserContext , BeanDefinitionBuilder builder ) {
8686 builder .addConstructorArgValue (this .expectReply );
87- String inputChannelAttributeName = this .getInputChannelAttributeName ();
88- String inputChannelRef = element .getAttribute (inputChannelAttributeName );
89- if (!StringUtils .hasText (inputChannelRef )) {
90- if (this .expectReply ) {
91- parserContext .getReaderContext ().error (
92- "a '" + inputChannelAttributeName + "' reference is required" , element );
93- }
94- else {
95- inputChannelRef = IntegrationNamespaceUtils .createDirectChannel (element , parserContext );
96- }
97- }
98- builder .addPropertyReference ("requestChannel" , inputChannelRef );
87+ parseInputChannel (element , parserContext , builder );
9988 IntegrationNamespaceUtils .setReferenceIfAttributeDefined (builder , element , "error-channel" );
10089
10190 BeanDefinition payloadExpressionDef =
@@ -104,22 +93,7 @@ protected void doParse(Element element, ParserContext parserContext, BeanDefinit
10493 builder .addPropertyValue ("payloadExpression" , payloadExpressionDef );
10594 }
10695
107- List <Element > headerElements = DomUtils .getChildElementsByTagName (element , "header" );
108-
109- if (!CollectionUtils .isEmpty (headerElements )) {
110- ManagedMap <String , Object > headerElementsMap = new ManagedMap <>();
111- for (Element headerElement : headerElements ) {
112- String name = headerElement .getAttribute (NAME_ATTRIBUTE );
113- BeanDefinition headerExpressionDef =
114- IntegrationNamespaceUtils
115- .createExpressionDefIfAttributeDefined (IntegrationNamespaceUtils .EXPRESSION_ATTRIBUTE ,
116- headerElement );
117- if (headerExpressionDef != null ) {
118- headerElementsMap .put (name , headerExpressionDef );
119- }
120- }
121- builder .addPropertyValue ("headerExpressions" , headerElementsMap );
122- }
96+ parseHeaders (element , builder );
12397
12498 if (this .expectReply ) {
12599 IntegrationNamespaceUtils .setReferenceIfAttributeDefined (builder , element , "reply-channel" );
@@ -145,19 +119,84 @@ protected void doParse(Element element, ParserContext parserContext, BeanDefinit
145119 IntegrationNamespaceUtils .setReferenceIfAttributeDefined (builder , element , "message-converters" );
146120 IntegrationNamespaceUtils .setValueIfAttributeDefined (builder , element , "merge-with-default-converters" );
147121
148- String headerMapper = element .getAttribute ("header-mapper" );
149122
123+ parseHeaderMapper (element , parserContext , builder );
124+
125+ BeanDefinition requestMappingDef = createRequestMapping (element );
126+ builder .addPropertyValue ("requestMapping" , requestMappingDef );
127+
128+
129+ parseCrossOrigin (element , builder );
130+
131+ IntegrationNamespaceUtils .setValueIfAttributeDefined (builder , element ,
132+ "request-payload-type" , "requestPayloadTypeClass" );
133+
134+ BeanDefinition statusCodeExpressionDef =
135+ IntegrationNamespaceUtils .createExpressionDefIfAttributeDefined ("status-code-expression" , element );
136+ if (statusCodeExpressionDef == null ) {
137+ statusCodeExpressionDef = IntegrationNamespaceUtils
138+ .createExpressionDefIfAttributeDefined ("reply-timeout-status-code-expression" , element );
139+ }
140+ if (statusCodeExpressionDef != null ) {
141+ builder .addPropertyValue ("statusCodeExpression" , statusCodeExpressionDef );
142+ }
143+
144+ IntegrationNamespaceUtils .setValueIfAttributeDefined (builder , element , IntegrationNamespaceUtils .AUTO_STARTUP );
145+ IntegrationNamespaceUtils .setValueIfAttributeDefined (builder , element , IntegrationNamespaceUtils .PHASE );
146+ IntegrationNamespaceUtils .setReferenceIfAttributeDefined (builder , element , "validator" );
147+ }
148+
149+ private void parseInputChannel (Element element , ParserContext parserContext , BeanDefinitionBuilder builder ) {
150+ String inputChannelAttributeName = this .getInputChannelAttributeName ();
151+ String inputChannelRef = element .getAttribute (inputChannelAttributeName );
152+ if (!StringUtils .hasText (inputChannelRef )) {
153+ if (this .expectReply ) {
154+ parserContext .getReaderContext ().error (
155+ "a '" + inputChannelAttributeName + "' reference is required" , element );
156+ }
157+ else {
158+ inputChannelRef = IntegrationNamespaceUtils .createDirectChannel (element , parserContext );
159+ }
160+ }
161+ builder .addPropertyReference ("requestChannel" , inputChannelRef );
162+ }
163+
164+ private String getInputChannelAttributeName () {
165+ return this .expectReply ? "request-channel" : "channel" ;
166+ }
167+
168+ private void parseHeaders (Element element , BeanDefinitionBuilder builder ) {
169+ List <Element > headerElements = DomUtils .getChildElementsByTagName (element , "header" );
170+
171+ if (!CollectionUtils .isEmpty (headerElements )) {
172+ ManagedMap <String , Object > headerElementsMap = new ManagedMap <>();
173+ for (Element headerElement : headerElements ) {
174+ String name = headerElement .getAttribute (NAME_ATTRIBUTE );
175+ BeanDefinition headerExpressionDef =
176+ IntegrationNamespaceUtils
177+ .createExpressionDefIfAttributeDefined (IntegrationNamespaceUtils .EXPRESSION_ATTRIBUTE ,
178+ headerElement );
179+ if (headerExpressionDef != null ) {
180+ headerElementsMap .put (name , headerExpressionDef );
181+ }
182+ }
183+ builder .addPropertyValue ("headerExpressions" , headerElementsMap );
184+ }
185+ }
186+
187+ private void parseHeaderMapper (Element element , ParserContext parserContext , BeanDefinitionBuilder builder ) {
150188 String mappedRequestHeaders = element .getAttribute ("mapped-request-headers" );
151189 String mappedResponseHeaders = element .getAttribute ("mapped-response-headers" );
152190
153191 boolean hasMappedRequestHeaders = StringUtils .hasText (mappedRequestHeaders );
154192 boolean hasMappedResponseHeaders = StringUtils .hasText (mappedResponseHeaders );
155193
194+ String headerMapper = element .getAttribute ("header-mapper" );
156195 if (StringUtils .hasText (headerMapper )) {
157196 if (hasMappedRequestHeaders || hasMappedResponseHeaders ) {
158197 parserContext .getReaderContext ()
159198 .error ("Neither 'mapped-request-headers' or 'mapped-response-headers' " +
160- "attributes are allowed when a 'header-mapper' has been specified." ,
199+ "attributes are allowed when a 'header-mapper' has been specified." ,
161200 parserContext .extractSource (element ));
162201 }
163202 builder .addPropertyReference ("headerMapper" , headerMapper );
@@ -176,11 +215,9 @@ protected void doParse(Element element, ParserContext parserContext, BeanDefinit
176215
177216 builder .addPropertyValue ("headerMapper" , headerMapperBuilder .getBeanDefinition ());
178217 }
218+ }
179219
180- BeanDefinition requestMappingDef = createRequestMapping (element );
181- builder .addPropertyValue ("requestMapping" , requestMappingDef );
182-
183-
220+ private void parseCrossOrigin (Element element , BeanDefinitionBuilder builder ) {
184221 Element crossOriginElement = DomUtils .getChildElementByTagName (element , "cross-origin" );
185222 if (crossOriginElement != null ) {
186223 BeanDefinitionBuilder crossOriginBuilder =
@@ -194,27 +231,6 @@ protected void doParse(Element element, ParserContext parserContext, BeanDefinit
194231 "allow-credentials" , true );
195232 builder .addPropertyValue ("crossOrigin" , crossOriginBuilder .getBeanDefinition ());
196233 }
197-
198- IntegrationNamespaceUtils .setValueIfAttributeDefined (builder , element ,
199- "request-payload-type" , "requestPayloadTypeClass" );
200-
201- BeanDefinition statusCodeExpressionDef =
202- IntegrationNamespaceUtils .createExpressionDefIfAttributeDefined ("status-code-expression" , element );
203- if (statusCodeExpressionDef == null ) {
204- statusCodeExpressionDef = IntegrationNamespaceUtils
205- .createExpressionDefIfAttributeDefined ("reply-timeout-status-code-expression" , element );
206- }
207- if (statusCodeExpressionDef != null ) {
208- builder .addPropertyValue ("statusCodeExpression" , statusCodeExpressionDef );
209- }
210-
211- IntegrationNamespaceUtils .setValueIfAttributeDefined (builder , element , IntegrationNamespaceUtils .AUTO_STARTUP );
212- IntegrationNamespaceUtils .setValueIfAttributeDefined (builder , element , IntegrationNamespaceUtils .PHASE );
213- IntegrationNamespaceUtils .setReferenceIfAttributeDefined (builder , element , "validator" );
214- }
215-
216- private String getInputChannelAttributeName () {
217- return this .expectReply ? "request-channel" : "channel" ;
218234 }
219235
220236 private BeanDefinition createRequestMapping (Element element ) {
@@ -231,7 +247,7 @@ private BeanDefinition createRequestMapping(Element element) {
231247 Element requestMappingElement = DomUtils .getChildElementByTagName (element , "request-mapping" );
232248
233249 if (requestMappingElement != null ) {
234- for (String requestMappingAttribute : new String [] { "params" , "headers" , "consumes" , "produces" }) {
250+ for (String requestMappingAttribute : new String []{ "params" , "headers" , "consumes" , "produces" }) {
235251 IntegrationNamespaceUtils .setValueIfAttributeDefined (requestMappingDefBuilder , requestMappingElement ,
236252 requestMappingAttribute );
237253 }
0 commit comments