Skip to content

Commit acb8ae1

Browse files
committed
Handle Spring Security Async Proxy
1 parent 28a327f commit acb8ae1

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

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

+21-12
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
import org.apache.camel.CamelContext;
2020
import org.apache.camel.component.platform.http.PlatformHttpComponent;
2121
import org.apache.camel.component.platform.http.spi.PlatformHttpEngine;
22-
import org.springframework.beans.factory.annotation.Autowired;
22+
import org.slf4j.Logger;
23+
import org.slf4j.LoggerFactory;
2324
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
2425
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
2526
import org.springframework.context.annotation.Bean;
@@ -36,33 +37,41 @@
3637
@AutoConfigureAfter(name = { "org.apache.camel.component.servlet.springboot.PlatformHttpComponentAutoConfiguration",
3738
"org.apache.camel.component.servlet.springboot.PlatformHttpComponentConverter" })
3839
public class SpringBootPlatformHttpAutoConfiguration {
39-
40-
@Autowired
41-
CamelContext camelContext;
42-
43-
@Autowired
44-
List<Executor> executors;
40+
private static final Logger LOG = LoggerFactory.getLogger(SpringBootPlatformHttpAutoConfiguration.class);
4541

4642
@Bean(name = "platform-http-engine")
4743
@ConditionalOnMissingBean(PlatformHttpEngine.class)
48-
public PlatformHttpEngine springBootPlatformHttpEngine(Environment env) {
44+
public PlatformHttpEngine springBootPlatformHttpEngine(Environment env, List<Executor> executors) {
4945
Executor executor;
5046

5147
if (executors != null && !executors.isEmpty()) {
48+
executors.forEach(e -> LOG.debug("Analyzing executor: {}", e.getClass().getName()));
5249
executor = executors.stream()
53-
.filter(e -> e instanceof ThreadPoolTaskExecutor || e instanceof SimpleAsyncTaskExecutor)
54-
.findFirst()
55-
.orElseThrow(() -> new RuntimeException("No ThreadPoolTaskExecutor or SimpleAsyncTaskExecutor configured"));
50+
.filter(e -> {
51+
try {
52+
return Class.forName("org.springframework.security.task.DelegatingSecurityContextAsyncTaskExecutor").isInstance(e);
53+
} catch (ClassNotFoundException ex) {
54+
// No problem, spring-security is not configured
55+
return false;
56+
}
57+
}).findAny().orElseGet(() ->
58+
executors.stream()
59+
.filter(e -> e instanceof ThreadPoolTaskExecutor || e instanceof SimpleAsyncTaskExecutor)
60+
.findFirst()
61+
.orElseThrow(() -> new RuntimeException("No ThreadPoolTaskExecutor, SimpleAsyncTaskExecutor or DelegatingSecurityContextAsyncTaskExecutor configured"))
62+
);
5663
} else {
5764
throw new RuntimeException("No Executor configured");
5865
}
66+
67+
LOG.debug("Using executor: {}", executor.getClass().getName());
5968
int port = Integer.parseInt(env.getProperty("server.port", "8080"));
6069
return new SpringBootPlatformHttpEngine(port, executor);
6170
}
6271

6372
@Bean
6473
@DependsOn("configurePlatformHttpComponent")
65-
public CamelRequestHandlerMapping platformHttpEngineRequestMapping(PlatformHttpEngine engine) {
74+
public CamelRequestHandlerMapping platformHttpEngineRequestMapping(PlatformHttpEngine engine, CamelContext camelContext) {
6675
PlatformHttpComponent component = camelContext.getComponent("platform-http", PlatformHttpComponent.class);
6776
CamelRequestHandlerMapping answer = new CamelRequestHandlerMapping(component, engine);
6877
return answer;

0 commit comments

Comments
 (0)