This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch camel-4.14.x
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/camel-4.14.x by this push:
new 04bd05a7a935 CAMEL-22494: camel-as2 - When a route is stopped then the
listener should return http 404 error as otherwise it will still process the
incoming request. (#19471)
04bd05a7a935 is described below
commit 04bd05a7a9353f7b50e63a226351cb5f7087f030
Author: Claus Ibsen <[email protected]>
AuthorDate: Tue Oct 7 19:44:09 2025 +0200
CAMEL-22494: camel-as2 - When a route is stopped then the listener should
return http 404 error as otherwise it will still process the incoming request.
(#19471)
---
.../component/as2/api/AS2ServerConnection.java | 16 ++++++++++
.../camel/component/as2/api/AS2ServerManager.java | 4 +++
.../as2/api/NotFoundHttpRequestHandler.java | 34 ++++++++++++++++++++++
components/camel-as2/camel-as2-component/pom.xml | 15 +---------
.../apache/camel/component/as2/AS2Consumer.java | 5 ++++
5 files changed, 60 insertions(+), 14 deletions(-)
diff --git
a/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/AS2ServerConnection.java
b/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/AS2ServerConnection.java
index c69a38f86d5e..b6210d7f3637 100644
---
a/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/AS2ServerConnection.java
+++
b/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/AS2ServerConnection.java
@@ -130,6 +130,11 @@ public class AS2ServerConnection {
void registerHandler(String requestUriPattern, HttpRequestHandler
httpRequestHandler) {
registry.register(null, requestUriPattern, httpRequestHandler);
}
+
+ void unregisterHandler(String requestUriPattern) {
+ // we cannot remove from http registry, but we can replace with a
not found to simulate 404
+ registry.register(null, requestUriPattern, new
NotFoundHttpRequestHandler());
+ }
}
class RequestHandlerThread extends Thread {
@@ -307,6 +312,17 @@ public class AS2ServerConnection {
}
}
+ public void unlisten(String requestUri) {
+ if (listenerThread != null) {
+ lock.lock();
+ try {
+ listenerThread.unregisterHandler(requestUri);
+ } finally {
+ lock.unlock();
+ }
+ }
+ }
+
protected HttpProcessor initProtocolProcessor(
String as2Version,
String originServer,
diff --git
a/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/AS2ServerManager.java
b/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/AS2ServerManager.java
index 9836e9b63dd9..e2b49ae44753 100644
---
a/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/AS2ServerManager.java
+++
b/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/AS2ServerManager.java
@@ -53,6 +53,10 @@ public class AS2ServerManager {
as2ServerConnection.listen(requestUriPattern, handler);
}
+ public void unlisten(String requestUriPattern) {
+ as2ServerConnection.unlisten(requestUriPattern);
+ }
+
public void handleMDNResponse(
HttpContext httpContext, String subject, String from) {
// Add Context attributes for Response
diff --git
a/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/NotFoundHttpRequestHandler.java
b/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/NotFoundHttpRequestHandler.java
new file mode 100644
index 000000000000..72a9067686b9
--- /dev/null
+++
b/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/NotFoundHttpRequestHandler.java
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.as2.api;
+
+import java.io.IOException;
+
+import org.apache.hc.core5.http.ClassicHttpRequest;
+import org.apache.hc.core5.http.ClassicHttpResponse;
+import org.apache.hc.core5.http.HttpException;
+import org.apache.hc.core5.http.io.HttpRequestHandler;
+import org.apache.hc.core5.http.protocol.HttpContext;
+
+public class NotFoundHttpRequestHandler implements HttpRequestHandler {
+
+ @Override
+ public void handle(ClassicHttpRequest classicHttpRequest,
ClassicHttpResponse classicHttpResponse, HttpContext httpContext)
+ throws HttpException, IOException {
+ classicHttpResponse.setCode(404);
+ }
+}
diff --git a/components/camel-as2/camel-as2-component/pom.xml
b/components/camel-as2/camel-as2-component/pom.xml
index cb1330b1241f..7bdee2b10c2e 100644
--- a/components/camel-as2/camel-as2-component/pom.xml
+++ b/components/camel-as2/camel-as2-component/pom.xml
@@ -136,13 +136,9 @@
<consumerOnly>true</consumerOnly>
<proxyClass>org.apache.camel.component.as2.api.AS2ServerManager</proxyClass>
<fromJavasource>
-
<excludeMethods>stopListening|handleMDNResponse</excludeMethods>
+
<excludeMethods>stopListening|handleMDNResponse|unlisten</excludeMethods>
</fromJavasource>
<excludeConfigNames>handler</excludeConfigNames>
- <!-- <nullableOptions>
-
<nullableOption>decryptingPrivateKey</nullableOption>
- </nullableOptions>
- -->
</api>
<api>
<apiName>receipt</apiName>
@@ -152,15 +148,6 @@
<excludeConfigNames>handler</excludeConfigNames>
</api>
</apis>
- <!-- Specify global values for all APIs here,
these are overridden at API level
- <substitutions />
- <excludeConfigNames />
- <excludeConfigTypes />
- <extraOptions />
- <fromJavasource />
- <aliases />
- <nullableOptions />
- -->
</configuration>
</execution>
</executions>
diff --git
a/components/camel-as2/camel-as2-component/src/main/java/org/apache/camel/component/as2/AS2Consumer.java
b/components/camel-as2/camel-as2-component/src/main/java/org/apache/camel/component/as2/AS2Consumer.java
index 9bdd8047733e..e05dacc1f39c 100644
---
a/components/camel-as2/camel-as2-component/src/main/java/org/apache/camel/component/as2/AS2Consumer.java
+++
b/components/camel-as2/camel-as2-component/src/main/java/org/apache/camel/component/as2/AS2Consumer.java
@@ -105,6 +105,11 @@ public class AS2Consumer extends
AbstractApiConsumer<AS2ApiName, AS2Configuratio
@Override
protected void doStop() throws Exception {
super.doStop();
+
+ if (apiProxy != null) {
+ String uri = properties.get("requestUriPattern").toString();
+ apiProxy.unlisten(uri);
+ }
}
@Override