This is an automated email from the ASF dual-hosted git repository.

fmariani pushed a commit to branch camel-spring-boot-4.8.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.8.x by 
this push:
     new 4e9a8d9f8cc Use SB Async Interceptor
4e9a8d9f8cc is described below

commit 4e9a8d9f8cc17e9eab61fa4fb4244e74291d0cf0
Author: Croway <federico.mariani.1...@gmail.com>
AuthorDate: Fri Oct 4 11:48:23 2024 +0200

    Use SB Async Interceptor
---
 .../camel-platform-http-starter/pom.xml            |  4 ++++
 .../SpringBootPlatformHttpAutoConfiguration.java   |  7 +++++-
 .../springboot/SpringBootPlatformHttpConsumer.java | 15 +++++++++---
 .../springboot/SpringBootPlatformHttpEngine.java   | 27 ++++++++++++++++++++--
 4 files changed, 47 insertions(+), 6 deletions(-)

diff --git a/components-starter/camel-platform-http-starter/pom.xml 
b/components-starter/camel-platform-http-starter/pom.xml
index dc9d05a7e20..01089ff8565 100644
--- a/components-starter/camel-platform-http-starter/pom.xml
+++ b/components-starter/camel-platform-http-starter/pom.xml
@@ -61,6 +61,10 @@
       <version>${jetty-version}</version>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>org.springframework</groupId>
+      <artifactId>spring-aop</artifactId>
+    </dependency>
     <!--START OF GENERATED CODE-->
     <dependency>
       <groupId>org.apache.camel.springboot</groupId>
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 e604dff895e..17220e4cfd2 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
@@ -27,6 +27,8 @@ import org.springframework.context.annotation.Configuration;
 import org.springframework.context.annotation.DependsOn;
 import org.springframework.core.env.Environment;
 
