} with 'id'
* {@link HttpContextUtils#HANDLER_MAPPING_BEAN_NAME}.
- *
- * In addition, checks if the {@code javax.servlet.Servlet} class is present on the classpath.
+ *
In addition, checks if the {@code javax.servlet.Servlet} class is present on the classpath.
* When Spring Integration HTTP is used only as an HTTP client, there is no reason to use and register
* the HTTP server components.
*/
@@ -64,9 +62,14 @@ public class HttpIntegrationConfigurationInitializer implements IntegrationConfi
if (HttpContextUtils.WEB_MVC_PRESENT &&
!registry.containsBeanDefinition(HttpContextUtils.HANDLER_MAPPING_BEAN_NAME)) {
BeanDefinitionBuilder requestMappingBuilder =
- BeanDefinitionBuilder.genericBeanDefinition(IntegrationRequestMappingHandlerMapping.class);
+ BeanDefinitionBuilder.genericBeanDefinition(IntegrationRequestMappingHandlerMapping.class,
+ () -> {
+ IntegrationRequestMappingHandlerMapping mapping =
+ new IntegrationRequestMappingHandlerMapping();
+ mapping.setOrder(0);
+ return mapping;
+ });
requestMappingBuilder.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
- requestMappingBuilder.addPropertyValue(IntegrationNamespaceUtils.ORDER, 0);
registry.registerBeanDefinition(HttpContextUtils.HANDLER_MAPPING_BEAN_NAME,
requestMappingBuilder.getBeanDefinition());
}
diff --git a/spring-integration-http/src/main/java/org/springframework/integration/http/config/IntegrationGraphControllerRegistrar.java b/spring-integration-http/src/main/java/org/springframework/integration/http/config/IntegrationGraphControllerRegistrar.java
index 918cffba85..55f860df13 100644
--- a/spring-integration-http/src/main/java/org/springframework/integration/http/config/IntegrationGraphControllerRegistrar.java
+++ b/spring-integration-http/src/main/java/org/springframework/integration/http/config/IntegrationGraphControllerRegistrar.java
@@ -32,6 +32,7 @@ import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionReaderUtils;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
+import org.springframework.beans.factory.support.GenericBeanDefinition;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.EnvironmentAware;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
@@ -43,8 +44,6 @@ import org.springframework.core.type.AnnotationMetadata;
import org.springframework.integration.context.IntegrationContextUtils;
import org.springframework.integration.graph.IntegrationGraphServer;
import org.springframework.integration.http.management.IntegrationGraphController;
-import org.springframework.web.servlet.config.annotation.CorsRegistry;
-import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/**
* Registers the necessary beans for {@link EnableIntegrationGraphController}.
@@ -54,7 +53,7 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
*
* @since 4.3
*/
-class IntegrationGraphControllerRegistrar implements ImportBeanDefinitionRegistrar {
+public class IntegrationGraphControllerRegistrar implements ImportBeanDefinitionRegistrar {
private static final Log LOGGER = LogFactory.getLog(IntegrationGraphControllerRegistrar.class);
@@ -81,10 +80,21 @@ class IntegrationGraphControllerRegistrar implements ImportBeanDefinitionRegistr
String path = (String) annotationAttributes.get("value");
String[] allowedOrigins = (String[]) annotationAttributes.get("allowedOrigins");
if (allowedOrigins != null && allowedOrigins.length > 0) {
- AbstractBeanDefinition controllerCorsConfigurer =
- new RootBeanDefinition(IntegrationGraphCorsConfigurer.class,
- () -> new IntegrationGraphCorsConfigurer(path, allowedOrigins));
- BeanDefinitionReaderUtils.registerWithGeneratedName(controllerCorsConfigurer, registry);
+ AbstractBeanDefinition controllerCorsConfigurer = null;
+ if (HttpContextUtils.WEB_MVC_PRESENT) {
+ controllerCorsConfigurer = webMvcControllerCorsConfigurerBean(path, allowedOrigins);
+ }
+ else if (HttpContextUtils.WEB_FLUX_PRESENT) {
+ controllerCorsConfigurer = webFluxControllerCorsConfigurerBean(path, allowedOrigins);
+ }
+
+ if (controllerCorsConfigurer != null) {
+ BeanDefinitionReaderUtils.registerWithGeneratedName(controllerCorsConfigurer, registry);
+ }
+ else {
+ LOGGER.warn("Nor Spring MVC, neither WebFlux is present to configure CORS origins " +
+ "for Integration Graph Controller.");
+ }
}
if (!registry.containsBeanDefinition(HttpContextUtils.GRAPH_CONTROLLER_BEAN_NAME)) {
@@ -107,7 +117,22 @@ class IntegrationGraphControllerRegistrar implements ImportBeanDefinitionRegistr
}
}
- private static final class GraphControllerPropertiesPopulator implements BeanFactoryPostProcessor, EnvironmentAware {
+ private static AbstractBeanDefinition webMvcControllerCorsConfigurerBean(String path, String[] allowedOrigins) {
+ GenericBeanDefinition beanDefinition = new GenericBeanDefinition();
+ beanDefinition.setBeanClass(WebMvcIntegrationGraphCorsConfigurer.class);
+ beanDefinition.setInstanceSupplier(() -> new WebMvcIntegrationGraphCorsConfigurer(path, allowedOrigins));
+ return beanDefinition;
+ }
+
+ private static AbstractBeanDefinition webFluxControllerCorsConfigurerBean(String path, String[] allowedOrigins) {
+ GenericBeanDefinition beanDefinition = new GenericBeanDefinition();
+ beanDefinition.setBeanClass(WebFluxIntegrationGraphCorsConfigurer.class);
+ beanDefinition.setInstanceSupplier(() -> new WebFluxIntegrationGraphCorsConfigurer(path, allowedOrigins));
+ return beanDefinition;
+ }
+
+ private static final class GraphControllerPropertiesPopulator
+ implements BeanFactoryPostProcessor, EnvironmentAware {
private final Map properties = new HashMap<>();
@@ -131,22 +156,4 @@ class IntegrationGraphControllerRegistrar implements ImportBeanDefinitionRegistr
}
- private static final class IntegrationGraphCorsConfigurer implements WebMvcConfigurer {
-
- private final String path;
-
- private final String[] allowedOrigins;
-
- private IntegrationGraphCorsConfigurer(String path, String[] allowedOrigins) { // NOSONAR
- this.path = path;
- this.allowedOrigins = allowedOrigins;
- }
-
- @Override
- public void addCorsMappings(CorsRegistry registry) {
- registry.addMapping(this.path).allowedOrigins(this.allowedOrigins).allowedMethods("GET");
- }
-
- }
-
}
diff --git a/spring-integration-http/src/main/java/org/springframework/integration/http/config/WebFluxIntegrationGraphCorsConfigurer.java b/spring-integration-http/src/main/java/org/springframework/integration/http/config/WebFluxIntegrationGraphCorsConfigurer.java
new file mode 100644
index 0000000000..66dd006f2e
--- /dev/null
+++ b/spring-integration-http/src/main/java/org/springframework/integration/http/config/WebFluxIntegrationGraphCorsConfigurer.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2021 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.integration.http.config;
+
+import org.springframework.web.reactive.config.CorsRegistry;
+import org.springframework.web.reactive.config.WebFluxConfigurer;
+
+/**
+ * The {@link WebFluxConfigurer} implementation for CORS mapping on the Integration Graph Controller.
+ *
+ * @author Artem Bilan
+ *
+ * @since 5.3.9
+ *
+ * @see EnableIntegrationGraphController
+ */
+final class WebFluxIntegrationGraphCorsConfigurer implements WebFluxConfigurer {
+
+ private final String path;
+
+ private final String[] allowedOrigins;
+
+ WebFluxIntegrationGraphCorsConfigurer(String path, String[] allowedOrigins) { // NOSONAR
+ this.path = path;
+ this.allowedOrigins = allowedOrigins;
+ }
+
+ @Override
+ public void addCorsMappings(CorsRegistry registry) {
+ registry.addMapping(this.path).allowedOrigins(this.allowedOrigins).allowedMethods("GET");
+ }
+
+}
diff --git a/spring-integration-http/src/main/java/org/springframework/integration/http/config/WebMvcIntegrationGraphCorsConfigurer.java b/spring-integration-http/src/main/java/org/springframework/integration/http/config/WebMvcIntegrationGraphCorsConfigurer.java
new file mode 100644
index 0000000000..611fbca388
--- /dev/null
+++ b/spring-integration-http/src/main/java/org/springframework/integration/http/config/WebMvcIntegrationGraphCorsConfigurer.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2021 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.integration.http.config;
+
+import org.springframework.web.reactive.config.WebFluxConfigurer;
+import org.springframework.web.servlet.config.annotation.CorsRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
+
+/**
+ * The {@link WebMvcConfigurer} implementation for CORS mapping on the Integration Graph Controller.
+ *
+ * @author Artem Bilan
+ *
+ * @since 5.3.9
+ *
+ * @see EnableIntegrationGraphController
+ */
+final class WebMvcIntegrationGraphCorsConfigurer implements WebMvcConfigurer {
+
+ private final String path;
+
+ private final String[] allowedOrigins;
+
+ WebMvcIntegrationGraphCorsConfigurer(String path, String[] allowedOrigins) { // NOSONAR
+ this.path = path;
+ this.allowedOrigins = allowedOrigins;
+ }
+
+ @Override
+ public void addCorsMappings(CorsRegistry registry) {
+ registry.addMapping(this.path).allowedOrigins(this.allowedOrigins).allowedMethods("GET");
+ }
+
+}
diff --git a/spring-integration-webflux/src/main/java/org/springframework/integration/webflux/config/WebFluxIntegrationConfigurationInitializer.java b/spring-integration-webflux/src/main/java/org/springframework/integration/webflux/config/WebFluxIntegrationConfigurationInitializer.java
index 6ee38d87cc..6046e0d7d8 100644
--- a/spring-integration-webflux/src/main/java/org/springframework/integration/webflux/config/WebFluxIntegrationConfigurationInitializer.java
+++ b/spring-integration-webflux/src/main/java/org/springframework/integration/webflux/config/WebFluxIntegrationConfigurationInitializer.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2017-2020 the original author or authors.
+ * Copyright 2017-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,7 +27,6 @@ import org.springframework.beans.factory.support.BeanDefinitionReaderUtils;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.integration.config.IntegrationConfigurationInitializer;
-import org.springframework.integration.config.xml.IntegrationNamespaceUtils;
import org.springframework.integration.http.config.HttpContextUtils;
import org.springframework.integration.webflux.inbound.IntegrationHandlerResultHandler;
import org.springframework.integration.webflux.inbound.WebFluxIntegrationRequestMappingHandlerMapping;
@@ -69,15 +68,22 @@ public class WebFluxIntegrationConfigurationInitializer implements IntegrationCo
private void registerReactiveRequestMappingHandlerMappingIfNecessary(BeanDefinitionRegistry registry) {
if (HttpContextUtils.WEB_FLUX_PRESENT &&
!registry.containsBeanDefinition(WebFluxContextUtils.HANDLER_MAPPING_BEAN_NAME)) {
+
BeanDefinitionBuilder requestMappingBuilder =
- BeanDefinitionBuilder.genericBeanDefinition(WebFluxIntegrationRequestMappingHandlerMapping.class);
+ BeanDefinitionBuilder.genericBeanDefinition(WebFluxIntegrationRequestMappingHandlerMapping.class,
+ () -> {
+ WebFluxIntegrationRequestMappingHandlerMapping mapping =
+ new WebFluxIntegrationRequestMappingHandlerMapping();
+ mapping.setOrder(0);
+ return mapping;
+ });
requestMappingBuilder.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
- requestMappingBuilder.addPropertyValue(IntegrationNamespaceUtils.ORDER, 0);
registry.registerBeanDefinition(WebFluxContextUtils.HANDLER_MAPPING_BEAN_NAME,
requestMappingBuilder.getBeanDefinition());
BeanDefinitionReaderUtils.registerWithGeneratedName(
- new RootBeanDefinition(IntegrationHandlerResultHandler.class), registry);
+ new RootBeanDefinition(IntegrationHandlerResultHandler.class, IntegrationHandlerResultHandler::new),
+ registry);
}
}