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 2015/09/25 16:51:13 UTC

[1/3] camel git commit: Camel-9166

Repository: camel
Updated Branches:
  refs/heads/master 2b6feb622 -> 651b7dda0


Camel-9166


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/745d4c88
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/745d4c88
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/745d4c88

Branch: refs/heads/master
Commit: 745d4c881e8736391c959714797659bf6b39988a
Parents: 2b6feb6
Author: Jyrki Ruuskanen <yu...@kotikone.fi>
Authored: Fri Sep 25 13:27:05 2015 +0300
Committer: Claus Ibsen <da...@apache.org>
Committed: Fri Sep 25 16:40:12 2015 +0200

----------------------------------------------------------------------
 components/camel-scr/pom.xml                    |  1 +
 .../apache/camel/scr/AbstractCamelRunner.java   | 23 +++++----
 .../camel/scr/AbstractCamelRunnerTest.java      | 18 +++----
 .../apache/camel/scr/ConcreteCamelRunner.java   |  3 +-
 .../org/apache/camel/scr/ScrHelperTest.java     | 54 ++++++++++++++++++++
 .../resources/componentDefinitionExample.xml    | 13 +++++
 6 files changed, 91 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/745d4c88/components/camel-scr/pom.xml
----------------------------------------------------------------------
diff --git a/components/camel-scr/pom.xml b/components/camel-scr/pom.xml
index 64e0b77..1e47652 100644
--- a/components/camel-scr/pom.xml
+++ b/components/camel-scr/pom.xml
@@ -31,6 +31,7 @@
 
   <properties>
     <camel.osgi.export.pkg>org.apache.camel.scr</camel.osgi.export.pkg>
+    <camel.osgi.import.camel.version>version="[2.12,$(version;=+;${camel.osgi.version.clean}))"</camel.osgi.import.camel.version>
   </properties>
 
   <dependencies>

