Repository: camel Updated Branches: refs/heads/master a42a2ca95 -> c34177d71
[CAMEL-7218] PlatformHelper relies now on analyzing CamelContext name. Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/c34177d7 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/c34177d7 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/c34177d7 Branch: refs/heads/master Commit: c34177d71974141076ab464843225fcd7b90a0a7 Parents: a42a2ca Author: Henryk Konsek <hekon...@gmail.com> Authored: Thu Feb 20 18:06:46 2014 +0100 Committer: Henryk Konsek <hekon...@gmail.com> Committed: Thu Feb 20 18:06:46 2014 +0100 ---------------------------------------------------------------------- .../org/apache/camel/util/PlatformHelper.java | 29 ++++++++------------ .../apache/camel/util/PlatformHelperTest.java | 21 ++++++++++++-- .../bean/validator/BeanValidatorComponent.java | 5 ++-- 3 files changed, 31 insertions(+), 24 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/c34177d7/camel-core/src/main/java/org/apache/camel/util/PlatformHelper.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/util/PlatformHelper.java b/camel-core/src/main/java/org/apache/camel/util/PlatformHelper.java index 1b47956..7831b9e 100644 --- a/camel-core/src/main/java/org/apache/camel/util/PlatformHelper.java +++ b/camel-core/src/main/java/org/apache/camel/util/PlatformHelper.java @@ -16,12 +16,10 @@ */ package org.apache.camel.util; -import org.osgi.framework.Bundle; +import org.apache.camel.CamelContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import static org.osgi.framework.FrameworkUtil.getBundle; - /** * Utility dedicated for resolving runtime information related to the platform on which Camel is currently running. */ @@ -33,26 +31,21 @@ public final class PlatformHelper { } /** - * Determine whether Camel is running in the OSGi environment. + * Determine whether Camel is OSGi-aware. Current implementation of the method checks if the name of the + * {@link CamelContext} matches the names of the known OSGi-aware contexts. * - * @param classFromBundle class to be tested against being deployed into OSGi - * @return true if caller is running in the OSGi environment, false otherwise + * @param camelContext context to be tested against OSGi-awareness + * @return true if given context is OSGi-aware, false otherwise */ - public static boolean isInOsgiEnvironment(Class classFromBundle) { - Bundle bundle = getBundle(classFromBundle); - if (bundle != null) { - LOG.trace("Found OSGi bundle {} for class {} so assuming running in the OSGi container.", - bundle.getSymbolicName(), classFromBundle.getSimpleName()); + public static boolean isOsgiContext(CamelContext camelContext) { + String contextType = camelContext.getClass().getSimpleName(); + if (contextType.startsWith("Osgi") || contextType.equals("BlueprintCamelContext")) { + LOG.trace("{} used - assuming running in the OSGi container.", contextType); return true; } else { - LOG.trace("Cannot find OSGi bundle for class {} so assuming not running in the OSGi container.", - classFromBundle.getSimpleName()); + LOG.trace("{} used - assuming running in the OSGi container.", contextType); return false; } } - public static boolean isInOsgiEnvironment() { - return isInOsgiEnvironment(PlatformHelper.class); - } - -} +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/c34177d7/camel-core/src/test/java/org/apache/camel/util/PlatformHelperTest.java ---------------------------------------------------------------------- diff --git a/camel-core/src/test/java/org/apache/camel/util/PlatformHelperTest.java b/camel-core/src/test/java/org/apache/camel/util/PlatformHelperTest.java index 72fbec0..d70cec5 100644 --- a/camel-core/src/test/java/org/apache/camel/util/PlatformHelperTest.java +++ b/camel-core/src/test/java/org/apache/camel/util/PlatformHelperTest.java @@ -16,16 +16,31 @@ */ package org.apache.camel.util; +import org.apache.camel.impl.DefaultCamelContext; import org.junit.Assert; import org.junit.Test; -import static org.apache.camel.util.PlatformHelper.isInOsgiEnvironment; +import static org.apache.camel.util.PlatformHelper.isOsgiContext; public class PlatformHelperTest extends Assert { @Test - public void shouldNotFindOsgiContext() { - assertFalse(isInOsgiEnvironment()); + public void shouldNotMatchDefaultCamelContext() { + assertFalse(isOsgiContext(new DefaultCamelContext())); } + @Test + public void shouldMatchBlueprintCamelContext() { + assertTrue(isOsgiContext(new BlueprintCamelContext())); + } + + @Test + public void shouldMatchOsgiDefaultCamelContext() { + assertTrue(isOsgiContext(new OsgiDefaultCamelContext())); + } + + private class BlueprintCamelContext extends DefaultCamelContext { } + + private class OsgiDefaultCamelContext extends DefaultCamelContext { } + } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/c34177d7/components/camel-bean-validator/src/main/java/org/apache/camel/component/bean/validator/BeanValidatorComponent.java ---------------------------------------------------------------------- diff --git a/components/camel-bean-validator/src/main/java/org/apache/camel/component/bean/validator/BeanValidatorComponent.java b/components/camel-bean-validator/src/main/java/org/apache/camel/component/bean/validator/BeanValidatorComponent.java index b226263..c50d3b4 100644 --- a/components/camel-bean-validator/src/main/java/org/apache/camel/component/bean/validator/BeanValidatorComponent.java +++ b/components/camel-bean-validator/src/main/java/org/apache/camel/component/bean/validator/BeanValidatorComponent.java @@ -30,8 +30,7 @@ import javax.validation.bootstrap.GenericBootstrap; import org.apache.camel.Endpoint; import org.apache.camel.impl.DefaultComponent; import org.apache.camel.impl.ProcessorEndpoint; - -import static org.apache.camel.util.PlatformHelper.isInOsgiEnvironment; +import org.apache.camel.util.PlatformHelper; /** * Bean Validator Component for validating Java beans against reference implementation of JSR 303 Validator (Hibernate @@ -105,7 +104,7 @@ public class BeanValidatorComponent extends DefaultComponent { * @return true if component is executed in the OSGi environment. False otherwise. */ protected boolean isOsgiContext() { - return isInOsgiEnvironment(); + return PlatformHelper.isOsgiContext(getCamelContext()); } } \ No newline at end of file