Skip to content

Commit 90f26e3

Browse files
committed
chore: fix platform-http failures with Spring Boot 3.5.14
1 parent c2b62b5 commit 90f26e3

19 files changed

Lines changed: 108 additions & 97 deletions

components-starter/camel-platform-http-starter/src/main/java/org/apache/camel/component/platform/http/springboot/SpringBootPlatformHttpAutoConfiguration.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@
2222
import org.apache.camel.spring.boot.ComponentConfigurationProperties;
2323
import org.slf4j.Logger;
2424
import org.slf4j.LoggerFactory;
25+
import org.springframework.beans.factory.ObjectProvider;
2526
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
2627
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
2728
import org.springframework.boot.autoconfigure.web.servlet.WebMvcProperties;
2829
import org.springframework.boot.context.properties.EnableConfigurationProperties;
2930
import org.springframework.context.annotation.Bean;
3031
import org.springframework.context.annotation.Configuration;
31-
import org.springframework.context.annotation.DependsOn;
3232
import org.springframework.core.env.Environment;
3333
import org.springframework.core.task.SimpleAsyncTaskExecutor;
3434
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
@@ -74,11 +74,11 @@ public PlatformHttpEngine springBootPlatformHttpEngine(Environment env, List<Exe
7474
}
7575

7676
@Bean
77-
@DependsOn("configurePlatformHttpComponent")
78-
public CamelRequestHandlerMapping platformHttpEngineRequestMapping(PlatformHttpEngine engine, CamelContext camelContext) {
77+
public CamelRequestHandlerMapping platformHttpEngineRequestMapping(
78+
PlatformHttpEngine engine, ObjectProvider<CamelContext> camelContextProvider) {
79+
CamelContext camelContext = camelContextProvider.getObject();
7980
PlatformHttpComponent component = camelContext.getComponent("platform-http", PlatformHttpComponent.class);
80-
CamelRequestHandlerMapping answer = new CamelRequestHandlerMapping(component, engine);
81-
return answer;
81+
return new CamelRequestHandlerMapping(component, engine);
8282
}
8383

8484
}

components-starter/camel-platform-http-starter/src/main/java/org/apache/camel/component/platform/http/springboot/SpringBootPlatformHttpConsumer.java

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
*/
1717
package org.apache.camel.component.platform.http.springboot;
1818

19-
import java.util.concurrent.CompletableFuture;
2019
import java.util.concurrent.Executor;
2120
import java.util.concurrent.Executors;
2221

@@ -40,8 +39,11 @@
4039
import org.apache.camel.support.DefaultConsumer;
4140
import org.slf4j.Logger;
4241
import org.slf4j.LoggerFactory;
42+
import org.springframework.core.task.AsyncTaskExecutor;
43+
import org.springframework.scheduling.concurrent.ConcurrentTaskExecutor;
4344
import org.springframework.web.bind.annotation.CookieValue;
4445
import org.springframework.web.bind.annotation.ResponseBody;
46+
import org.springframework.web.context.request.async.WebAsyncTask;
4547

