This is an automated email from the ASF dual-hosted git repository.
Croway pushed a commit to branch camel-spring-boot-4.22.x
in repository https://gitbox.apache.org/repos/asf/camel-spring-boot.git
The following commit(s) were added to refs/heads/camel-spring-boot-4.22.x by
this push:
new 04d6a70f957 CAMEL-25086: camel-platform-http-starter - start outside a
servlet web application
04d6a70f957 is described below
commit 04d6a70f957e3b1f8688906d26944a77ac35bb66
Author: Henrik Brautaset Aronsen <[email protected]>
AuthorDate: Mon Sep 28 11:27:13 2026 +0200
CAMEL-25086: camel-platform-http-starter - start outside a servlet web
application
(cherry picked from commit f4b79cf83d7872cca8e3305458a96f394593b85c)
---
.../SpringBootPlatformHttpAutoConfiguration.java | 7 +-
.../SpringBootPlatformWebMvcConfiguration.java | 19 ++++--
.../SpringBootPlatformHttpNonWebContextTest.java | 79 ++++++++++++++++++++++
3 files changed, 96 insertions(+), 9 deletions(-)
diff --git
a/components-starter/camel-platform-http-starter/src/main/java/org/apache/camel/component/platform/http/springboot/SpringBootPlatformHttpAutoConfiguration.java
b/components-starter/camel-platform-http-starter/src/main/java/org/apache/camel/component/platform/http/springboot/SpringBootPlatformHttpAutoConfiguration.java
index d65511a6ad5..7a96e3aff41 100644
---
a/components-starter/camel-platform-http-starter/src/main/java/org/apache/camel/component/platform/http/springboot/SpringBootPlatformHttpAutoConfiguration.java
+++
b/components-starter/camel-platform-http-starter/src/main/java/org/apache/camel/component/platform/http/springboot/SpringBootPlatformHttpAutoConfiguration.java
@@ -44,7 +44,7 @@ public class SpringBootPlatformHttpAutoConfiguration {
@Bean(name = "platform-http-engine")
@ConditionalOnMissingBean(PlatformHttpEngine.class)
- public PlatformHttpEngine springBootPlatformHttpEngine(Environment env,
ServerProperties serverProperties,
+ public PlatformHttpEngine springBootPlatformHttpEngine(Environment env,
ObjectProvider<ServerProperties> serverProperties,
List<Executor>
executors,
SpringBootPlatformHttpServerProperties serverHttpProperties) {
if (executors == null || executors.isEmpty()) {
@@ -88,7 +88,10 @@ public class SpringBootPlatformHttpAutoConfiguration {
} else {
LOG.debug("Using executor: {}", executor.getClass().getName());
}
- int port = serverProperties.getPort() != null ?
serverProperties.getPort() : 8080;
+ // ServerProperties is only registered in a servlet web application
+ ServerProperties server = serverProperties.getIfAvailable();
+ int port = server != null && server.getPort() != null
+ ? server.getPort() : env.getProperty("server.port",
Integer.class, 8080);
return new SpringBootPlatformHttpEngine(port, executor,
serverHttpProperties.isDeleteUploadedFilesOnEnd());
}
diff --git
a/components-starter/camel-platform-http-starter/src/main/java/org/apache/camel/component/platform/http/springboot/SpringBootPlatformWebMvcConfiguration.java
b/components-starter/camel-platform-http-starter/src/main/java/org/apache/camel/component/platform/http/springboot/SpringBootPlatformWebMvcConfiguration.java
index 9628efe22d9..01bd8bf4359 100644
---
a/components-starter/camel-platform-http-starter/src/main/java/org/apache/camel/component/platform/http/springboot/SpringBootPlatformWebMvcConfiguration.java
+++
b/components-starter/camel-platform-http-starter/src/main/java/org/apache/camel/component/platform/http/springboot/SpringBootPlatformWebMvcConfiguration.java
@@ -16,7 +16,10 @@
*/
package org.apache.camel.component.platform.http.springboot;
+import java.time.Duration;
+
import org.apache.camel.spring.boot.ComponentConfigurationProperties;
+import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import
org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.webmvc.autoconfigure.WebMvcProperties;
@@ -28,24 +31,26 @@ import
org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
public class SpringBootPlatformWebMvcConfiguration implements WebMvcConfigurer
{
private final PlatformHttpComponentConfiguration
platformHttpComponentConfiguration;
- private final WebMvcProperties webMvcProperties;
+ private final ObjectProvider<WebMvcProperties> webMvcProperties;
+ // WebMvcProperties is only registered in a servlet web application
public
SpringBootPlatformWebMvcConfiguration(PlatformHttpComponentConfiguration
platformHttpComponentConfiguration,
- WebMvcProperties
webMvcProperties) {
+
ObjectProvider<WebMvcProperties> webMvcProperties) {
this.platformHttpComponentConfiguration =
platformHttpComponentConfiguration;
this.webMvcProperties = webMvcProperties;
}
@Override
public void configureAsyncSupport(AsyncSupportConfigurer configurer) {
- if (webMvcProperties.getAsync().getRequestTimeout() == null &&
- platformHttpComponentConfiguration.getRequestTimeout() !=
null) {
+ WebMvcProperties properties = webMvcProperties.getIfAvailable();
+ Duration requestTimeout = properties != null ?
properties.getAsync().getRequestTimeout() : null;
+
+ if (requestTimeout == null &&
platformHttpComponentConfiguration.getRequestTimeout() != null) {
configurer.setDefaultTimeout(platformHttpComponentConfiguration.getRequestTimeout());
}
- if (webMvcProperties.getAsync().getRequestTimeout() != null &&
- platformHttpComponentConfiguration.getRequestTimeout() ==
null) {
-
platformHttpComponentConfiguration.setRequestTimeout(webMvcProperties.getAsync().getRequestTimeout().toMillis());
+ if (requestTimeout != null &&
platformHttpComponentConfiguration.getRequestTimeout() == null) {
+
platformHttpComponentConfiguration.setRequestTimeout(requestTimeout.toMillis());
}
}
}
diff --git
a/components-starter/camel-platform-http-starter/src/test/java/org/apache/camel/component/platform/http/springboot/SpringBootPlatformHttpNonWebContextTest.java
b/components-starter/camel-platform-http-starter/src/test/java/org/apache/camel/component/platform/http/springboot/SpringBootPlatformHttpNonWebContextTest.java
new file mode 100644
index 00000000000..ad4a8894f35
--- /dev/null
+++
b/components-starter/camel-platform-http-starter/src/test/java/org/apache/camel/component/platform/http/springboot/SpringBootPlatformHttpNonWebContextTest.java
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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
+ *
+ * http://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.apache.camel.component.platform.http.springboot;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.ServiceStatus;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.platform.http.spi.PlatformHttpEngine;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+import org.junit.jupiter.api.Test;
+import org.springframework.boot.autoconfigure.AutoConfigurations;
+import
org.springframework.boot.autoconfigure.task.TaskExecutionAutoConfiguration;
+import org.springframework.boot.test.context.runner.ApplicationContextRunner;
+import org.springframework.boot.web.server.autoconfigure.ServerProperties;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * The starter must start outside a servlet web application, where Spring Boot
registers neither
+ * {@link ServerProperties} nor {@code WebMvcProperties}, for example {@code
@SpringBootTest(webEnvironment = NONE)}.
+ */
+public class SpringBootPlatformHttpNonWebContextTest {
+
+ private final ApplicationContextRunner runner = new
ApplicationContextRunner()
+
.withConfiguration(AutoConfigurations.of(CamelAutoConfiguration.class,
TaskExecutionAutoConfiguration.class,
+ PlatformHttpComponentAutoConfiguration.class,
PlatformHttpComponentConverter.class,
+ SpringBootPlatformHttpAutoConfiguration.class,
SpringBootPlatformWebMvcConfiguration.class))
+ .withBean(RouteBuilder.class, () -> new RouteBuilder() {
+ @Override
+ public void configure() {
+
from("platform-http:/hello").routeId("hello").setBody().constant("hello");
+ }
+ });
+
+ @Test
+ void startsWithoutServerProperties() {
+ runner.withPropertyValues("server.port=12345").run(context -> {
+ assertThat(context).hasNotFailed();
+
assertThat(context.getBean(CamelContext.class).getRouteController().getRouteStatus("hello"))
+ .isEqualTo(ServiceStatus.Started);
+ assertThat(((SpringBootPlatformHttpEngine)
context.getBean(PlatformHttpEngine.class)).getServerPort())
+ .isEqualTo(12345);
+ });
+ }
+
+ @Test
+ void defaultsToPort8080() {
+ runner.run(context -> {
+ assertThat(context).hasNotFailed();
+ assertThat(((SpringBootPlatformHttpEngine)
context.getBean(PlatformHttpEngine.class)).getServerPort())
+ .isEqualTo(8080);
+ });
+ }
+
+ @Test
+ void serverPropertiesPortWins() {
+ ServerProperties serverProperties = new ServerProperties();
+ serverProperties.setPort(23456);
+ runner.withBean(ServerProperties.class, () ->
serverProperties).run(context -> {
+ assertThat(context).hasNotFailed();
+ assertThat(((SpringBootPlatformHttpEngine)
context.getBean(PlatformHttpEngine.class)).getServerPort())
+ .isEqualTo(23456);
+ });
+ }
+}