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 2014/02/10 15:40:25 UTC
[2/2] git commit: CAMEL-7188: ManagedCamelContext findComponents
should only return meta-data over JMX and not the actual comp.
implementation.
CAMEL-7188: ManagedCamelContext findComponents should only return meta-data over JMX and not the actual comp. implementation.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/ffda34a3
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/ffda34a3
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/ffda34a3
Branch: refs/heads/camel-2.12.x
Commit: ffda34a34d77c118f720d3faf6aa12c9508e00e4
Parents: 8b00142
Author: Claus Ibsen <da...@apache.org>
Authored: Mon Feb 10 15:40:52 2014 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Mon Feb 10 15:41:24 2014 +0100
----------------------------------------------------------------------
.../management/mbean/ManagedCamelContext.java | 9 +++-
.../apache/camel/util/CamelContextHelper.java | 57 ++++++++++++++++++--
.../management/ManagedCamelContextTest.java | 1 +
3 files changed, 62 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/ffda34a3/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java
index 29d4521..a8f2571 100644
--- a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java
+++ b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java
@@ -371,7 +371,14 @@ public class ManagedCamelContext extends ManagedPerformanceCounter implements Ti
}
public Map<String, Properties> findComponents() throws Exception {
- return context.findComponents();
+ Map<String, Properties> answer = context.findComponents();
+ for (Map.Entry<String, Properties> entry : answer.entrySet()) {
+ // remove component as its not serializable over JMX
+ if (entry.getValue() != null) {
+ entry.getValue().remove("component");
+ }
+ }
+ return answer;
}
public String getComponentDocumentation(String componentName) throws IOException {
http://git-wip-us.apache.org/repos/asf/camel/blob/ffda34a3/camel-core/src/main/java/org/apache/camel/util/CamelContextHelper.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/CamelContextHelper.java b/camel-core/src/main/java/org/apache/camel/util/CamelContextHelper.java
index 35095a6..10629a7 100644
--- a/camel-core/src/main/java/org/apache/camel/util/CamelContextHelper.java
+++ b/camel-core/src/main/java/org/apache/camel/util/CamelContextHelper.java
@@ -17,8 +17,10 @@
package org.apache.camel.util;
import java.io.IOException;
+import java.io.InputStream;
import java.net.URL;
import java.util.Enumeration;
+import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Properties;
@@ -45,6 +47,7 @@ import static org.apache.camel.util.ObjectHelper.notNull;
* @version
*/
public final class CamelContextHelper {
+ public static final String COMPONENT_BASE = "META-INF/services/org/apache/camel/component/";
public static final String COMPONENT_DESCRIPTOR = "META-INF/services/org/apache/camel/component.properties";
public static final String COMPONENT_DOCUMENTATION_PREFIX = "org/apache/camel/component/";
@@ -352,7 +355,8 @@ public final class CamelContextHelper {
}
/**
- * Finds all possible Components on the classpath and Registry
+ * Finds all possible Components on the classpath, already registered in {@link org.apache.camel.CamelContext},
+ * and from the {@link org.apache.camel.spi.Registry}.
*/
public static SortedMap<String, Properties> findComponents(CamelContext camelContext) throws LoadPropertiesException {
Enumeration<URL> iter = camelContext.getClassResolver().loadResourcesAsURL(COMPONENT_DESCRIPTOR);
@@ -373,7 +377,36 @@ public final class CamelContextHelper {
StringTokenizer tok = new StringTokenizer(names);
while (tok.hasMoreTokens()) {
String name = tok.nextToken();
- map.put(name, properties);
+
+ // try to find the class name for this component
+ String className = null;
+ InputStream is = null;
+ try {
+ is = camelContext.getClassResolver().loadResourceAsStream(COMPONENT_BASE + name);
+ if (is != null) {
+ Properties compProperties = new Properties();
+ compProperties.load(is);
+ if (!compProperties.isEmpty()) {
+ className = compProperties.getProperty("class");
+ }
+ }
+ } catch (Exception e) {
+ // ignore
+ } finally {
+ IOHelper.close(is);
+ }
+
+ // inherit properties we loaded first, as it has maven details
+ Properties prop = new Properties();
+ prop.putAll(properties);
+ if (camelContext.hasComponent(name) != null) {
+ prop.put("component", camelContext.getComponent(name));
+ }
+ if (className != null) {
+ prop.put("class", className);
+ }
+ prop.put("name", name);
+ map.put(name, prop);
}
}
} catch (IOException e) {
@@ -381,17 +414,33 @@ public final class CamelContextHelper {
}
}
+ // lets see what other components are registered on camel context
+ List<String> names = camelContext.getComponentNames();
+ for (String name : names) {
+ if (!map.containsKey(name)) {
+ Component component = camelContext.getComponent(name);
+ if (component != null) {
+ Properties properties = new Properties();
+ properties.put("component", component);
+ properties.put("class", component.getClass().getName());
+ properties.put("name", name);
+ map.put(name, properties);
+ }
+ }
+ }
+
// lets see what other components are in the registry
Map<String, Component> beanMap = camelContext.getRegistry().findByTypeWithName(Component.class);
Set<Map.Entry<String, Component>> entries = beanMap.entrySet();
for (Map.Entry<String, Component> entry : entries) {
String name = entry.getKey();
if (!map.containsKey(name)) {
- Properties properties = new Properties();
Component component = entry.getValue();
if (component != null) {
- properties.put("component", component);
+ Properties properties = new Properties();
+ properties.put("component", name);
properties.put("class", component.getClass().getName());
+ properties.put("name", name);
map.put(name, properties);
}
}
http://git-wip-us.apache.org/repos/asf/camel/blob/ffda34a3/camel-core/src/test/java/org/apache/camel/management/ManagedCamelContextTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/management/ManagedCamelContextTest.java b/camel-core/src/test/java/org/apache/camel/management/ManagedCamelContextTest.java
index 5b8ec5e..c49186f 100644
--- a/camel-core/src/test/java/org/apache/camel/management/ManagedCamelContextTest.java
+++ b/camel-core/src/test/java/org/apache/camel/management/ManagedCamelContextTest.java
@@ -197,6 +197,7 @@ public class ManagedCamelContextTest extends ManagementTestSupport {
assertEquals(22, info.size());
Properties prop = info.get("seda");
assertNotNull(prop);
+ assertEquals("seda", prop.get("name"));
assertEquals("org.apache.camel", prop.get("groupId"));
assertEquals("camel-core", prop.get("artifactId"));
}