Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle Spring Security Async Proxy #1401

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
import org.apache.camel.CamelContext;
import org.apache.camel.component.platform.http.PlatformHttpComponent;
import org.apache.camel.component.platform.http.spi.PlatformHttpEngine;
import org.springframework.beans.factory.annotation.Autowired;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
Expand All @@ -36,33 +37,41 @@
@AutoConfigureAfter(name = { "org.apache.camel.component.servlet.springboot.PlatformHttpComponentAutoConfiguration",
"org.apache.camel.component.servlet.springboot.PlatformHttpComponentConverter" })
public class SpringBootPlatformHttpAutoConfiguration {

@Autowired
CamelContext camelContext;

@Autowired
List<Executor> executors;
private static final Logger LOG = LoggerFactory.getLogger(SpringBootPlatformHttpAutoConfiguration.class);

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

if (executors != null && !executors.isEmpty()) {
executors.forEach(e -> LOG.debug("Analyzing executor: {}", e.getClass().getName()));
executor = executors.stream()
.filter(e -> e instanceof ThreadPoolTaskExecutor || e instanceof SimpleAsyncTaskExecutor)
.findFirst()
.orElseThrow(() -> new RuntimeException("No ThreadPoolTaskExecutor or SimpleAsyncTaskExecutor configured"));
.filter(e -> {
try {
return Class.forName("org.springframework.security.task.DelegatingSecurityContextAsyncTaskExecutor").isInstance(e);
} catch (ClassNotFoundException ex) {
// No problem, spring-security is not configured
return false;
}
}).findAny().orElseGet(() ->
executors.stream()
.filter(e -> e instanceof ThreadPoolTaskExecutor || e instanceof SimpleAsyncTaskExecutor)
.findFirst()
.orElseThrow(() -> new RuntimeException("No ThreadPoolTaskExecutor, SimpleAsyncTaskExecutor or DelegatingSecurityContextAsyncTaskExecutor configured"))
);
} else {
throw new RuntimeException("No Executor configured");
}

LOG.debug("Using executor: {}", executor.getClass().getName());
int port = Integer.parseInt(env.getProperty("server.port", "8080"));
return new SpringBootPlatformHttpEngine(port, executor);
}

@Bean
@DependsOn("configurePlatformHttpComponent")
public CamelRequestHandlerMapping platformHttpEngineRequestMapping(PlatformHttpEngine engine) {
public CamelRequestHandlerMapping platformHttpEngineRequestMapping(PlatformHttpEngine engine, CamelContext camelContext) {
PlatformHttpComponent component = camelContext.getComponent("platform-http", PlatformHttpComponent.class);
CamelRequestHandlerMapping answer = new CamelRequestHandlerMapping(component, engine);
return answer;
Expand Down