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 2016/04/24 11:35:23 UTC
camel git commit: CAMEL-9872: VetoCamelContextStartException with
rethrowException=false cases MainSupport class to hang
Repository: camel
Updated Branches:
refs/heads/master 5214e6891 -> d600abe87
CAMEL-9872: VetoCamelContextStartException with rethrowException=false cases MainSupport class to hang
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/d600abe8
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/d600abe8
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/d600abe8
Branch: refs/heads/master
Commit: d600abe87f20c1e9fd5fcc3941968402f1436920
Parents: 5214e68
Author: Claus Ibsen <da...@apache.org>
Authored: Sun Apr 24 11:35:14 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Sun Apr 24 11:35:14 2016 +0200
----------------------------------------------------------------------
.../camel/spring/CamelContextFactoryBean.java | 4 +-
.../main/java/org/apache/camel/spring/Main.java | 37 ++++++++++------
.../spring/handler/CamelNamespaceHandler.java | 2 +-
.../org/apache/camel/spring/MainVetoTest.java | 46 ++++++++++++++++++++
.../apache/camel/spring/MyVetoLifecycle.java | 30 +++++++++++++
...CamelContextLogExhaustedMessageBodyTest.java | 6 +--
.../org/apache/camel/spring/MainVetoTest.xml | 34 +++++++++++++++
7 files changed, 139 insertions(+), 20 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/d600abe8/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java b/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
index 6179724..5f94f6b 100644
--- a/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
+++ b/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
@@ -16,8 +16,6 @@
*/
package org.apache.camel.spring;
-import static org.apache.camel.util.ObjectHelper.wrapRuntimeCamelException;
-
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -77,6 +75,8 @@ import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
+import static org.apache.camel.util.ObjectHelper.wrapRuntimeCamelException;
+
/**
* A Spring {@link FactoryBean} to create and initialize a
* {@link SpringCamelContext} and install routes either explicitly configured in
http://git-wip-us.apache.org/repos/asf/camel/blob/d600abe8/components/camel-spring/src/main/java/org/apache/camel/spring/Main.java
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/main/java/org/apache/camel/spring/Main.java b/components/camel-spring/src/main/java/org/apache/camel/spring/Main.java
index 1b45e8d..6ca9003 100644
--- a/components/camel-spring/src/main/java/org/apache/camel/spring/Main.java
+++ b/components/camel-spring/src/main/java/org/apache/camel/spring/Main.java
@@ -148,24 +148,33 @@ public class Main extends MainSupport {
@Override
protected void doStart() throws Exception {
- super.doStart();
- if (applicationContext == null) {
- applicationContext = createDefaultApplicationContext();
- }
+ try {
+ super.doStart();
+ if (applicationContext == null) {
+ applicationContext = createDefaultApplicationContext();
+ }
- // then start any additional after Camel has been started
- if (additionalApplicationContext == null) {
- additionalApplicationContext = createAdditionalLocationsFromClasspath();
- if (additionalApplicationContext != null) {
- LOG.debug("Starting Additional ApplicationContext: " + additionalApplicationContext.getId());
- additionalApplicationContext.start();
+ // then start any additional after Camel has been started
+ if (additionalApplicationContext == null) {
+ additionalApplicationContext = createAdditionalLocationsFromClasspath();
+ if (additionalApplicationContext != null) {
+ LOG.debug("Starting Additional ApplicationContext: " + additionalApplicationContext.getId());
+ additionalApplicationContext.start();
+ }
}
- }
- LOG.debug("Starting Spring ApplicationContext: " + applicationContext.getId());
- applicationContext.start();
+ LOG.debug("Starting Spring ApplicationContext: " + applicationContext.getId());
+ applicationContext.start();
- postProcessContext();
+ postProcessContext();
+ } finally {
+ if (camelContexts != null && !camelContexts.isEmpty()) {
+ // if we were veto started then mark as completed
+ if (getCamelContexts().get(0).isVetoStarted()) {
+ completed();
+ }
+ }
+ }
}
protected void doStop() throws Exception {
http://git-wip-us.apache.org/repos/asf/camel/blob/d600abe8/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java b/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java
index c6b938d..fd062a0 100644
--- a/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java
+++ b/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java
@@ -26,7 +26,6 @@ import javax.xml.bind.Binder;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
-import org.apache.camel.model.HystrixConfigurationDefinition;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
@@ -39,6 +38,7 @@ import org.apache.camel.core.xml.CamelPropertyPlaceholderDefinition;
import org.apache.camel.core.xml.CamelStreamCachingStrategyDefinition;
import org.apache.camel.impl.DefaultCamelContextNameStrategy;
import org.apache.camel.model.FromDefinition;
+import org.apache.camel.model.HystrixConfigurationDefinition;
import org.apache.camel.model.SendDefinition;
import org.apache.camel.spi.CamelContextNameStrategy;
import org.apache.camel.spi.NamespaceAware;
http://git-wip-us.apache.org/repos/asf/camel/blob/d600abe8/components/camel-spring/src/test/java/org/apache/camel/spring/MainVetoTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/java/org/apache/camel/spring/MainVetoTest.java b/components/camel-spring/src/test/java/org/apache/camel/spring/MainVetoTest.java
new file mode 100644
index 0000000..bbe23da
--- /dev/null
+++ b/components/camel-spring/src/test/java/org/apache/camel/spring/MainVetoTest.java
@@ -0,0 +1,46 @@
+/**
+ * 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.spring;
+
+import junit.framework.TestCase;
+import org.apache.camel.CamelContext;
+import org.apache.camel.VetoCamelContextStartException;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.support.LifecycleStrategySupport;
+import org.junit.Test;
+
+/**
+ * @version
+ */
+public class MainVetoTest extends TestCase {
+
+ @Test
+ public void testMain() throws Exception {
+ // lets make a simple route
+ Main main = new Main();
+ main.setDuration(30);
+ main.setDurationHitExitCode(99);
+ main.setApplicationContextUri("org/apache/camel/spring/MainVetoTest.xml");
+
+ // should not hang as we veto fail
+ main.run();
+
+ // should complete normally due veto
+ assertEquals(0, main.getExitCode());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/d600abe8/components/camel-spring/src/test/java/org/apache/camel/spring/MyVetoLifecycle.java
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/java/org/apache/camel/spring/MyVetoLifecycle.java b/components/camel-spring/src/test/java/org/apache/camel/spring/MyVetoLifecycle.java
new file mode 100644
index 0000000..4aaa134
--- /dev/null
+++ b/components/camel-spring/src/test/java/org/apache/camel/spring/MyVetoLifecycle.java
@@ -0,0 +1,30 @@
+/**
+ * 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.spring;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.VetoCamelContextStartException;
+import org.apache.camel.support.LifecycleStrategySupport;
+
+public class MyVetoLifecycle extends LifecycleStrategySupport {
+
+ @Override
+ public void onContextStart(CamelContext context) throws VetoCamelContextStartException {
+ throw new VetoCamelContextStartException("We do not like this route", context, false);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/d600abe8/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringCamelContextLogExhaustedMessageBodyTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringCamelContextLogExhaustedMessageBodyTest.java b/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringCamelContextLogExhaustedMessageBodyTest.java
index efdd033..33a81d9 100644
--- a/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringCamelContextLogExhaustedMessageBodyTest.java
+++ b/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringCamelContextLogExhaustedMessageBodyTest.java
@@ -5,9 +5,9 @@
* 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
- * <p>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p>
+ *
+ * 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.
http://git-wip-us.apache.org/repos/asf/camel/blob/d600abe8/components/camel-spring/src/test/resources/org/apache/camel/spring/MainVetoTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/resources/org/apache/camel/spring/MainVetoTest.xml b/components/camel-spring/src/test/resources/org/apache/camel/spring/MainVetoTest.xml
new file mode 100644
index 0000000..376d2fb
--- /dev/null
+++ b/components/camel-spring/src/test/resources/org/apache/camel/spring/MainVetoTest.xml
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
+ ">
+
+ <bean id="lifecycleStrategy" class="org.apache.camel.spring.MyVetoLifecycle"/>
+
+ <camelContext xmlns="http://camel.apache.org/schema/spring">
+ <route>
+ <from uri="direct:start"/>
+ <to uri="mock:result"/>
+ </route>
+ </camelContext>
+
+</beans>