4648
public class SpringBootPlatformHttpConsumer extends DefaultConsumer implements PlatformHttpConsumer, Suspendable, SuspendableService {
4749

@@ -84,13 +86,14 @@ public PlatformHttpEndpoint getEndpoint() {
8486
/**
8587
* This method is invoked by Spring Boot when invoking Camel via platform-http.
8688
*
87-
* The method is already running asynchronously via AsyncExecutionInterceptor.
88-
*
89-
* Returns an empty CompletableFuture as per documentation https://spring.io/guides/gs/async-method
89+
* Returns a WebAsyncTask to integrate with Spring MVC async lifecycle while preserving the custom executor.
9090
*/
9191
@ResponseBody
92-
public CompletableFuture<Void> service(HttpServletRequest request, HttpServletResponse response) {
93-
return CompletableFuture.runAsync(() -> {
92+
public WebAsyncTask<Void> service(HttpServletRequest request, HttpServletResponse response) {
93+
AsyncTaskExecutor asyncExecutor = (executor instanceof AsyncTaskExecutor ate)
94+
? ate
95+
: new ConcurrentTaskExecutor(executor);
96+
WebAsyncTask<Void> task = new WebAsyncTask<>(null, asyncExecutor, () -> {
9497
LOG.trace("Service: {}", request);
9598
try {
9699
handleService(request, response);
@@ -105,7 +108,15 @@ public CompletableFuture<Void> service(HttpServletRequest request, HttpServletRe
105108
// ignore
106109
}
107110
}
108-
}, executor);
111+
return null;
112+
});
113+
task.onTimeout(() -> {
114+
if (!response.isCommitted()) {
115+
response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
116+
}
117+
return null;
118+
});
119+
return task;
109120
}
110121

111122
protected void handleService(HttpServletRequest request, HttpServletResponse response) throws Exception {

components-starter/camel-platform-http-starter/src/test/java/org/apache/camel/component/platform/http/springboot/PlatformHttpBinaryUploadTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
import org.junit.jupiter.api.Test;
2727
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
2828
import org.springframework.boot.test.context.SpringBootTest;
29-
import org.springframework.boot.test.web.server.LocalServerPort;
29+
import org.springframework.beans.factory.annotation.Autowired;
30+
import org.springframework.core.env.Environment;
3031
import org.springframework.context.annotation.Bean;
3132
import org.springframework.context.annotation.Configuration;
3233
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
@@ -56,9 +57,8 @@ public class PlatformHttpBinaryUploadTest {
5657

5758
static final String FILE_NAME = "example.pdf";
5859
static Path uploadDir;
59-
60-
@LocalServerPort
61-
private int port;
60+
@Autowired
61+
private Environment environment;
6262

6363
@BeforeAll
6464
public static void createUploadDir() throws IOException {
@@ -73,7 +73,7 @@ public static void cleanUploadDir() throws IOException {
7373

7474
@BeforeEach
7575
public void setUp() {
76-
RestAssured.port = port;
76+
RestAssured.port = Integer.parseInt(environment.getRequiredProperty("local.server.port"));
7777
}
7878

7979
@Test

components-starter/camel-platform-http-starter/src/test/java/org/apache/camel/component/platform/http/springboot/PlatformHttpStreamingTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
import org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientAutoConfiguration;
2929
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
3030
import org.springframework.boot.test.context.SpringBootTest;
31-
import org.springframework.boot.test.web.server.LocalServerPort;
31+
import org.springframework.beans.factory.annotation.Autowired;
32+
import org.springframework.core.env.Environment;
3233
import org.springframework.context.annotation.Bean;
3334
import org.springframework.context.annotation.Configuration;
3435

@@ -52,13 +53,12 @@
5253
SpringBootPlatformHttpTest.class, PlatformHttpStreamingTest.TestConfiguration.class,
5354
PlatformHttpComponentAutoConfiguration.class, SpringBootPlatformHttpAutoConfiguration.class })
5455
public class PlatformHttpStreamingTest {
55-
56-
@LocalServerPort
57-
private int port;
56+
@Autowired
57+
private Environment environment;
5858

5959
@BeforeEach
6060
public void setUp() {
61-
RestAssured.port = port;
61+
RestAssured.port = Integer.parseInt(environment.getRequiredProperty("local.server.port"));
6262
}
6363

6464
@Test

components-starter/camel-platform-http-starter/src/test/java/org/apache/camel/component/platform/http/springboot/SpringBootPlatformHttpBridgedEndpointTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
import org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientAutoConfiguration;
3030
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
3131
import org.springframework.boot.test.context.SpringBootTest;
32-
import org.springframework.boot.test.web.server.LocalServerPort;
32+
import org.springframework.beans.factory.annotation.Autowired;
33+
import org.springframework.core.env.Environment;
3334
import org.springframework.context.annotation.Bean;
3435
import org.springframework.context.annotation.Configuration;
3536
import org.wiremock.spring.ConfigureWireMock;
@@ -46,9 +47,8 @@
4647
PlatformHttpComponentAutoConfiguration.class, SpringBootPlatformHttpAutoConfiguration.class, HttpComponentAutoConfiguration.class})
4748
@EnableWireMock(@ConfigureWireMock(portProperties = "customPort"))
4849
public class SpringBootPlatformHttpBridgedEndpointTest {
49-
50-
@LocalServerPort
51-
private Integer port;
50+
@Autowired
51+
private Environment environment;
5252

5353
@BeforeEach
5454
void setUp() {
@@ -83,7 +83,7 @@ public void configure() {
8383

8484
@Test
8585
public void bridgedEndpointTest() {
86-
final var proxyURI = "http://localhost:%s/mock".formatted(port);
86+
final var proxyURI = "http://localhost:%s/mock".formatted(Integer.parseInt(environment.getRequiredProperty("local.server.port")));
8787

8888
given()
8989
.contentType(ContentType.JSON)

components-starter/camel-platform-http-starter/src/test/java/org/apache/camel/component/platform/http/springboot/SpringBootPlatformHttpCamelIntegrationsTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
3131
import org.springframework.boot.test.context.SpringBootTest;
3232
import org.springframework.boot.test.web.client.TestRestTemplate;
33-
import org.springframework.boot.test.web.server.LocalServerPort;
33+
import org.springframework.beans.factory.annotation.Autowired;
34+
import org.springframework.core.env.Environment;
3435
import org.springframework.context.annotation.Bean;
3536
import org.springframework.context.annotation.Configuration;
3637

@@ -48,13 +49,12 @@ public class SpringBootPlatformHttpCamelIntegrationsTest {
4849

4950
@Autowired
5051
CamelContext camelContext;
51-
52-
@LocalServerPort
53-
private Integer port;
52+
@Autowired
53+
private Environment environment;
5454

5555
@BeforeEach
5656
void setUp() {
57-
RestAssured.port = port;
57+
RestAssured.port = Integer.parseInt(environment.getRequiredProperty("local.server.port"));
5858
}
5959

6060
@Configuration

components-starter/camel-platform-http-starter/src/test/java/org/apache/camel/component/platform/http/springboot/SpringBootPlatformHttpCertificationTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@
5454
import org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientAutoConfiguration;
5555
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
5656
import org.springframework.boot.test.context.SpringBootTest;
57-
import org.springframework.boot.test.web.server.LocalServerPort;
57+
import org.springframework.beans.factory.annotation.Autowired;
58+
import org.springframework.core.env.Environment;
5859
import org.springframework.context.annotation.Bean;
5960
import org.springframework.context.annotation.Configuration;
6061

@@ -73,13 +74,12 @@ public class SpringBootPlatformHttpCertificationTest extends PlatformHttpBase {
7374

7475
private static final String postRouteId = "SpringBootPlatformHttpRestDSLTest_mypost";
7576
private static final String getRouteId = "SpringBootPlatformHttpRestDSLTest_myget";
76-
77-
@LocalServerPort
78-
private Integer port;
77+
@Autowired
78+
private Environment environment;
7979

8080
@BeforeEach
8181
void setUp() {
82-
RestAssured.port = port;
82+
RestAssured.port = Integer.parseInt(environment.getRequiredProperty("local.server.port"));
8383
}
8484

8585
@Configuration

components-starter/camel-platform-http-starter/src/test/java/org/apache/camel/component/platform/http/springboot/SpringBootPlatformHttpCookiesTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@
3434
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
3535
import org.springframework.boot.test.context.SpringBootTest;
3636
import org.springframework.boot.test.web.client.TestRestTemplate;
37-
import org.springframework.boot.test.web.server.LocalServerPort;
37+
import org.springframework.beans.factory.annotation.Autowired;
38+
import org.springframework.core.env.Environment;
3839
import org.springframework.context.annotation.Bean;
3940
import org.springframework.context.annotation.Configuration;
4041

@@ -56,13 +57,12 @@ public class SpringBootPlatformHttpCookiesTest {
5657

5758
@Autowired
5859
CamelContext camelContext;
59-
60-
@LocalServerPort
61-
private Integer port;
60+
@Autowired
61+
private Environment environment;
6262

6363
@BeforeEach
6464
void setUp() {
65-
RestAssured.port = port;
65+
RestAssured.port = Integer.parseInt(environment.getRequiredProperty("local.server.port"));
6666
}
6767

6868
@Configuration

components-starter/camel-platform-http-starter/src/test/java/org/apache/camel/component/platform/http/springboot/SpringBootPlatformHttpCorsCredentialsTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
import org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientAutoConfiguration;
2828
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
2929
import org.springframework.boot.test.context.SpringBootTest;
30-
import org.springframework.boot.test.web.server.LocalServerPort;
30+
import org.springframework.beans.factory.annotation.Autowired;
31+
import org.springframework.core.env.Environment;
3132
import org.springframework.context.annotation.Bean;
3233
import org.springframework.context.annotation.Configuration;
3334

@@ -40,13 +41,12 @@
4041
SpringBootPlatformHttpCorsCredentialsTest.class, SpringBootPlatformHttpCorsCredentialsTest.TestConfiguration.class,
4142
PlatformHttpComponentAutoConfiguration.class, SpringBootPlatformHttpAutoConfiguration.class, })
4243
public class SpringBootPlatformHttpCorsCredentialsTest {
43-
44-
@LocalServerPort
45-
private Integer port;
44+
@Autowired
45+
private Environment environment;
4646

4747
@BeforeEach
4848
void setUp() {
49-
RestAssured.port = port;
49+
RestAssured.port = Integer.parseInt(environment.getRequiredProperty("local.server.port"));
5050
RestAssured.enableLoggingOfRequestAndResponseIfValidationFails();
5151
}
5252

components-starter/camel-platform-http-starter/src/test/java/org/apache/camel/component/platform/http/springboot/SpringBootPlatformHttpCorsTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
import org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientAutoConfiguration;
2828
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
2929
import org.springframework.boot.test.context.SpringBootTest;
30-
import org.springframework.boot.test.web.server.LocalServerPort;
30+
import org.springframework.beans.factory.annotation.Autowired;
31+
import org.springframework.core.env.Environment;
3132
import org.springframework.context.annotation.Bean;
3233
import org.springframework.context.annotation.Configuration;
3334

@@ -42,13 +43,12 @@
4243
SpringBootPlatformHttpCorsTest.class, SpringBootPlatformHttpCorsTest.TestConfiguration.class,
4344
PlatformHttpComponentAutoConfiguration.class, SpringBootPlatformHttpAutoConfiguration.class, })
4445
public class SpringBootPlatformHttpCorsTest {
45-
46-
@LocalServerPort
47-
private Integer port;
46+
@Autowired
47+
private Environment environment;
4848

4949
@BeforeEach
5050
void setUp() {
51-
RestAssured.port = port;
51+
RestAssured.port = Integer.parseInt(environment.getRequiredProperty("local.server.port"));
5252
RestAssured.enableLoggingOfRequestAndResponseIfValidationFails();
5353
}
5454

0 commit comments

Comments
 (0)