You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2024/02/18 08:54:09 UTC
(camel) branch main updated (fb0f98e1db7 -> 1930442a728)
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a change to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
from fb0f98e1db7 CAMEL-20361: The generated marker file in META-INF services did not allow sub-folders due to a recent santize fix.
new 1d9ea747b9a CAMEL-20361: camel-jbang - Make jolokia pluggable for camel-platform-http-main (#12985)
new 1930442a728 CAMEL-20361: camel-jbang - Auto download jolokia plugin if in use.
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../DefaultJolokiaPlatformHttpPluginTest.java | 5 +--
.../platform/http/main/MainHttpServer.java | 42 +++++++++++-----------
.../platform/http/PlatformHttpPluginRegistry.java | 6 ++--
.../http/spi/PlatformHttpPluginRegistry.java | 7 ++--
.../camel-main-known-dependencies.properties | 1 +
5 files changed, 33 insertions(+), 28 deletions(-)
(camel) 01/02: CAMEL-20361: camel-jbang - Make jolokia pluggable for camel-platform-http-main (#12985)
Posted by da...@apache.org.
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 1d9ea747b9aea5da7f35bff5b0ee7ad188555d62
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Sun Feb 18 09:28:42 2024 +0100
CAMEL-20361: camel-jbang - Make jolokia pluggable for camel-platform-http-main (#12985)
---
.../DefaultJolokiaPlatformHttpPluginTest.java | 5 +--
.../platform/http/main/MainHttpServer.java | 42 +++++++++++-----------
.../platform/http/PlatformHttpPluginRegistry.java | 4 +--
.../http/spi/PlatformHttpPluginRegistry.java | 7 ++--
4 files changed, 31 insertions(+), 27 deletions(-)
diff --git a/components/camel-platform-http-jolokia/src/test/java/org/apache/camel/component/platform/http/plugin/DefaultJolokiaPlatformHttpPluginTest.java b/components/camel-platform-http-jolokia/src/test/java/org/apache/camel/component/platform/http/plugin/DefaultJolokiaPlatformHttpPluginTest.java
index f98ef6e22bf..6b7f6caf9cc 100644
--- a/components/camel-platform-http-jolokia/src/test/java/org/apache/camel/component/platform/http/plugin/DefaultJolokiaPlatformHttpPluginTest.java
+++ b/components/camel-platform-http-jolokia/src/test/java/org/apache/camel/component/platform/http/plugin/DefaultJolokiaPlatformHttpPluginTest.java
@@ -19,6 +19,7 @@ package org.apache.camel.component.platform.http.plugin;
import java.util.HashMap;
import java.util.Optional;
+import com.fasterxml.jackson.core.util.VersionUtil;
import org.apache.camel.ContextTestSupport;
import org.apache.camel.component.platform.http.spi.PlatformHttpPluginRegistry;
import org.apache.camel.support.ResolverHelper;
@@ -37,8 +38,8 @@ public class DefaultJolokiaPlatformHttpPluginTest extends ContextTestSupport {
public void jolokiaPlatformHttpPluginContextTest() throws Exception {
PlatformHttpPluginRegistry registry = resolvePlatformHttpPluginRegistry();
Assertions.assertNotNull(registry);
- DefaultJolokiaPlatformHttpPlugin plugin = (DefaultJolokiaPlatformHttpPlugin) registry
- .resolvePluginById("jolokia").orElseThrow();
+ DefaultJolokiaPlatformHttpPlugin plugin = registry
+ .resolvePluginById("jolokia", DefaultJolokiaPlatformHttpPlugin.class).orElseThrow();
Assertions.assertNotNull(plugin);
HttpRequestHandler handler = plugin.getRequestHandler();
diff --git a/components/camel-platform-http-main/src/main/java/org/apache/camel/component/platform/http/main/MainHttpServer.java b/components/camel-platform-http-main/src/main/java/org/apache/camel/component/platform/http/main/MainHttpServer.java
index 882e50ea706..e573fb55254 100644
--- a/components/camel-platform-http-main/src/main/java/org/apache/camel/component/platform/http/main/MainHttpServer.java
+++ b/components/camel-platform-http-main/src/main/java/org/apache/camel/component/platform/http/main/MainHttpServer.java
@@ -96,6 +96,8 @@ public class MainHttpServer extends ServiceSupport implements CamelContextAware,
private CamelContext camelContext;
private PlatformHttpComponent platformHttpComponent;
+ private PlatformHttpPluginRegistry pluginRegistry;
+ private JolokiaPlatformHttpPlugin jolokiaPlugin;
private VertxPlatformHttpServerConfiguration configuration = new VertxPlatformHttpServerConfiguration();
private boolean devConsoleEnabled;
@@ -275,24 +277,20 @@ public class MainHttpServer extends ServiceSupport implements CamelContextAware,
server = new VertxPlatformHttpServer(configuration);
camelContext.addService(server);
- PlatformHttpPluginRegistry pluginRegistry
- = getCamelContext().getCamelContextExtension().getContextPlugin(PlatformHttpPluginRegistry.class);
+ pluginRegistry = getCamelContext().getCamelContextExtension().getContextPlugin(PlatformHttpPluginRegistry.class);
if (pluginRegistry == null && pluginsEnabled()) {
pluginRegistry = resolvePlatformHttpPluginRegistry();
pluginRegistry.setCamelContext(getCamelContext());
getCamelContext().getCamelContextExtension().addContextPlugin(PlatformHttpPluginRegistry.class, pluginRegistry);
}
- }
-
- private boolean pluginsEnabled() {
- return jolokiaEnabled;
+ ServiceHelper.initService(pluginRegistry);
}
@Override
protected void doStart() throws Exception {
ObjectHelper.notNull(camelContext, "CamelContext");
- ServiceHelper.startService(server);
+ ServiceHelper.startService(server, pluginRegistry);
router = VertxPlatformHttpRouter.lookup(camelContext);
platformHttpComponent = camelContext.getComponent("platform-http", PlatformHttpComponent.class);
@@ -300,6 +298,15 @@ public class MainHttpServer extends ServiceSupport implements CamelContextAware,
setupStartupSummary();
}
+ @Override
+ protected void doShutdown() throws Exception {
+ ServiceHelper.stopAndShutdownService(pluginRegistry);
+ }
+
+ private boolean pluginsEnabled() {
+ return jolokiaEnabled;
+ }
+
protected void setupConsoles() {
if (devConsoleEnabled) {
setupDevConsole();
@@ -451,17 +458,21 @@ public class MainHttpServer extends ServiceSupport implements CamelContextAware,
}
protected void setupJolokia() {
+ // load plugin
+ jolokiaPlugin = pluginRegistry.resolvePluginById(JolokiaPlatformHttpPlugin.NAME, JolokiaPlatformHttpPlugin.class)
+ .orElseThrow(() -> new RuntimeException(
+ "JolokiaPlatformHttpPlugin not found. Please add camel-platform-http-jolokia dependency."));
+
Route jolokia = router.route("/q/jolokia/*");
jolokia.method(HttpMethod.GET);
jolokia.method(HttpMethod.POST);
Handler<RoutingContext> handler = routingContext -> {
+ HttpRequestHandler requestHandler = jolokiaPlugin.getRequestHandler();
HttpServerRequest req = routingContext.request();
String remainingPath = Utils.pathOffset(req.path(), routingContext);
- HttpRequestHandler requestHandler = getHttpRequestHandler();
-
JSONAware json = null;
try {
requestHandler.checkAccess(req.remoteAddress().host(), req.remoteAddress().host(), getOriginOrReferer(req));
@@ -497,17 +508,8 @@ public class MainHttpServer extends ServiceSupport implements CamelContextAware,
getCamelContext(),
PlatformHttpPluginRegistry.FACTORY,
PlatformHttpPluginRegistry.class);
- return result.orElse(null);
- }
-
- private HttpRequestHandler getHttpRequestHandler() {
- PlatformHttpPluginRegistry registry
- = camelContext.getCamelContextExtension().getContextPlugin(PlatformHttpPluginRegistry.class);
- JolokiaPlatformHttpPlugin jolokia
- = (JolokiaPlatformHttpPlugin) registry.resolvePluginById(JolokiaPlatformHttpPlugin.NAME)
- .orElseThrow(() -> new RuntimeException(
- "JolokiaPlatformHttpPlugin not found. Please add camel-platform-http-jolokia dependency."));
- return jolokia.getRequestHandler();
+ return result.orElseThrow(() -> new IllegalArgumentException(
+ "Cannot create PlatformHttpPluginRegistry. Make sure camel-platform-http JAR is on classpath."));
}
private Map<String, String[]> getParams(MultiMap params) {
diff --git a/components/camel-platform-http/src/main/java/org/apache/camel/component/platform/http/PlatformHttpPluginRegistry.java b/components/camel-platform-http/src/main/java/org/apache/camel/component/platform/http/PlatformHttpPluginRegistry.java
index b4acd4675e9..91f2a470632 100644
--- a/components/camel-platform-http/src/main/java/org/apache/camel/component/platform/http/PlatformHttpPluginRegistry.java
+++ b/components/camel-platform-http/src/main/java/org/apache/camel/component/platform/http/PlatformHttpPluginRegistry.java
@@ -48,7 +48,7 @@ public class PlatformHttpPluginRegistry extends ServiceSupport
private final Set<PlatformHttpPlugin> plugins = new TreeSet<>(Comparator.comparing(PlatformHttpPlugin::getId));
@Override
- public Optional<PlatformHttpPlugin> resolvePluginById(String id) {
+ public <T extends PlatformHttpPlugin> Optional<T> resolvePluginById(String id, Class<T> type) {
PlatformHttpPlugin answer = plugins.stream().filter(plugin -> plugin.getId().equals(id)).findFirst()
.orElse(getCamelContext().getRegistry().findByTypeWithName(PlatformHttpPlugin.class).get(id));
if (answer == null) {
@@ -58,7 +58,7 @@ public class PlatformHttpPluginRegistry extends ServiceSupport
if (answer != null) {
register(answer);
}
- return Optional.ofNullable(answer);
+ return Optional.ofNullable(type.cast(answer));
}
@Override
diff --git a/components/camel-platform-http/src/main/java/org/apache/camel/component/platform/http/spi/PlatformHttpPluginRegistry.java b/components/camel-platform-http/src/main/java/org/apache/camel/component/platform/http/spi/PlatformHttpPluginRegistry.java
index 481ac41b6b8..016e3bd94ea 100644
--- a/components/camel-platform-http/src/main/java/org/apache/camel/component/platform/http/spi/PlatformHttpPluginRegistry.java
+++ b/components/camel-platform-http/src/main/java/org/apache/camel/component/platform/http/spi/PlatformHttpPluginRegistry.java
@@ -31,10 +31,11 @@ public interface PlatformHttpPluginRegistry extends CamelContextAware, StaticSer
/**
* Resolve a plugin by id
*
- * @param id the plugin id
- * @return the plugin if found
+ * @param id the plugin id
+ * @param type the plugin class type
+ * @return the plugin if found
*/
- Optional<PlatformHttpPlugin> resolvePluginById(String id);
+ <T extends PlatformHttpPlugin> Optional<T> resolvePluginById(String id, Class<T> type);
/**
* Register the plugin into the registry.
(camel) 02/02: CAMEL-20361: camel-jbang - Auto download jolokia plugin if in use.
Posted by da...@apache.org.
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 1930442a728e901e9e513a83c48a51ad0e5fd6f9
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Sun Feb 18 09:53:54 2024 +0100
CAMEL-20361: camel-jbang - Auto download jolokia plugin if in use.
---
.../camel/component/platform/http/PlatformHttpPluginRegistry.java | 2 +-
.../src/main/resources/camel-main-known-dependencies.properties | 1 +
2 files changed, 2 insertions(+), 1 deletion(-)
diff --git a/components/camel-platform-http/src/main/java/org/apache/camel/component/platform/http/PlatformHttpPluginRegistry.java b/components/camel-platform-http/src/main/java/org/apache/camel/component/platform/http/PlatformHttpPluginRegistry.java
index 91f2a470632..4493687af9c 100644
--- a/components/camel-platform-http/src/main/java/org/apache/camel/component/platform/http/PlatformHttpPluginRegistry.java
+++ b/components/camel-platform-http/src/main/java/org/apache/camel/component/platform/http/PlatformHttpPluginRegistry.java
@@ -96,7 +96,7 @@ public class PlatformHttpPluginRegistry extends ServiceSupport
PlatformHttpPlugin answer = null;
FactoryFinder factoryFinder
- = getCamelContext().getCamelContextExtension().getFactoryFinder(PLATFORM_HTTP_PLUGIN_FACTORY_PATH);
+ = getCamelContext().getCamelContextExtension().getBootstrapFactoryFinder(PLATFORM_HTTP_PLUGIN_FACTORY_PATH);
Class<?> type = factoryFinder.findOptionalClass(id).orElse(null);
if (type != null) {
if (PlatformHttpPlugin.class.isAssignableFrom(type)) {
diff --git a/dsl/camel-kamelet-main/src/main/resources/camel-main-known-dependencies.properties b/dsl/camel-kamelet-main/src/main/resources/camel-main-known-dependencies.properties
index f11f5cd3bc6..09724f0267a 100644
--- a/dsl/camel-kamelet-main/src/main/resources/camel-main-known-dependencies.properties
+++ b/dsl/camel-kamelet-main/src/main/resources/camel-main-known-dependencies.properties
@@ -32,3 +32,4 @@ META-INF/services/org/apache/camel/modelxml-dumper = camel:xml-io
META-INF/services/org/apache/camel/modelyaml-dumper = camel:yaml-io
META-INF/services/org/apache/camel/micrometer-prometheus = camel:micrometer-prometheus
META-INF/services/org/apache/camel/cron/cron-service = camel:quartz
+META-INF/services/org/apache/camel/platform-http/jolokia = camel:camel-platform-http-jolokia