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 2017/06/14 17:26:32 UTC
[1/2] camel git commit: CAMEL-11410: camel-spring - Should not list
uris as spring bean ids from Camel routes
Repository: camel
Updated Branches:
refs/heads/master 70d4e52ce -> 891148417
CAMEL-11410: camel-spring - Should not list uris as spring bean ids from Camel routes
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/78fea48d
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/78fea48d
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/78fea48d
Branch: refs/heads/master
Commit: 78fea48d0fe350fae4fecc9d4b5f690e3026754b
Parents: 70d4e52
Author: Claus Ibsen <da...@apache.org>
Authored: Wed Jun 14 15:25:09 2017 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Wed Jun 14 15:25:16 2017 +0200
----------------------------------------------------------------------
.../spring/handler/CamelNamespaceHandler.java | 3 +-
.../spring/CircularComponentInjectionTest.java | 3 +-
.../camel/spring/NodeIdReferenceTest.java | 2 +-
.../CircularComponentInjectionTest-context.xml | 6 ++--
.../spring/NodeIdReferenceTest-context.xml | 15 +++++-----
...merTemplateOutOfCamelContextTest-context.xml | 17 ++++++------
.../SpringConsumerTemplateTest-context.xml | 29 ++++++++++----------
.../SpringJmxEndpointInjectBeanRefTest.xml | 4 ++-
8 files changed, 44 insertions(+), 35 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/78fea48d/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 2b89d44..43afb2b 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
@@ -440,7 +440,7 @@ public class CamelNamespaceHandler extends NamespaceHandlerSupport {
}
// register as endpoint defined indirectly in the routes by from/to types having id explicit set
- registerEndpointsWithIdsDefinedInFromOrToTypes(element, parserContext, contextId, binder);
+ // registerEndpointsWithIdsDefinedInFromOrToTypes(element, parserContext, contextId, binder);
// register templates if not already defined
registerTemplates(element, parserContext, contextId);
@@ -534,6 +534,7 @@ public class CamelNamespaceHandler extends NamespaceHandlerSupport {
/**
* Used for auto registering endpoints from the <tt>from</tt> or <tt>to</tt> DSL if they have an id attribute set
*/
+ @Deprecated
protected void registerEndpointsWithIdsDefinedInFromOrToTypes(Element element, ParserContext parserContext, String contextId, Binder<Node> binder) {
NodeList list = element.getChildNodes();
int size = list.getLength();
http://git-wip-us.apache.org/repos/asf/camel/blob/78fea48d/components/camel-spring/src/test/java/org/apache/camel/spring/CircularComponentInjectionTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/java/org/apache/camel/spring/CircularComponentInjectionTest.java b/components/camel-spring/src/test/java/org/apache/camel/spring/CircularComponentInjectionTest.java
index 92500b7..eea1059 100644
--- a/components/camel-spring/src/test/java/org/apache/camel/spring/CircularComponentInjectionTest.java
+++ b/components/camel-spring/src/test/java/org/apache/camel/spring/CircularComponentInjectionTest.java
@@ -16,7 +16,6 @@
*/
package org.apache.camel.spring;
-
import org.apache.camel.Endpoint;
import org.apache.camel.EndpointInject;
import org.junit.Assert;
@@ -26,8 +25,10 @@ import org.springframework.test.context.ContextConfiguration;
@ContextConfiguration
public class CircularComponentInjectionTest extends SpringRunWithTestSupport {
+
@EndpointInject(ref = "seda")
protected Endpoint sedaEndpoint;
+
@EndpointInject(ref = "log")
protected Endpoint logEndpoint;
http://git-wip-us.apache.org/repos/asf/camel/blob/78fea48d/components/camel-spring/src/test/java/org/apache/camel/spring/NodeIdReferenceTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/java/org/apache/camel/spring/NodeIdReferenceTest.java b/components/camel-spring/src/test/java/org/apache/camel/spring/NodeIdReferenceTest.java
index 0e96717..33613d0 100644
--- a/components/camel-spring/src/test/java/org/apache/camel/spring/NodeIdReferenceTest.java
+++ b/components/camel-spring/src/test/java/org/apache/camel/spring/NodeIdReferenceTest.java
@@ -29,7 +29,7 @@ import org.springframework.test.context.ContextConfiguration;
*/
@ContextConfiguration
public class NodeIdReferenceTest extends SpringRunWithTestSupport {
- protected String expectedBody = "Godday World";
+ protected String expectedBody = "Hi World";
@Autowired
protected ProducerTemplate producer;
http://git-wip-us.apache.org/repos/asf/camel/blob/78fea48d/components/camel-spring/src/test/resources/org/apache/camel/spring/CircularComponentInjectionTest-context.xml
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/resources/org/apache/camel/spring/CircularComponentInjectionTest-context.xml b/components/camel-spring/src/test/resources/org/apache/camel/spring/CircularComponentInjectionTest-context.xml
index 4b72c4c..8d7b06e 100644
--- a/components/camel-spring/src/test/resources/org/apache/camel/spring/CircularComponentInjectionTest-context.xml
+++ b/components/camel-spring/src/test/resources/org/apache/camel/spring/CircularComponentInjectionTest-context.xml
@@ -26,9 +26,11 @@
http://camel.apache.org/schema/spring/camel-spring.xsd">
<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
+ <endpoint id="log" uri="seda:test"/>
+ <endpoint id="seda" uri="log:test"/>
<route>
- <from id="log" uri="seda:test"/>
- <to id="seda" uri="log:test"/>
+ <from uri="ref:log"/>
+ <to uri="ref:seda"/>
</route>
</camelContext>
http://git-wip-us.apache.org/repos/asf/camel/blob/78fea48d/components/camel-spring/src/test/resources/org/apache/camel/spring/NodeIdReferenceTest-context.xml
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/resources/org/apache/camel/spring/NodeIdReferenceTest-context.xml b/components/camel-spring/src/test/resources/org/apache/camel/spring/NodeIdReferenceTest-context.xml
index 52bae91..27b6434 100644
--- a/components/camel-spring/src/test/resources/org/apache/camel/spring/NodeIdReferenceTest-context.xml
+++ b/components/camel-spring/src/test/resources/org/apache/camel/spring/NodeIdReferenceTest-context.xml
@@ -24,13 +24,14 @@
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
">
- <camelContext xmlns="http://camel.apache.org/schema/spring">
- <template id="camelTemplate"/>
+ <camelContext xmlns="http://camel.apache.org/schema/spring">
+ <template id="camelTemplate"/>
+ <endpoint id="foo" uri="direct:start"/>
- <route>
- <from id="foo" uri="direct:start"/>
- <to uri="mock:result"/>
- </route>
- </camelContext>
+ <route>
+ <from uri="ref:foo"/>
+ <to uri="mock:result"/>
+ </route>
+ </camelContext>
</beans>
http://git-wip-us.apache.org/repos/asf/camel/blob/78fea48d/components/camel-spring/src/test/resources/org/apache/camel/spring/SpringConsumerTemplateOutOfCamelContextTest-context.xml
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/resources/org/apache/camel/spring/SpringConsumerTemplateOutOfCamelContextTest-context.xml b/components/camel-spring/src/test/resources/org/apache/camel/spring/SpringConsumerTemplateOutOfCamelContextTest-context.xml
index 5001c78..1e04125 100644
--- a/components/camel-spring/src/test/resources/org/apache/camel/spring/SpringConsumerTemplateOutOfCamelContextTest-context.xml
+++ b/components/camel-spring/src/test/resources/org/apache/camel/spring/SpringConsumerTemplateOutOfCamelContextTest-context.xml
@@ -25,14 +25,15 @@
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
">
- <camelContext id="myCamel" xmlns="http://camel.apache.org/schema/spring">
- <route>
- <from uri="seda:foo"/>
- <to id="result" uri="mock:result"/>
- </route>
- </camelContext>
+ <camelContext id="myCamel" xmlns="http://camel.apache.org/schema/spring">
+ <endpoint id="result" uri="mock:result"/>
+ <route>
+ <from uri="seda:foo"/>
+ <to uri="ref:result"/>
+ </route>
+ </camelContext>
- <camel:template id="template" camelContextId="myCamel"/>
- <camel:consumerTemplate id="consumerTemplate" camelContextId="myCamel"/>
+ <camel:template id="template" camelContextId="myCamel"/>
+ <camel:consumerTemplate id="consumerTemplate" camelContextId="myCamel"/>
</beans>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/78fea48d/components/camel-spring/src/test/resources/org/apache/camel/spring/SpringConsumerTemplateTest-context.xml
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/resources/org/apache/camel/spring/SpringConsumerTemplateTest-context.xml b/components/camel-spring/src/test/resources/org/apache/camel/spring/SpringConsumerTemplateTest-context.xml
index a46d834..b4d46e2 100644
--- a/components/camel-spring/src/test/resources/org/apache/camel/spring/SpringConsumerTemplateTest-context.xml
+++ b/components/camel-spring/src/test/resources/org/apache/camel/spring/SpringConsumerTemplateTest-context.xml
@@ -19,24 +19,25 @@
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:camel="http://camel.apache.org/schema/spring"
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
">
- <!-- START SNIPPET: e1 -->
- <camelContext xmlns="http://camel.apache.org/schema/spring">
- <!-- define a producer template -->
- <template id="producer"/>
- <!-- define a consumer template -->
- <consumerTemplate id="consumer"/>
-
- <route>
- <from uri="seda:foo"/>
- <to id="result" uri="mock:result"/>
- </route>
- </camelContext>
- <!-- END SNIPPET: e1 -->
+ <!-- START SNIPPET: e1 -->
+ <camelContext xmlns="http://camel.apache.org/schema/spring">
+ <!-- define a producer template -->
+ <template id="producer"/>
+ <!-- define a consumer template -->
+ <consumerTemplate id="consumer"/>
+ <!-- define endpoint -->
+ <endpoint id="result" uri="mock:result"/>
+
+ <route>
+ <from uri="seda:foo"/>
+ <to uri="ref:result"/>
+ </route>
+ </camelContext>
+ <!-- END SNIPPET: e1 -->
</beans>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/78fea48d/components/camel-spring/src/test/resources/org/apache/camel/spring/management/SpringJmxEndpointInjectBeanRefTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/resources/org/apache/camel/spring/management/SpringJmxEndpointInjectBeanRefTest.xml b/components/camel-spring/src/test/resources/org/apache/camel/spring/management/SpringJmxEndpointInjectBeanRefTest.xml
index 6914be7..659c8df 100644
--- a/components/camel-spring/src/test/resources/org/apache/camel/spring/management/SpringJmxEndpointInjectBeanRefTest.xml
+++ b/components/camel-spring/src/test/resources/org/apache/camel/spring/management/SpringJmxEndpointInjectBeanRefTest.xml
@@ -29,13 +29,15 @@
<!-- enable JMX -->
<jmxAgent id="agent" disabled="false"/>
+ <endpoint id="foo" uri="seda:foo"/>
+
<route>
<from uri="direct:start"/>
<to uri="bean:myBean"/>
</route>
<route>
- <from uri="seda:foo" id="foo"/>
+ <from uri="ref:foo"/>
<to uri="mock:result"/>
</route>
[2/2] camel git commit: CAMEL-11410: camel-spring - Should not list
uris as spring bean ids from Camel routes
Posted by da...@apache.org.
CAMEL-11410: camel-spring - Should not list uris as spring bean ids from Camel routes
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/89114841
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/89114841
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/89114841
Branch: refs/heads/master
Commit: 891148417e1e82120b9220d83fa53fe391676f36
Parents: 78fea48
Author: Claus Ibsen <da...@apache.org>
Authored: Wed Jun 14 16:01:07 2017 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Wed Jun 14 16:01:07 2017 +0200
----------------------------------------------------------------------
.../camel/spring/CamelContextFactoryBean.java | 16 ++++++
.../spring/handler/CamelNamespaceHandler.java | 15 +++++-
.../camel/spring/NodeIdReferenceLegacyTest.java | 52 ++++++++++++++++++++
.../NodeIdReferenceLegacyTest-context.xml | 36 ++++++++++++++
4 files changed, 117 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/89114841/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 eb79196..fd47daf 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
@@ -121,6 +121,9 @@ public class CamelContextFactoryBean extends AbstractCamelContextFactoryBean<Spr
private String autoStartup;
@XmlAttribute @Metadata(defaultValue = "true")
private String shutdownEager;
+ @XmlAttribute @Metadata(defaultValue = "false")
+ @Deprecated
+ private String registerEndpointIdsFromRoute;
@XmlAttribute
private String useMDCLogging;
@XmlAttribute
@@ -758,6 +761,19 @@ public class CamelContextFactoryBean extends AbstractCamelContextFactoryBean<Spr
this.shutdownEager = shutdownEager;
}
+ public String getRegisterEndpointIdsFromRoute() {
+ return registerEndpointIdsFromRoute;
+ }
+
+ /**
+ * Sets whether to register endpoints that has id attribute assigned in the Spring registry.
+ * <p/>
+ * This mode is by default false, but can be turned on for backwards compatibility.
+ */
+ public void setRegisterEndpointIdsFromRoute(String registerEndpointIdsFromRoute) {
+ this.registerEndpointIdsFromRoute = registerEndpointIdsFromRoute;
+ }
+
public String getUseMDCLogging() {
return useMDCLogging;
}
http://git-wip-us.apache.org/repos/asf/camel/blob/89114841/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 43afb2b..9ecdf6c 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
@@ -350,6 +350,7 @@ public class CamelNamespaceHandler extends NamespaceHandlerSupport {
String contextId = element.getAttribute("id");
boolean implicitId = false;
+ boolean registerEndpointIdsFromRoute = false;
// lets avoid folks having to explicitly give an ID to a camel context
if (ObjectHelper.isEmpty(contextId)) {
@@ -407,6 +408,8 @@ public class CamelNamespaceHandler extends NamespaceHandlerSupport {
builder.addPropertyValue("hystrixConfigurations", factoryBean.getHystrixConfigurations());
// add any depends-on
addDependsOn(factoryBean, builder);
+
+ registerEndpointIdsFromRoute = "true".equalsIgnoreCase(factoryBean.getRegisterEndpointIdsFromRoute());
}
NodeList list = element.getChildNodes();
@@ -439,8 +442,11 @@ public class CamelNamespaceHandler extends NamespaceHandlerSupport {
}
}
- // register as endpoint defined indirectly in the routes by from/to types having id explicit set
- // registerEndpointsWithIdsDefinedInFromOrToTypes(element, parserContext, contextId, binder);
+ if (registerEndpointIdsFromRoute) {
+ // register as endpoint defined indirectly in the routes by from/to types having id explicit set
+ LOG.debug("Registering endpoint with ids defined in Camel routes");
+ registerEndpointsWithIdsDefinedInFromOrToTypes(element, parserContext, contextId, binder);
+ }
// register templates if not already defined
registerTemplates(element, parserContext, contextId);
@@ -689,6 +695,11 @@ public class CamelNamespaceHandler extends NamespaceHandlerSupport {
String id = childElement.getAttribute("id");
// must have an id to be registered
if (ObjectHelper.isNotEmpty(id)) {
+ // skip underscore as they are internal naming and should not be registered
+ if (id.startsWith("_")) {
+ LOG.debug("Skip registering endpoint starting with underscore: {}", id);
+ return;
+ }
BeanDefinition definition = endpointParser.parse(childElement, parserContext);
definition.getPropertyValues().addPropertyValue("camelContext", new RuntimeBeanReference(contextId));
// Need to add this dependency of CamelContext for Spring 3.0
http://git-wip-us.apache.org/repos/asf/camel/blob/89114841/components/camel-spring/src/test/java/org/apache/camel/spring/NodeIdReferenceLegacyTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/java/org/apache/camel/spring/NodeIdReferenceLegacyTest.java b/components/camel-spring/src/test/java/org/apache/camel/spring/NodeIdReferenceLegacyTest.java
new file mode 100644
index 0000000..044169d
--- /dev/null
+++ b/components/camel-spring/src/test/java/org/apache/camel/spring/NodeIdReferenceLegacyTest.java
@@ -0,0 +1,52 @@
+/**
+ * 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.Endpoint;
+import org.apache.camel.EndpointInject;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.ContextConfiguration;
+
+/**
+ * @version
+ */
+@ContextConfiguration
+public class NodeIdReferenceLegacyTest extends SpringRunWithTestSupport {
+ protected String expectedBody = "Bye World";
+
+ @Autowired
+ protected ProducerTemplate producer;
+
+ @EndpointInject(ref = "foo")
+ protected Endpoint start;
+
+ @EndpointInject(uri = "mock:result")
+ protected MockEndpoint result;
+
+ @Test
+ public void testNodeIdReferenceLegacy() throws Exception {
+ result.expectedBodiesReceived(expectedBody);
+
+ producer.sendBody(start, expectedBody);
+
+ result.assertIsSatisfied();
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/89114841/components/camel-spring/src/test/resources/org/apache/camel/spring/NodeIdReferenceLegacyTest-context.xml
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/resources/org/apache/camel/spring/NodeIdReferenceLegacyTest-context.xml b/components/camel-spring/src/test/resources/org/apache/camel/spring/NodeIdReferenceLegacyTest-context.xml
new file mode 100644
index 0000000..fefb292
--- /dev/null
+++ b/components/camel-spring/src/test/resources/org/apache/camel/spring/NodeIdReferenceLegacyTest-context.xml
@@ -0,0 +1,36 @@
+<?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
+ ">
+
+ <camelContext registerEndpointIdsFromRoute="true" xmlns="http://camel.apache.org/schema/spring">
+ <template id="camelTemplate"/>
+
+ <route>
+ <from id="foo" uri="direct:start"/>
+ <to uri="mock:result"/>
+ </route>
+ </camelContext>
+
+</beans>