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


The following commit(s) were added to refs/heads/main by this push:
     new 7d6f7da  Fixed NPE
7d6f7da is described below

commit 7d6f7da7d95b51be5b7f825d905bdfebfb9dc731
Author: Claus Ibsen <[email protected]>
AuthorDate: Sun Dec 26 11:27:29 2021 +0100

    Fixed NPE
---
 .../org/apache/camel/main/VertxHttpServer.java     | 99 ++++++++++++----------
 1 file changed, 54 insertions(+), 45 deletions(-)

diff --git 
a/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/VertxHttpServer.java
 
b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/VertxHttpServer.java
index 6000e08..99d0295 100644
--- 
a/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/VertxHttpServer.java
+++ 
b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/VertxHttpServer.java
@@ -24,6 +24,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
 import org.apache.camel.CamelContext;
 import org.apache.camel.Component;
 import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.StartupListener;
 import org.apache.camel.spi.CamelEvent;
 import org.apache.camel.support.IntrospectionSupport;
 import org.apache.camel.support.ObjectHelper;
@@ -71,54 +72,62 @@ public final class VertxHttpServer {
             Object server = clazz.getConstructors()[0].newInstance(config);
 
             camelContext.addService(server);
-        } catch (Exception e) {
-            throw RuntimeCamelException.wrapRuntimeException(e);
-        }
-
-        camelContext.getManagementStrategy().addEventNotifier(new 
SimpleEventNotifierSupport() {
-
-            private volatile Component phc;
-            private volatile Method method;
-            private Set<String> last;
-
-            @Override
-            public boolean isEnabled(CamelEvent event) {
-                return event instanceof CamelEvent.CamelContextStartedEvent || 
event instanceof CamelEvent.RouteReloadedEvent;
-            }
-
-            @Override
-            public void notify(CamelEvent event) throws Exception {
-                if (method == null) {
-                    phc = camelContext.getComponent("platform-http", 
Component.class);
-                    method = ReflectionHelper.findMethod(phc.getClass(), 
"getHttpEndpoints");
-                }
 
-                // when reloading then there may be more routes in the same 
batch, so we only want
-                // to log the summary at the end
-                if (event instanceof CamelEvent.RouteReloadedEvent) {
-                    CamelEvent.RouteReloadedEvent re = 
(CamelEvent.RouteReloadedEvent) event;
-                    if (re.getIndex() < re.getTotal()) {
-                        return;
-                    }
+            // after camel is started then add event notifier
+            camelContext.addStartupListener(new StartupListener() {
+                @Override
+                public void onCamelContextStarted(CamelContext context, 
boolean alreadyStarted) throws Exception {
+                    camelContext.getManagementStrategy().addEventNotifier(new 
SimpleEventNotifierSupport() {
+
+                        private volatile Component phc;
+                        private volatile Method method;
+                        private Set<String> last;
+
+                        @Override
+                        public boolean isEnabled(CamelEvent event) {
+                            return event instanceof 
CamelEvent.CamelContextStartedEvent
+                                    || event instanceof 
CamelEvent.RouteReloadedEvent;
+                        }
+
+                        @Override
+                        public void notify(CamelEvent event) throws Exception {
+                            if (method == null) {
+                                phc = 
camelContext.getComponent("platform-http", Component.class);
+                                method = 
ReflectionHelper.findMethod(phc.getClass(), "getHttpEndpoints");
+                            }
+
+                            // when reloading then there may be more routes in 
the same batch, so we only want
+                            // to log the summary at the end
+                            if (event instanceof 
CamelEvent.RouteReloadedEvent) {
+                                CamelEvent.RouteReloadedEvent re = 
(CamelEvent.RouteReloadedEvent) event;
+                                if (re.getIndex() < re.getTotal()) {
+                                    return;
+                                }
+                            }
+
+                            Set<String> endpoints = (Set<String>) 
ObjectHelper.invokeMethodSafe(method, phc);
+                            if (endpoints.isEmpty()) {
+                                return;
+                            }
+
+                            // log only if changed
+                            if (last == null || last.size() != 
endpoints.size() || !last.containsAll(endpoints)) {
+                                LOG.info("HTTP endpoints summary");
+                                for (String u : endpoints) {
+                                    LOG.info("    http://0.0.0.0:"; + port + u);
+                                }
+                            }
+
+                            // use a defensive copy of last known endpoints
+                            last = new HashSet<>(endpoints);
+                        }
+                    });
                 }
+            });
 
-                Set<String> endpoints = (Set<String>) 
ObjectHelper.invokeMethodSafe(method, phc);
-                if (endpoints.isEmpty()) {
-                    return;
-                }
-
-                // log only if changed
-                if (last == null || last.size() != endpoints.size() || 
!last.containsAll(endpoints)) {
-                    LOG.info("HTTP endpoints summary");
-                    for (String u : endpoints) {
-                        LOG.info("    http://0.0.0.0:"; + port + u);
-                    }
-                }
-
-                // use a defensive copy of last known endpoints
-                last = new HashSet<>(endpoints);
-            }
-        });
+        } catch (Exception e) {
+            throw RuntimeCamelException.wrapRuntimeException(e);
+        }
     }
 
 }

Reply via email to