+import java.util.concurrent.Executor;
+
 @Configuration(proxyBeanMethods = false)
 @AutoConfigureAfter(name = { 
"org.apache.camel.component.servlet.springboot.PlatformHttpComponentAutoConfiguration",
         
"org.apache.camel.component.servlet.springboot.PlatformHttpComponentConverter" 
})
@@ -35,11 +37,14 @@ public class SpringBootPlatformHttpAutoConfiguration {
     @Autowired
     CamelContext camelContext;
 
+    @Autowired
+    Executor executor;
+
     @Bean(name = "platform-http-engine")
     @ConditionalOnMissingBean(PlatformHttpEngine.class)
     public PlatformHttpEngine springBootPlatformHttpEngine(Environment env) {
         int port = Integer.parseInt(env.getProperty("server.port", "8080"));
-        return new SpringBootPlatformHttpEngine(port);
+        return new SpringBootPlatformHttpEngine(port, executor);
     }
 
     @Bean
diff --git 
a/components-starter/camel-platform-http-starter/src/main/java/org/apache/camel/component/platform/http/springboot/SpringBootPlatformHttpConsumer.java
 
b/components-starter/camel-platform-http-starter/src/main/java/org/apache/camel/component/platform/http/springboot/SpringBootPlatformHttpConsumer.java
index 8a312416abf..d5e5909c3bb 100644
--- 
a/components-starter/camel-platform-http-starter/src/main/java/org/apache/camel/component/platform/http/springboot/SpringBootPlatformHttpConsumer.java
+++ 
b/components-starter/camel-platform-http-starter/src/main/java/org/apache/camel/component/platform/http/springboot/SpringBootPlatformHttpConsumer.java
@@ -19,7 +19,6 @@ package org.apache.camel.component.platform.http.springboot;
 import jakarta.servlet.ServletException;
 import jakarta.servlet.http.HttpServletRequest;
 import jakarta.servlet.http.HttpServletResponse;
-import java.util.concurrent.CompletableFuture;
 import org.apache.camel.Exchange;
 import org.apache.camel.ExchangePattern;
 import org.apache.camel.Processor;
@@ -27,7 +26,6 @@ import org.apache.camel.Suspendable;
 import org.apache.camel.SuspendableService;
 import org.apache.camel.component.platform.http.PlatformHttpEndpoint;
 import org.apache.camel.component.platform.http.spi.PlatformHttpConsumer;
-import org.apache.camel.http.common.DefaultHttpBinding;
 import org.apache.camel.http.common.HttpBinding;
 import org.apache.camel.http.common.HttpHelper;
 import org.apache.camel.support.DefaultConsumer;
@@ -35,12 +33,17 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.web.bind.annotation.ResponseBody;
 
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.Executor;
+import java.util.concurrent.Executors;
+
 public class SpringBootPlatformHttpConsumer extends DefaultConsumer implements 
PlatformHttpConsumer, Suspendable, SuspendableService {
 
     private static final Logger LOG = 
LoggerFactory.getLogger(SpringBootPlatformHttpConsumer.class);
 
     private HttpBinding binding;
     private final boolean handleWriteResponseError;
+    private Executor executor;
 
     public SpringBootPlatformHttpConsumer(PlatformHttpEndpoint endpoint, 
Processor processor) {
         super(endpoint, processor);
@@ -50,6 +53,12 @@ public class SpringBootPlatformHttpConsumer extends 
DefaultConsumer implements P
         
this.binding.setFileNameExtWhitelist(endpoint.getFileNameExtWhitelist());
         this.binding.setUseReaderForPayload(!endpoint.isUseStreaming());
         this.handleWriteResponseError = endpoint.isHandleWriteResponseError();
+        this.executor = Executors.newSingleThreadExecutor();
+    }
+
+    public SpringBootPlatformHttpConsumer(PlatformHttpEndpoint endpoint, 
Processor processor, Executor executor) {
+        this(endpoint, processor);
+        this.executor = executor;
     }
 
     /**
@@ -84,7 +93,7 @@ public class SpringBootPlatformHttpConsumer extends 
DefaultConsumer implements P
                     // ignore
                 }
             }
-        });
+        }, executor);
     }
 
     protected void handleService(HttpServletRequest request, 
HttpServletResponse response) throws Exception {
diff --git 
a/components-starter/camel-platform-http-starter/src/main/java/org/apache/camel/component/platform/http/springboot/SpringBootPlatformHttpEngine.java
 
b/components-starter/camel-platform-http-starter/src/main/java/org/apache/camel/component/platform/http/springboot/SpringBootPlatformHttpEngine.java
index 39ccca4ca96..4e5d3c9ab16 100644
--- 
a/components-starter/camel-platform-http-starter/src/main/java/org/apache/camel/component/platform/http/springboot/SpringBootPlatformHttpEngine.java
+++ 
b/components-starter/camel-platform-http-starter/src/main/java/org/apache/camel/component/platform/http/springboot/SpringBootPlatformHttpEngine.java
@@ -16,23 +16,46 @@
  */
 package org.apache.camel.component.platform.http.springboot;
 
-import org.apache.camel.Consumer;
 import org.apache.camel.Processor;
 import org.apache.camel.component.platform.http.PlatformHttpEndpoint;
 import org.apache.camel.component.platform.http.spi.PlatformHttpConsumer;
 import org.apache.camel.component.platform.http.spi.PlatformHttpEngine;
+import org.springframework.aop.framework.ProxyFactory;
+import org.springframework.aop.interceptor.AsyncExecutionInterceptor;
+import org.springframework.aop.support.DefaultPointcutAdvisor;
+import org.springframework.aop.support.JdkRegexpMethodPointcut;
+
+import java.util.concurrent.Executor;
 
 public class SpringBootPlatformHttpEngine implements PlatformHttpEngine {
 
     private final int port;
+    private Executor executor;
 
     public SpringBootPlatformHttpEngine(int port) {
         this.port = port;
     }
 
+    public SpringBootPlatformHttpEngine(int port, Executor executor) {
+        this(port);
+        this.executor = executor;
+    }
+
     @Override
     public PlatformHttpConsumer createConsumer(PlatformHttpEndpoint endpoint, 
Processor processor) {
-        return new SpringBootPlatformHttpConsumer(endpoint, processor);
+        ProxyFactory factory = new ProxyFactory();
+        factory.setTarget(new SpringBootPlatformHttpConsumer(endpoint, 
processor, executor));
+
+        JdkRegexpMethodPointcut jdkRegexpMethodPointcut = new 
JdkRegexpMethodPointcut();
+        
jdkRegexpMethodPointcut.setPattern("org.apache.camel.component.platform.http.springboot.SpringBootPlatformHttpConsumer.service");
+
+        DefaultPointcutAdvisor advisor = new DefaultPointcutAdvisor();
+        advisor.setAdvice(new AsyncExecutionInterceptor(executor));
+        advisor.setPointcut(jdkRegexpMethodPointcut);
+
+        factory.addAdvisor(advisor);
+
+        return (SpringBootPlatformHttpConsumer) factory.getProxy();
     }
 
     @Override

Reply via email to