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/06/03 08:45:57 UTC

[3/3] camel git commit: CAMEL-10009: Fixed Spring XML DSL to not fail when using with both id and ref attribute.

CAMEL-10009: Fixed Spring XML DSL to not fail when using <to> with both id and ref attribute.


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

Branch: refs/heads/camel-2.16.x
Commit: b3843f9d45bda7eff73ae7a333b85df12e3aa245
Parents: 6134357
Author: Claus Ibsen <da...@apache.org>
Authored: Fri Jun 3 10:43:51 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Fri Jun 3 10:45:46 2016 +0200

----------------------------------------------------------------------
 .../camel/spring/CamelEndpointFactoryBean.java  | 13 +++++++
 .../camel/spring/EndpointToIdRefTest.java       | 36 ++++++++++++++++++++
 .../apache/camel/spring/EndpointToIdRefTest.xml | 36 ++++++++++++++++++++
 3 files changed, 85 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/b3843f9d/components/camel-spring/src/main/java/org/apache/camel/spring/CamelEndpointFactoryBean.java
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/main/java/org/apache/camel/spring/CamelEndpointFactoryBean.java b/components/camel-spring/src/main/java/org/apache/camel/spring/CamelEndpointFactoryBean.java
index ace1ccd..e0c28b9 100644
--- a/components/camel-spring/src/main/java/org/apache/camel/spring/CamelEndpointFactoryBean.java
+++ b/components/camel-spring/src/main/java/org/apache/camel/spring/CamelEndpointFactoryBean.java
@@ -40,6 +40,11 @@ import org.springframework.context.ApplicationContextAware;
 public class CamelEndpointFactoryBean extends AbstractCamelEndpointFactoryBean implements FactoryBean<Endpoint>, ApplicationContextAware {
     @XmlTransient
     private ApplicationContext applicationContext;
+    // ref is needed as transient as namespace parser registerEndpointsWithIdsDefinedInFromOrToTypes
+    // will discover <endpoint>, <to> etc and parse those eager and would attempt to call setRef on
+    // this factory bean for a <to id="foo" ref="bar"/> that is using both id and ref.
+    @XmlTransient
+    private String ref;
 
     @Override
     protected CamelContext getCamelContextWithId(String camelContextId) {
@@ -55,4 +60,12 @@ public class CamelEndpointFactoryBean extends AbstractCamelEndpointFactoryBean i
         Endpoint answer = super.getObject();
         return answer;
     }
+
+    public String getRef() {
+        return ref;
+    }
+
+    public void setRef(String ref) {
+        this.ref = ref;
+    }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/b3843f9d/components/camel-spring/src/test/java/org/apache/camel/spring/EndpointToIdRefTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/java/org/apache/camel/spring/EndpointToIdRefTest.java b/components/camel-spring/src/test/java/org/apache/camel/spring/EndpointToIdRefTest.java
new file mode 100644
index 0000000..bc08679
--- /dev/null
+++ b/components/camel-spring/src/test/java/org/apache/camel/spring/EndpointToIdRefTest.java
@@ -0,0 +1,36 @@
+/**
+ * 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.springframework.context.support.AbstractXmlApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+public class EndpointToIdRefTest extends SpringTestSupport {
+
+    protected AbstractXmlApplicationContext createApplicationContext() {
+        return new ClassPathXmlApplicationContext("org/apache/camel/spring/EndpointToIdRefTest.xml");
+    }
+
+    public void testEndpoint() throws Exception {
+        getMockEndpoint("mock:result").expectedMessageCount(1);
+
+        template.sendBody("direct:start", "Hello World");
+
+        assertMockEndpointsSatisfied();
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/b3843f9d/components/camel-spring/src/test/resources/org/apache/camel/spring/EndpointToIdRefTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/resources/org/apache/camel/spring/EndpointToIdRefTest.xml b/components/camel-spring/src/test/resources/org/apache/camel/spring/EndpointToIdRefTest.xml
new file mode 100644
index 0000000..a3f1cc4
--- /dev/null
+++ b/components/camel-spring/src/test/resources/org/apache/camel/spring/EndpointToIdRefTest.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 xmlns="http://camel.apache.org/schema/spring">
+
+    <endpoint id="result" uri="mock:result"/>
+
+    <route>
+      <from uri="direct:start"/>
+      <to id="foo" ref="result"/>
+    </route>
+
+  </camelContext>
+
+</beans>