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/02/15 15:17:02 UTC
[2/3] camel git commit: CAMEL-7488: Do not use autowire by ctr when
creating PropertiesComponent as Spring inject weird locations when ppl use
util:constant in their spring xml files. Also its not needed to autowire this
component.
CAMEL-7488: Do not use autowire by ctr when creating PropertiesComponent as Spring inject weird locations when ppl use util:constant in their spring xml files. Also its not needed to autowire this component.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/da595019
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/da595019
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/da595019
Branch: refs/heads/camel-2.14.x
Commit: da5950194928e1075f8803e79db2a1be82a6dc1e
Parents: 2dd0956
Author: Claus Ibsen <da...@apache.org>
Authored: Sun Feb 15 13:15:20 2015 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Sun Feb 15 15:16:27 2015 +0100
----------------------------------------------------------------------
.../apache/camel/util/CamelContextHelper.java | 4 +-
.../camel/spring/CamelContextFactoryBean.java | 7 ++-
...pertyPlaceholderConfigurerUtilIssueTest.java | 40 ++++++++++++++++
...gePropertyPlaceholderConfigurerUtilIssue.xml | 48 ++++++++++++++++++++
4 files changed, 97 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/da595019/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 ba3b717..7e4fac1 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
@@ -497,7 +497,9 @@ public final class CamelContextHelper {
if (answer == null && autoCreate) {
// create a default properties component to be used as there may be default values we can use
LOG.info("No existing PropertiesComponent has been configured, creating a new default PropertiesComponent with name: properties");
- answer = camelContext.getComponent("properties", PropertiesComponent.class);
+ // do not auto create using getComponent as spring autowrire by constructor causes a side effect
+ answer = new PropertiesComponent();
+ camelContext.addComponent("properties", answer);
}
return answer;
}
http://git-wip-us.apache.org/repos/asf/camel/blob/da595019/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 0a39e2a..b0ffa15 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
@@ -282,7 +282,12 @@ public class CamelContextFactoryBean extends AbstractCamelContextFactoryBean<Spr
LOG.info("Bridging Camel and Spring property placeholder configurer with id: " + id);
// get properties component
- PropertiesComponent pc = getContext().getComponent("properties", PropertiesComponent.class);
+ PropertiesComponent pc = (PropertiesComponent) getContext().getComponent("properties", false);
+ if (pc == null) {
+ // do not auto create the component as spring autowrire by constructor causes a side effect when using bridge
+ pc = new PropertiesComponent();
+ getContext().addComponent("properties", pc);
+ }
// replace existing resolver with us
configurer.setResolver(pc.getPropertiesResolver());
configurer.setParser(pc.getPropertiesParser());
http://git-wip-us.apache.org/repos/asf/camel/blob/da595019/components/camel-spring/src/test/java/org/apache/camel/spring/spi/BridgePropertyPlaceholderConfigurerUtilIssueTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/java/org/apache/camel/spring/spi/BridgePropertyPlaceholderConfigurerUtilIssueTest.java b/components/camel-spring/src/test/java/org/apache/camel/spring/spi/BridgePropertyPlaceholderConfigurerUtilIssueTest.java
new file mode 100644
index 0000000..04a6dac
--- /dev/null
+++ b/components/camel-spring/src/test/java/org/apache/camel/spring/spi/BridgePropertyPlaceholderConfigurerUtilIssueTest.java
@@ -0,0 +1,40 @@
+/**
+ * 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.spi;
+
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.spring.SpringTestSupport;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+public class BridgePropertyPlaceholderConfigurerUtilIssueTest extends SpringTestSupport {
+ public static final String CONSTANT = "This is the test property.";
+
+ @Override
+ protected AbstractXmlApplicationContext createApplicationContext() {
+ return new ClassPathXmlApplicationContext("org/apache/camel/spring/spi/bridgePropertyPlaceholderConfigurerUtilIssue.xml");
+ }
+
+ public void testIssue() throws Exception {
+ MockEndpoint result = context.getEndpoint("mock:result", MockEndpoint.class);
+ // we do not receive the constant but a different value
+ result.expectedBodiesReceived("Hello Camel");
+ template.sendBody("direct:start", "Test");
+ result.assertIsSatisfied();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/da595019/components/camel-spring/src/test/resources/org/apache/camel/spring/spi/bridgePropertyPlaceholderConfigurerUtilIssue.xml
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/resources/org/apache/camel/spring/spi/bridgePropertyPlaceholderConfigurerUtilIssue.xml b/components/camel-spring/src/test/resources/org/apache/camel/spring/spi/bridgePropertyPlaceholderConfigurerUtilIssue.xml
new file mode 100644
index 0000000..ca503b7
--- /dev/null
+++ b/components/camel-spring/src/test/resources/org/apache/camel/spring/spi/bridgePropertyPlaceholderConfigurerUtilIssue.xml
@@ -0,0 +1,48 @@
+<?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"
+ xmlns:util="http://www.springframework.org/schema/util"
+ 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
+ http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
+ ">
+
+ <util:constant id="test" static-field="org.apache.camel.spring.spi.BridgePropertyPlaceholderConfigurerTest.CONSTANT"/>
+
+ <bean id="bridgePropertyPlaceHolder" class="org.apache.camel.spring.spi.BridgePropertyPlaceholderConfigurer">
+ <property name="locations">
+ <list>
+ <value>classpath:org/apache/camel/component/properties/myprop.properties</value>
+ </list>
+ </property>
+ </bean>
+
+ <camel:camelContext xmlns="http://camel.apache.org/schema/spring">
+ <camel:route>
+ <camel:from uri="direct:start" />
+ <camel:setBody>
+ <camel:simple>{{hello}}</camel:simple>
+ </camel:setBody>
+ <camel:to uri="mock:result" />
+ </camel:route>
+ </camel:camelContext>
+
+</beans>
\ No newline at end of file