You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by bv...@apache.org on 2012/11/18 19:39:24 UTC

svn commit: r1410952 - in /camel/trunk: camel-core/src/main/java/org/apache/camel/model/ camel-core/src/test/java/org/apache/camel/processor/intercept/ components/camel-spring/src/test/java/org/apache/camel/component/properties/ components/camel-spring...

Author: bvahdat
Date: Sun Nov 18 18:39:21 2012
New Revision: 1410952

URL: http://svn.apache.org/viewvc?rev=1410952&view=rev
Log:
CAMEL-5796: Fixed the resolvement of the property placeholder in combination with the transacted DSL. Thanks to Claus Ibsen for providing a better patch as well as the unit-test for the camel-core module. I also added two tests for the camel-spring module using the propertyPlaceholder and bridgePropertyPlaceholder variants, also polished a tiny generics stuff of the ProcessorDefinition.resolvePropertyPlaceholders() method.

Added:
    camel/trunk/camel-core/src/test/java/org/apache/camel/processor/intercept/TransactedPropertyPlaceholderIssueTest.java   (with props)
    camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/properties/SpringPropertiesAfterTransactedDSL2Test.java   (with props)
    camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/properties/SpringPropertiesAfterTransactedDSLTest.java   (with props)
    camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/properties/SpringPropertiesAfterTransactedDSL2Test.xml   (with props)
    camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/properties/SpringPropertiesAfterTransactedDSLTest.xml   (with props)
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
    camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/properties/myprop.properties

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java?rev=1410952&r1=1410951&r2=1410952&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java Sun Nov 18 18:39:21 2012
@@ -367,9 +367,29 @@ public abstract class ProcessorDefinitio
         List<Processor> list = new ArrayList<Processor>();
         for (ProcessorDefinition<?> output : outputs) {
 
+            // allow any custom logic before we create the processor
+            output.preCreateProcessor();
+
             // resolve properties before we create the processor
             resolvePropertyPlaceholders(routeContext, output);
 
+            // resolve constant fields (eg Exchange.FILE_NAME)
+            resolveKnownConstantFields(output);
+
+            // also resolve properties and constant fields on embedded expressions
+            ProcessorDefinition<?> me = (ProcessorDefinition<?>) output;
+            if (me instanceof ExpressionNode) {
+                ExpressionNode exp = (ExpressionNode) me;
+                ExpressionDefinition expressionDefinition = exp.getExpression();
+                if (expressionDefinition != null) {
+                    // resolve properties before we create the processor
+                    resolvePropertyPlaceholders(routeContext, expressionDefinition);
+
+                    // resolve constant fields (eg Exchange.FILE_NAME)
+                    resolveKnownConstantFields(expressionDefinition);
+                }
+            }
+
             Processor processor = null;
             // at first use custom factory
             if (routeContext.getCamelContext().getProcessorFactory() != null) {
@@ -472,10 +492,9 @@ public abstract class ProcessorDefinitio
         // include additional properties which have the Camel placeholder QName
         // and when the definition parameter is this (otherAttributes belong to this)
         if (processorDefinition != null && processorDefinition.getOtherAttributes() != null) {
-            for (Object key : processorDefinition.getOtherAttributes().keySet()) {
-                QName qname = (QName) key;
-                if (Constants.PLACEHOLDER_QNAME.equals(qname.getNamespaceURI())) {
-                    String local = qname.getLocalPart();
+            for (QName key : processorDefinition.getOtherAttributes().keySet()) {
+                if (Constants.PLACEHOLDER_QNAME.equals(key.getNamespaceURI())) {
+                    String local = key.getLocalPart();
                     Object value = processorDefinition.getOtherAttributes().get(key);
                     if (value != null && value instanceof String) {
                         // value must be enclosed with placeholder tokens

Added: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/intercept/TransactedPropertyPlaceholderIssueTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/intercept/TransactedPropertyPlaceholderIssueTest.java?rev=1410952&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/intercept/TransactedPropertyPlaceholderIssueTest.java (added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/intercept/TransactedPropertyPlaceholderIssueTest.java Sun Nov 18 18:39:21 2012
@@ -0,0 +1,77 @@
+/**
+ * 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.processor.intercept;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.properties.PropertiesComponent;
+import org.apache.camel.model.ProcessorDefinition;
+import org.apache.camel.spi.Policy;
+import org.apache.camel.spi.RouteContext;
+
+/**
+ *
+ */
+public class TransactedPropertyPlaceholderIssueTest extends ContextTestSupport {
+
+    public void testPropertyPlaceholder() throws Exception {
+        getMockEndpoint("mock:result").expectedBodiesReceived("Camel");
+        template.sendBody("seda:foo", "Hello World");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("seda:foo")
+                    .policy(new MyDummyPolicy())
+                    .setBody().constant("{{cool.name}}")
+                    .to("mock:result");
+            }
+        };
+    }
+
+    @Override
+    protected CamelContext createCamelContext() throws Exception {
+        CamelContext context = super.createCamelContext();
+
+        PropertiesComponent pc = new PropertiesComponent();
+        pc.setLocation("classpath:org/apache/camel/component/properties/myproperties.properties");
+        context.addComponent("properties", pc);
+
+        return context;
+    }
+
+    private static final class MyDummyPolicy implements Policy {
+
+        @Override
+        public void beforeWrap(RouteContext routeContext, ProcessorDefinition<?> definition) {
+            // noop
+        }
+
+        @Override
+        public Processor wrap(RouteContext routeContext, Processor processor) {
+            return processor;
+        }
+    }
+
+}

Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/intercept/TransactedPropertyPlaceholderIssueTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/properties/SpringPropertiesAfterTransactedDSL2Test.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/properties/SpringPropertiesAfterTransactedDSL2Test.java?rev=1410952&view=auto
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/properties/SpringPropertiesAfterTransactedDSL2Test.java (added)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/properties/SpringPropertiesAfterTransactedDSL2Test.java Sun Nov 18 18:39:21 2012
@@ -0,0 +1,33 @@
+/**
+ * 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.component.properties;
+
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+/**
+ * @version
+ */
+public class SpringPropertiesAfterTransactedDSL2Test extends SpringPropertiesAfterTransactedDSLTest {
+
+    @Override
+    protected AbstractXmlApplicationContext createApplicationContext() {
+        // instead of the propertyPlaceholder here we make use of the bridgePropertyPlaceholder
+        return new ClassPathXmlApplicationContext("org/apache/camel/component/properties/SpringPropertiesAfterTransactedDSL2Test.xml");
+    }
+
+}

Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/properties/SpringPropertiesAfterTransactedDSL2Test.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/properties/SpringPropertiesAfterTransactedDSLTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/properties/SpringPropertiesAfterTransactedDSLTest.java?rev=1410952&view=auto
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/properties/SpringPropertiesAfterTransactedDSLTest.java (added)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/properties/SpringPropertiesAfterTransactedDSLTest.java Sun Nov 18 18:39:21 2012
@@ -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.component.properties;
+
+import org.apache.camel.spring.SpringTestSupport;
+import org.junit.Test;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+/**
+ * @version
+ */
+public class SpringPropertiesAfterTransactedDSLTest extends SpringTestSupport {
+
+    @Override
+    protected AbstractXmlApplicationContext createApplicationContext() {
+        return new ClassPathXmlApplicationContext("org/apache/camel/component/properties/SpringPropertiesAfterTransactedDSLTest.xml");
+    }
+
+    @Test
+    public void testResolveHeaderAfterTransactedDSL() throws Exception {
+        getMockEndpoint("mock:transactedHeader").expectedMessageCount(1);
+        getMockEndpoint("mock:transactedHeader").message(0).header("myHeader").isEqualTo("transacted");
+
+        template.requestBody("direct:transactedHeader", "Hello");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Test
+    public void testResolveBodyAfterTransactedDSL() throws Exception {
+        getMockEndpoint("mock:transactedBody").expectedMessageCount(1);
+        getMockEndpoint("mock:transactedBody").message(0).body().isEqualTo("transacted");
+
+        template.requestBody("direct:transactedBody", "Hello");
+
+        assertMockEndpointsSatisfied();
+    }
+
+}

Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/properties/SpringPropertiesAfterTransactedDSLTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/properties/SpringPropertiesAfterTransactedDSL2Test.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/properties/SpringPropertiesAfterTransactedDSL2Test.xml?rev=1410952&view=auto
==============================================================================
--- camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/properties/SpringPropertiesAfterTransactedDSL2Test.xml (added)
+++ camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/properties/SpringPropertiesAfterTransactedDSL2Test.xml Sun Nov 18 18:39:21 2012
@@ -0,0 +1,52 @@
+<?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">
+
+  <!-- require a spring transaction manager so that transacted DSL can find and use it -->
+  <import resource="../../spring/interceptor/transactionalClientDataSource.xml" />
+
+  <bean id="bridgePropertyPlaceholder" class="org.apache.camel.spring.spi.BridgePropertyPlaceholderConfigurer">
+    <property name="location" value="classpath:org/apache/camel/component/properties/myprop.properties" />
+  </bean>
+
+  <camelContext xmlns="http://camel.apache.org/schema/spring">
+
+    <route>
+      <from uri="direct:transactedHeader" />
+      <transacted />
+      <setHeader headerName="myHeader">
+        <constant>{{mydsl}}</constant>
+      </setHeader>
+      <to uri="mock:transactedHeader" />
+    </route>
+
+    <route>
+      <from uri="direct:transactedBody" />
+      <transacted />
+      <setBody>
+        <constant>{{mydsl}}</constant>
+      </setBody>
+      <to uri="mock:transactedBody" />
+    </route>
+
+  </camelContext>
+
+</beans>

Propchange: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/properties/SpringPropertiesAfterTransactedDSL2Test.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/properties/SpringPropertiesAfterTransactedDSLTest.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/properties/SpringPropertiesAfterTransactedDSLTest.xml?rev=1410952&view=auto
==============================================================================
--- camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/properties/SpringPropertiesAfterTransactedDSLTest.xml (added)
+++ camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/properties/SpringPropertiesAfterTransactedDSLTest.xml Sun Nov 18 18:39:21 2012
@@ -0,0 +1,49 @@
+<?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">
+
+  <!-- require a spring transaction manager so that transacted DSL can find and use it -->
+  <import resource="../../spring/interceptor/transactionalClientDataSource.xml" />
+
+  <camelContext xmlns="http://camel.apache.org/schema/spring">
+    <propertyPlaceholder id="properties" location="classpath:org/apache/camel/component/properties/myprop.properties" />
+
+    <route>
+      <from uri="direct:transactedHeader" />
+      <transacted />
+      <setHeader headerName="myHeader">
+        <constant>{{mydsl}}</constant>
+      </setHeader>
+      <to uri="mock:transactedHeader" />
+    </route>
+
+    <route>
+      <from uri="direct:transactedBody" />
+      <transacted />
+      <setBody>
+        <constant>{{mydsl}}</constant>
+      </setBody>
+      <to uri="mock:transactedBody" />
+    </route>
+
+  </camelContext>
+
+</beans>

Propchange: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/properties/SpringPropertiesAfterTransactedDSLTest.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/properties/myprop.properties
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/properties/myprop.properties?rev=1410952&r1=1410951&r2=1410952&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/properties/myprop.properties (original)
+++ camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/properties/myprop.properties Sun Nov 18 18:39:21 2012
@@ -22,4 +22,6 @@ result=mock:result
 
 mybuilder=simpleRoute
 
+mydsl=transacted
+
 stop=true
\ No newline at end of file