http://git-wip-us.apache.org/repos/asf/camel/blob/745d4c88/components/camel-scr/src/main/java/org/apache/camel/scr/AbstractCamelRunner.java
----------------------------------------------------------------------
diff --git a/components/camel-scr/src/main/java/org/apache/camel/scr/AbstractCamelRunner.java b/components/camel-scr/src/main/java/org/apache/camel/scr/AbstractCamelRunner.java
index 32bfe81..e9647ab 100644
--- a/components/camel-scr/src/main/java/org/apache/camel/scr/AbstractCamelRunner.java
+++ b/components/camel-scr/src/main/java/org/apache/camel/scr/AbstractCamelRunner.java
@@ -56,7 +56,10 @@ public abstract class AbstractCamelRunner implements Runnable {
     protected Logger log = LoggerFactory.getLogger(getClass());
     protected CamelContext context;
     protected SimpleRegistry registry = new SimpleRegistry();
-    protected boolean active;
+
+    // Configured fields
+    private String camelContextId;
+    private boolean active;
 
     private ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
     private ScheduledFuture starter;
@@ -82,7 +85,7 @@ public abstract class AbstractCamelRunner implements Runnable {
         // Configure fields from properties
         configure(context, this, log, true);
 
-        setupCamelContext(bundleContext);
+        setupCamelContext(bundleContext, camelContextId);
     }
 
     protected void createCamelContext(final BundleContext bundleContext, final Map<String, String> props) {
@@ -96,18 +99,13 @@ public abstract class AbstractCamelRunner implements Runnable {
             context = new DefaultCamelContext(registry);
         }
         setupPropertiesComponent(context, props, log);
-
-        String name = props.remove("camelContextId");
-        if (name != null) {
-            context.setNameStrategy(new ExplicitCamelContextNameStrategy(name));
-        }
-
-        // ensure we publish this CamelContext to the OSGi service registry
-        context.getManagementStrategy().addEventNotifier(new OsgiCamelContextPublisher(bundleContext));
     }
     
-    protected void setupCamelContext(final BundleContext bundleContext) throws Exception {
+    protected void setupCamelContext(final BundleContext bundleContext, final String camelContextId) throws Exception {
         // Set up CamelContext
+        if (camelContextId != null) {
+            context.setNameStrategy(new ExplicitCamelContextNameStrategy(camelContextId));
+        }
         context.setUseMDCLogging(true);
         context.setUseBreadcrumb(true);
 
@@ -115,6 +113,9 @@ public abstract class AbstractCamelRunner implements Runnable {
         for (RoutesBuilder route : getRouteBuilders()) {
             context.addRoutes(configure(context, route, log));
         }
+
+        // ensure we publish this CamelContext to the OSGi service registry
+        context.getManagementStrategy().addEventNotifier(new OsgiCamelContextPublisher(bundleContext));
     }
 
     public static void setupPropertiesComponent(final CamelContext context, final Map<String, String> props, Logger log) {

http://git-wip-us.apache.org/repos/asf/camel/blob/745d4c88/components/camel-scr/src/test/java/org/apache/camel/scr/AbstractCamelRunnerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-scr/src/test/java/org/apache/camel/scr/AbstractCamelRunnerTest.java b/components/camel-scr/src/test/java/org/apache/camel/scr/AbstractCamelRunnerTest.java
index 5b10b15..f8f64c7 100644
--- a/components/camel-scr/src/test/java/org/apache/camel/scr/AbstractCamelRunnerTest.java
+++ b/components/camel-scr/src/test/java/org/apache/camel/scr/AbstractCamelRunnerTest.java
@@ -38,25 +38,29 @@ public class AbstractCamelRunnerTest {
     public TestName testName = new TestName();
 
     private Logger log = LoggerFactory.getLogger(getClass());
+    private ConcreteCamelRunner integration;
 
     @Before
     public void setUp() throws Exception {
         log.info("*******************************************************************");
         log.info("Test: " + testName.getMethodName());
         log.info("*******************************************************************");
+
+        // Set property prefix for unit testing
+        System.setProperty(AbstractCamelRunner.PROPERTY_PREFIX, "unit");
+
+        // Prepare the integration
+        integration = new ConcreteCamelRunner();
     }
 
     @Test
-    public void testDeepConfigure() throws Exception {
-        ConcreteCamelRunner integration = new ConcreteCamelRunner();
-
+    public void testConfigure() throws Exception {
         integration.activate(null, integration.getDefaultProperties());
-        assertEquals("Overriding camelContextId failed (deep configure)", integration.getDefaultProperties().get("camelContextId"), integration.getContext().getName());
+        assertEquals("Configuring camelContextId with prefix failed", integration.getDefaultProperties().get("unit.camelContextId"), integration.getContext().getName());
     }
 
     @Test
     public void testActivateDeactivate() {
-        ConcreteCamelRunner integration = new ConcreteCamelRunner();
         try {
             integration.activate(null, integration.getDefaultProperties());
             Thread.sleep(AbstractCamelRunner.START_DELAY + 1000);
@@ -72,7 +76,6 @@ public class AbstractCamelRunnerTest {
 
     @Test
     public void testPrepareRunStop() {
-        ConcreteCamelRunner integration = new ConcreteCamelRunner();
         try {
             integration.prepare(null, integration.getDefaultProperties());
             integration.run();
@@ -91,7 +94,6 @@ public class AbstractCamelRunnerTest {
 
     @Test
     public void testDelayedStart() {
-        ConcreteCamelRunner integration = new ConcreteCamelRunner();
         try {
             integration.activate(null, integration.getDefaultProperties());
             Thread.sleep(2000);
@@ -111,8 +113,6 @@ public class AbstractCamelRunnerTest {
 
     @Test
     public void testDelayedStartCancel() {
-        ConcreteCamelRunner integration = new ConcreteCamelRunner();
-
         Map<String, String> properties = integration.getDefaultProperties();
         properties.put("from", "notfound:something");
         properties.put("camelroute.id", "test/notfound-mock");

http://git-wip-us.apache.org/repos/asf/camel/blob/745d4c88/components/camel-scr/src/test/java/org/apache/camel/scr/ConcreteCamelRunner.java
----------------------------------------------------------------------
diff --git a/components/camel-scr/src/test/java/org/apache/camel/scr/ConcreteCamelRunner.java b/components/camel-scr/src/test/java/org/apache/camel/scr/ConcreteCamelRunner.java
index 0ad1123..b1a7090 100644
--- a/components/camel-scr/src/test/java/org/apache/camel/scr/ConcreteCamelRunner.java
+++ b/components/camel-scr/src/test/java/org/apache/camel/scr/ConcreteCamelRunner.java
@@ -45,7 +45,8 @@ public class ConcreteCamelRunner extends AbstractCamelRunner implements Lifecycl
     public Map<String, String> getDefaultProperties() {
         // Set default properties
         Map<String, String> defaultProps = new HashMap<String, String>();
-        defaultProps.put("camelContextId", "camel-runner-test");
+        defaultProps.put("camelContextId", "camel-runner");
+        defaultProps.put("unit.camelContextId", "camel-runner-unitTest");
         defaultProps.put("camelRouteId", "test/direct-mock");
         defaultProps.put("active", "true");
         defaultProps.put("from", "direct:start");

http://git-wip-us.apache.org/repos/asf/camel/blob/745d4c88/components/camel-scr/src/test/java/org/apache/camel/scr/ScrHelperTest.java
----------------------------------------------------------------------
diff --git a/components/camel-scr/src/test/java/org/apache/camel/scr/ScrHelperTest.java b/components/camel-scr/src/test/java/org/apache/camel/scr/ScrHelperTest.java
new file mode 100644
index 0000000..e80e208
--- /dev/null
+++ b/components/camel-scr/src/test/java/org/apache/camel/scr/ScrHelperTest.java
@@ -0,0 +1,54 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.scr;
+
+import java.util.Map;
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TestName;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+@RunWith(JUnit4.class)
+public class ScrHelperTest {
+
+    @Rule
+    public TestName testName = new TestName();
+
+    private Logger log = LoggerFactory.getLogger(getClass());
+
+    @Before
+    public void setUp() throws Exception {
+        log.info("*******************************************************************");
+        log.info("Test: " + testName.getMethodName());
+        log.info("*******************************************************************");
+    }
+
+    @Test
+    public void scrHelperTest() throws Exception {
+        Map<String, String> properties = ScrHelper.getScrProperties("src/test/resources/componentDefinitionExample.xml", "my.example.Component");
+        assertEquals("exampleContext", properties.get("camelContextId"));
+        assertTrue(properties.size() == 6);
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/745d4c88/components/camel-scr/src/test/resources/componentDefinitionExample.xml
----------------------------------------------------------------------
diff --git a/components/camel-scr/src/test/resources/componentDefinitionExample.xml b/components/camel-scr/src/test/resources/componentDefinitionExample.xml
new file mode 100644
index 0000000..162ca9c
--- /dev/null
+++ b/components/camel-scr/src/test/resources/componentDefinitionExample.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<components xmlns:scr="http://www.osgi.org/xmlns/scr/v1.2.0">
+    <scr:component immediate="true" name="my.example.Component">
+        <implementation class="my.example.Component"/>
+        <property name="camelContextId" value="exampleContext"/>
+        <property name="unit.camelContextId" value="exampleContextForUnitTest"/>
+        <property name="camelRouteId" value="{{camelContextId}}/timer-log"/>
+        <property name="active" value="true"/>
+        <property name="master" value="master:{{camelContextId}}"/>
+        <property name="service.pid" value="my.example.Component"/>
+        <reference name="camelComponent" interface="org.apache.camel.spi.ComponentResolver" cardinality="1..n" policy="dynamic" bind="gotCamelComponent" unbind="lostCamelComponent" policy-option="greedy"/>
+    </scr:component>
+</components>


[3/3] camel git commit: CAMEL-9166: Polished. This fixes #620.

Posted by da...@apache.org.
CAMEL-9166: Polished. This fixes #620.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/651b7dda
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/651b7dda
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/651b7dda

Branch: refs/heads/master
Commit: 651b7dda066a9b0949c8f2a0d313769b68e50593
Parents: 397a39b
Author: Claus Ibsen <da...@apache.org>
Authored: Fri Sep 25 16:51:34 2015 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Fri Sep 25 16:51:59 2015 +0200

----------------------------------------------------------------------
 components/camel-scr/pom.xml                     |  1 -
 .../apache/camel/scr/AbstractCamelRunner.java    | 19 ++++++++++++-------
 2 files changed, 12 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/651b7dda/components/camel-scr/pom.xml
----------------------------------------------------------------------
diff --git a/components/camel-scr/pom.xml b/components/camel-scr/pom.xml
index 1e47652..64e0b77 100644
--- a/components/camel-scr/pom.xml
+++ b/components/camel-scr/pom.xml
@@ -31,7 +31,6 @@
 
   <properties>
     <camel.osgi.export.pkg>org.apache.camel.scr</camel.osgi.export.pkg>
-    <camel.osgi.import.camel.version>version="[2.12,$(version;=+;${camel.osgi.version.clean}))"</camel.osgi.import.camel.version>
   </properties>
 
   <dependencies>

http://git-wip-us.apache.org/repos/asf/camel/blob/651b7dda/components/camel-scr/src/main/java/org/apache/camel/scr/AbstractCamelRunner.java
----------------------------------------------------------------------
diff --git a/components/camel-scr/src/main/java/org/apache/camel/scr/AbstractCamelRunner.java b/components/camel-scr/src/main/java/org/apache/camel/scr/AbstractCamelRunner.java
index c4be591..478afe7 100644
--- a/components/camel-scr/src/main/java/org/apache/camel/scr/AbstractCamelRunner.java
+++ b/components/camel-scr/src/main/java/org/apache/camel/scr/AbstractCamelRunner.java
@@ -38,11 +38,12 @@ import org.apache.camel.RoutesBuilder;
 import org.apache.camel.component.properties.PropertiesComponent;
 import org.apache.camel.core.osgi.OsgiCamelContextPublisher;
 import org.apache.camel.core.osgi.OsgiDefaultCamelContext;
+import org.apache.camel.core.osgi.OsgiServiceRegistry;
 import org.apache.camel.core.osgi.utils.BundleDelegatingClassLoader;
 import org.apache.camel.impl.DefaultCamelContext;
 import org.apache.camel.impl.ExplicitCamelContextNameStrategy;
 import org.apache.camel.impl.SimpleRegistry;
-import org.apache.camel.model.ModelCamelContext;
+import org.apache.camel.spi.Registry;
 import org.apache.camel.util.ReflectionHelper;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceReference;
@@ -55,8 +56,8 @@ public abstract class AbstractCamelRunner implements Runnable {
     public static final String PROPERTY_PREFIX = "camel.scr.properties.prefix";
     
     protected Logger log = LoggerFactory.getLogger(getClass());
-    protected ModelCamelContext context;
-    protected SimpleRegistry registry = new SimpleRegistry();
+    protected CamelContext context;
+    protected Registry registry;
 
     // Configured fields
     private String camelContextId;
@@ -91,12 +92,14 @@ public abstract class AbstractCamelRunner implements Runnable {
 
     protected void createCamelContext(final BundleContext bundleContext, final Map<String, String> props) {
         if (bundleContext != null) {
+            registry = new OsgiServiceRegistry(bundleContext);
             context = new OsgiDefaultCamelContext(bundleContext, registry);
             // Setup the application context classloader with the bundle classloader
             context.setApplicationContextClassLoader(new BundleDelegatingClassLoader(bundleContext.getBundle()));
             // and make sure the TCCL is our classloader
             Thread.currentThread().setContextClassLoader(context.getApplicationContextClassLoader());
         } else {
+            registry = new SimpleRegistry();
             context = new DefaultCamelContext(registry);
         }
         setupPropertiesComponent(context, props, log);
@@ -107,6 +110,7 @@ public abstract class AbstractCamelRunner implements Runnable {
         if (camelContextId != null) {
             context.setNameStrategy(new ExplicitCamelContextNameStrategy(camelContextId));
         }
+        // TODO: allow to configure these options and not hardcode
         context.setUseMDCLogging(true);
         context.setUseBreadcrumb(true);
 
@@ -129,11 +133,11 @@ public abstract class AbstractCamelRunner implements Runnable {
         }
 
         // Set property prefix
-        if (null != System.getProperty(PROPERTY_PREFIX)) {
+        if (System.getProperty(PROPERTY_PREFIX) != null) {
             pc.setPropertyPrefix(System.getProperty(PROPERTY_PREFIX) + ".");
         }
 
-        if (null != props) {
+        if (props != null) {
             Properties initialProps = new Properties();
             initialProps.putAll(props);
             log.debug(String.format("Added %d initial properties", props.size()));
@@ -197,6 +201,7 @@ public abstract class AbstractCamelRunner implements Runnable {
             context.start();
             started = true;
         } catch (Exception e) {
+            // LOL so the best we can do is to try to start every 5th second and cross our fingers - yeah OSGi is lovely ;(
             log.warn("Failed to start Camel context. Will try again when more Camel components have been registered.", e);
         }
     }
@@ -208,7 +213,7 @@ public abstract class AbstractCamelRunner implements Runnable {
         try {
             context.stop();
         } catch (Exception e) {
-            log.error("Failed to stop Camel context.", e);
+            log.warn("Failed to stop Camel context.", e);
         } finally {
             // Even if stopping failed we consider Camel context stopped
             started = false;
@@ -257,7 +262,7 @@ public abstract class AbstractCamelRunner implements Runnable {
                     log.debug("Configured field {} with value {}", field.getName(), propertyValue);
                 }
             } catch (Exception e) {
-                log.error("Error setting field " + field.getName() + " due: " + e.getMessage() + ". This exception is ignored.", e);
+                log.warn("Error setting field " + field.getName() + " due: " + e.getMessage() + ". This exception is ignored.", e);
             }
         }
         return target;


[2/3] camel git commit: Reverted ABI change in AbstractCamelRunner

Posted by da...@apache.org.
Reverted ABI change in AbstractCamelRunner


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/397a39b8
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/397a39b8
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/397a39b8

Branch: refs/heads/master
Commit: 397a39b885ec7bb921e9253b72957d54d9735a8a
Parents: 745d4c8
Author: Jyrki Ruuskanen <yu...@kotikone.fi>
Authored: Fri Sep 25 13:53:59 2015 +0300
Committer: Claus Ibsen <da...@apache.org>
Committed: Fri Sep 25 16:40:13 2015 +0200

----------------------------------------------------------------------
 .../src/main/java/org/apache/camel/scr/AbstractCamelRunner.java   | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/397a39b8/components/camel-scr/src/main/java/org/apache/camel/scr/AbstractCamelRunner.java
----------------------------------------------------------------------
diff --git a/components/camel-scr/src/main/java/org/apache/camel/scr/AbstractCamelRunner.java b/components/camel-scr/src/main/java/org/apache/camel/scr/AbstractCamelRunner.java
index e9647ab..c4be591 100644
--- a/components/camel-scr/src/main/java/org/apache/camel/scr/AbstractCamelRunner.java
+++ b/components/camel-scr/src/main/java/org/apache/camel/scr/AbstractCamelRunner.java
@@ -42,6 +42,7 @@ import org.apache.camel.core.osgi.utils.BundleDelegatingClassLoader;
 import org.apache.camel.impl.DefaultCamelContext;
 import org.apache.camel.impl.ExplicitCamelContextNameStrategy;
 import org.apache.camel.impl.SimpleRegistry;
+import org.apache.camel.model.ModelCamelContext;
 import org.apache.camel.util.ReflectionHelper;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceReference;
@@ -54,7 +55,7 @@ public abstract class AbstractCamelRunner implements Runnable {
     public static final String PROPERTY_PREFIX = "camel.scr.properties.prefix";
     
     protected Logger log = LoggerFactory.getLogger(getClass());
-    protected CamelContext context;
+    protected ModelCamelContext context;
     protected SimpleRegistry registry = new SimpleRegistry();
 
     // Configured fields