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

davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 3ec80199b65cd9627a1002cafe5f420caed4ff4d
Author: Claus Ibsen <claus.ib...@gmail.com>
AuthorDate: Tue Mar 21 18:44:30 2023 +0100

    CAMEL-19176: camel-platform-http - Add listener for added/removed http 
endpoints
---
 .../platform/http/PlatformHttpComponent.java       | 25 ++++++----------------
 .../platform/http/PlatformHttpListener.java        |  5 -----
 2 files changed, 7 insertions(+), 23 deletions(-)

diff --git 
a/components/camel-platform-http/src/main/java/org/apache/camel/component/platform/http/PlatformHttpComponent.java
 
b/components/camel-platform-http/src/main/java/org/apache/camel/component/platform/http/PlatformHttpComponent.java
index 994c0911d49..3bd47d51c89 100644
--- 
a/components/camel-platform-http/src/main/java/org/apache/camel/component/platform/http/PlatformHttpComponent.java
+++ 
b/components/camel-platform-http/src/main/java/org/apache/camel/component/platform/http/PlatformHttpComponent.java
@@ -104,24 +104,11 @@ public class PlatformHttpComponent extends 
DefaultComponent implements RestConsu
      * Adds a known http endpoint managed by this component.
      */
     public void addHttpEndpoint(String uri, String verbs, Consumer consumer) {
-        boolean updated = false;
-
-        HttpEndpointModel model = httpEndpoints.stream().filter(e -> 
e.getUri().equals(uri)).findFirst().orElse(null);
-        if (model == null) {
-            model = new HttpEndpointModel(uri, verbs, consumer);
-            httpEndpoints.add(model);
-        } else {
-            updated = true;
-            model.addVerb(verbs);
-        }
-
+        HttpEndpointModel model = new HttpEndpointModel(uri, verbs, consumer);
+        httpEndpoints.add(model);
         for (PlatformHttpListener listener : listeners) {
             try {
-                if (updated) {
-                    listener.updateHttpEndpoint(model);
-                } else {
-                    listener.registerHttpEndpoint(model);
-                }
+                listener.registerHttpEndpoint(model);
             } catch (Exception e) {
                 LOG.warn("Error adding listener due to " + e.getMessage() + ". 
This exception is ignored", e);
             }
@@ -132,8 +119,9 @@ public class PlatformHttpComponent extends DefaultComponent 
implements RestConsu
      * Removes a known http endpoint managed by this component.
      */
     public void removeHttpEndpoint(String uri) {
-        httpEndpoints.stream().filter(e -> 
e.getUri().equals(uri)).findFirst().ifPresent(model -> {
-            httpEndpoints.remove(model);
+        List<HttpEndpointModel> toRemove = new ArrayList<>();
+        httpEndpoints.stream().filter(e -> 
e.getUri().equals(uri)).forEach(model -> {
+            toRemove.add(model);
             for (PlatformHttpListener listener : listeners) {
                 try {
                     listener.unregisterHttpEndpoint(model);
@@ -142,6 +130,7 @@ public class PlatformHttpComponent extends DefaultComponent 
implements RestConsu
                 }
             }
         });
+        httpEndpoints.removeAll(toRemove);
     }
 
     /**
diff --git 
a/components/camel-platform-http/src/main/java/org/apache/camel/component/platform/http/PlatformHttpListener.java
 
b/components/camel-platform-http/src/main/java/org/apache/camel/component/platform/http/PlatformHttpListener.java
index 5304838f756..8cdc6322082 100644
--- 
a/components/camel-platform-http/src/main/java/org/apache/camel/component/platform/http/PlatformHttpListener.java
+++ 
b/components/camel-platform-http/src/main/java/org/apache/camel/component/platform/http/PlatformHttpListener.java
@@ -23,11 +23,6 @@ public interface PlatformHttpListener {
      */
     void registerHttpEndpoint(HttpEndpointModel model);
 
-    /**
-     * Callback when an existing HTTP endpoint is updated.
-     */
-    void updateHttpEndpoint(HttpEndpointModel model);
-
     /**
      * Callback when an existing HTTP endpoint is removed.
      */

Reply via email to