|
19 | 19 | import org.apache.camel.CamelContext;
|
20 | 20 | import org.apache.camel.component.platform.http.PlatformHttpComponent;
|
21 | 21 | 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; |
23 | 24 | import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
24 | 25 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
25 | 26 | import org.springframework.context.annotation.Bean;
|
|
36 | 37 | @AutoConfigureAfter(name = { "org.apache.camel.component.servlet.springboot.PlatformHttpComponentAutoConfiguration",
|
37 | 38 | "org.apache.camel.component.servlet.springboot.PlatformHttpComponentConverter" })
|
38 | 39 | 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); |
45 | 41 |
|
46 | 42 | @Bean(name = "platform-http-engine")
|
47 | 43 | @ConditionalOnMissingBean(PlatformHttpEngine.class)
|
48 |
| - public PlatformHttpEngine springBootPlatformHttpEngine(Environment env) { |
| 44 | + public PlatformHttpEngine springBootPlatformHttpEngine(Environment env, List<Executor> executors) { |
49 | 45 | Executor executor;
|
50 | 46 |
|
51 | 47 | if (executors != null && !executors.isEmpty()) {
|
| 48 | + executors.forEach(e -> LOG.debug("Analyzing executor: {}", e.getClass().getName())); |
52 | 49 | 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 | + ); |
56 | 63 | } else {
|
57 | 64 | throw new RuntimeException("No Executor configured");
|
58 | 65 | }
|
| 66 | + |
| 67 | + LOG.debug("Using executor: {}", executor.getClass().getName()); |
59 | 68 | int port = Integer.parseInt(env.getProperty("server.port", "8080"));
|
60 | 69 | return new SpringBootPlatformHttpEngine(port, executor);
|
61 | 70 | }
|
62 | 71 |
|
63 | 72 | @Bean
|
64 | 73 | @DependsOn("configurePlatformHttpComponent")
|
65 |
| - public CamelRequestHandlerMapping platformHttpEngineRequestMapping(PlatformHttpEngine engine) { |
| 74 | + public CamelRequestHandlerMapping platformHttpEngineRequestMapping(PlatformHttpEngine engine, CamelContext camelContext) { |
66 | 75 | PlatformHttpComponent component = camelContext.getComponent("platform-http", PlatformHttpComponent.class);
|
67 | 76 | CamelRequestHandlerMapping answer = new CamelRequestHandlerMapping(component, engine);
|
68 | 77 | return answer;
|
|
0 commit comments