camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [1/4] git commit: CAMEL-3215: Added new @PropertyInject to inject property placeholders in POJOs.
Date Mon, 26 Aug 2013 12:32:16 GMT
Updated Branches:
  refs/heads/camel-2.11.x f85ca1d00 -> 3e7978d1d
  refs/heads/master cfa3b5f53 -> 90af871dd


CAMEL-3215: Added new @PropertyInject to inject property placeholders in POJOs.


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

Branch: refs/heads/master
Commit: 70ca8f35f291040cdc29c6c95fc707a90efb8884
Parents: cfa3b5f
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Mon Aug 26 13:38:02 2013 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Mon Aug 26 14:11:59 2013 +0200

----------------------------------------------------------------------
 .../java/org/apache/camel/PropertyInject.java   |  35 +++++++
 .../camel/impl/CamelPostProcessorHelper.java    |  25 ++++-
 .../impl/DefaultCamelBeanPostProcessor.java     |  30 ++++++
 .../impl/CamelPostProcessorHelperTest.java      | 105 +++++++++++++++++++
 .../handler/CamelNamespaceHandler.java          |  29 +++++
 .../SpringBuilderRefPropertyInjectTest.java     |  41 ++++++++
 .../route2/SpringPropertyInjectRoute.java       |  37 +++++++
 .../SpringBuilderRefPropertyInjectTest.xml      |  32 ++++++
 .../component/properties/myprop.properties      |   4 +-
 .../blueprint/BlueprintPropertyInjectRoute.java |  34 ++++++
 .../camel/test/blueprint/MyProperties.java      |   1 +
 .../test/blueprint/PropertyInjectTest.java      |  38 +++++++
 .../camel/test/blueprint/propertyInjectTest.xml |  34 ++++++
 13 files changed, 443 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/70ca8f35/camel-core/src/main/java/org/apache/camel/PropertyInject.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/PropertyInject.java b/camel-core/src/main/java/org/apache/camel/PropertyInject.java
new file mode 100644
index 0000000..35bfdef
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/PropertyInject.java
@@ -0,0 +1,35 @@
+/**
+ * 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;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Used to indicate an injection point of a
+ * <a href="http://camel.apache.org/using-propertyplaceholder.html">property placeholder</a>
into a POJO.
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Documented
+@Target({ElementType.FIELD, ElementType.METHOD, ElementType.CONSTRUCTOR })
+public @interface PropertyInject {
+    String value();
+    String context() default "";
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/70ca8f35/camel-core/src/main/java/org/apache/camel/impl/CamelPostProcessorHelper.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/CamelPostProcessorHelper.java
b/camel-core/src/main/java/org/apache/camel/impl/CamelPostProcessorHelper.java
index e9c36b8..7208552 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/CamelPostProcessorHelper.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/CamelPostProcessorHelper.java
@@ -135,7 +135,7 @@ public class CamelPostProcessorHelper implements CamelContextAware {
     }
 
     public Endpoint getEndpointInjection(Object bean, String uri, String name, String propertyName,
-                                            String injectionPointName, boolean mandatory)
{
+                                         String injectionPointName, boolean mandatory) {
         if (ObjectHelper.isEmpty(uri) && ObjectHelper.isEmpty(name)) {
             // if no uri or ref, then fallback and try the endpoint property
             return doGetEndpointInjection(bean, propertyName, injectionPointName);
@@ -221,6 +221,29 @@ public class CamelPostProcessorHelper implements CamelContextAware {
         }
     }
 
+    public Object getInjectionPropertyValue(Class<?> type, String propertyName, String
injectionPointName, Object bean, String beanName) {
+        try {
+            String key;
+            String prefix = getCamelContext().getPropertyPrefixToken();
+            String suffix = getCamelContext().getPropertySuffixToken();
+            if (!propertyName.contains(prefix)) {
+                // must enclose the property name with prefix/suffix to have it resolved
+                key = prefix + propertyName + suffix;
+            } else {
+                // key has already prefix/suffix so use it as-is as it may be a compound
key
+                key = propertyName;
+            }
+            String value = getCamelContext().resolvePropertyPlaceholders(key);
+            if (value != null) {
+                return getCamelContext().getTypeConverter().mandatoryConvertTo(type, value);
+            } else {
+                return null;
+            }
+        } catch (Exception e) {
+            throw ObjectHelper.wrapRuntimeCamelException(e);
+        }
+    }
+
     /**
      * Factory method to create a {@link org.apache.camel.ProducerTemplate} to be injected
into a POJO
      */

http://git-wip-us.apache.org/repos/asf/camel/blob/70ca8f35/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelBeanPostProcessor.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelBeanPostProcessor.java
b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelBeanPostProcessor.java
index 924e22e..29d4f0b 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelBeanPostProcessor.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelBeanPostProcessor.java
@@ -23,6 +23,7 @@ import org.apache.camel.CamelContext;
 import org.apache.camel.CamelContextAware;
 import org.apache.camel.EndpointInject;
 import org.apache.camel.Produce;
+import org.apache.camel.PropertyInject;
 import org.apache.camel.util.ObjectHelper;
 import org.apache.camel.util.ReflectionHelper;
 import org.slf4j.Logger;
@@ -165,6 +166,11 @@ public class DefaultCamelBeanPostProcessor {
     protected void injectFields(final Object bean, final String beanName) {
         ReflectionHelper.doWithFields(bean.getClass(), new ReflectionHelper.FieldCallback()
{
             public void doWith(Field field) throws IllegalArgumentException, IllegalAccessException
{
+                PropertyInject propertyInject = field.getAnnotation(PropertyInject.class);
+                if (propertyInject != null && getPostProcessorHelper().matchContext(propertyInject.context()))
{
+                    injectFieldProperty(field, propertyInject.value(), bean, beanName);
+                }
+
                 EndpointInject endpointInject = field.getAnnotation(EndpointInject.class);
                 if (endpointInject != null && getPostProcessorHelper().matchContext(endpointInject.context()))
{
                     injectField(field, endpointInject.uri(), endpointInject.ref(), endpointInject.property(),
bean, beanName);
@@ -185,6 +191,12 @@ public class DefaultCamelBeanPostProcessor {
                         field.getName(), bean, beanName));
     }
 
+    public void injectFieldProperty(Field field, String propertyName, Object bean, String
beanName) {
+        ReflectionHelper.setField(field, bean,
+                getPostProcessorHelper().getInjectionPropertyValue(field.getType(), propertyName,
+                        field.getName(), bean, beanName));
+    }
+
     protected void injectMethods(final Object bean, final String beanName) {
         ReflectionHelper.doWithMethods(bean.getClass(), new ReflectionHelper.MethodCallback()
{
             public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException
{
@@ -195,6 +207,11 @@ public class DefaultCamelBeanPostProcessor {
     }
 
     protected void setterInjection(Method method, Object bean, String beanName) {
+        PropertyInject propertyInject = method.getAnnotation(PropertyInject.class);
+        if (propertyInject != null && getPostProcessorHelper().matchContext(propertyInject.context()))
{
+            setterPropertyInjection(method, propertyInject.value(), bean, beanName);
+        }
+
         EndpointInject endpointInject = method.getAnnotation(EndpointInject.class);
         if (endpointInject != null && getPostProcessorHelper().matchContext(endpointInject.context()))
{
             setterInjection(method, bean, beanName, endpointInject.uri(), endpointInject.ref(),
endpointInject.property());
@@ -220,4 +237,17 @@ public class DefaultCamelBeanPostProcessor {
         }
     }
 
+    public void setterPropertyInjection(Method method, String name, Object bean, String beanName)
{
+        Class<?>[] parameterTypes = method.getParameterTypes();
+        if (parameterTypes != null) {
+            if (parameterTypes.length != 1) {
+                LOG.warn("Ignoring badly annotated method for injection due to incorrect
number of parameters: " + method);
+            } else {
+                String propertyName = ObjectHelper.getPropertyName(method);
+                Object value = getPostProcessorHelper().getInjectionPropertyValue(parameterTypes[0],
name, propertyName, bean, beanName);
+                ObjectHelper.invokeMethod(method, bean, value);
+            }
+        }
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/70ca8f35/camel-core/src/test/java/org/apache/camel/impl/CamelPostProcessorHelperTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/impl/CamelPostProcessorHelperTest.java
b/camel-core/src/test/java/org/apache/camel/impl/CamelPostProcessorHelperTest.java
index 4e32f7e..2e07bf6 100644
--- a/camel-core/src/test/java/org/apache/camel/impl/CamelPostProcessorHelperTest.java
+++ b/camel-core/src/test/java/org/apache/camel/impl/CamelPostProcessorHelperTest.java
@@ -18,7 +18,9 @@ package org.apache.camel.impl;
 
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
+import java.util.Properties;
 
+import org.apache.camel.CamelContext;
 import org.apache.camel.Consume;
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.EndpointInject;
@@ -28,9 +30,11 @@ import org.apache.camel.PollingConsumer;
 import org.apache.camel.Produce;
 import org.apache.camel.Producer;
 import org.apache.camel.ProducerTemplate;
+import org.apache.camel.PropertyInject;
 import org.apache.camel.ResolveEndpointFailedException;
 import org.apache.camel.RuntimeCamelException;
 import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.component.properties.PropertiesComponent;
 import org.apache.camel.support.SynchronizationAdapter;
 import org.apache.camel.util.ObjectHelper;
 
@@ -40,6 +44,24 @@ import org.apache.camel.util.ObjectHelper;
 public class CamelPostProcessorHelperTest extends ContextTestSupport {
 
     private MySynchronization mySynchronization = new MySynchronization();
+    private Properties myProp = new Properties();
+
+    @Override
+    protected JndiRegistry createRegistry() throws Exception {
+        JndiRegistry jndi = super.createRegistry();
+        jndi.bind("myProp", myProp);
+        return jndi;
+    }
+
+    @Override
+    protected CamelContext createCamelContext() throws Exception {
+        CamelContext context = super.createCamelContext();
+
+        PropertiesComponent pc = context.getComponent("properties", PropertiesComponent.class);
+        pc.setLocation("ref:myProp");
+
+        return context;
+    }
 
     public void testConstructor() {
         CamelPostProcessorHelper helper = new CamelPostProcessorHelper();
@@ -309,6 +331,48 @@ public class CamelPostProcessorHelperTest extends ContextTestSupport
{
         }
     }
 
+    public void testPropertyFieldInject() throws Exception {
+        myProp.put("myTimeout", "2000");
+        myProp.put("myApp", "Camel");
+
+        CamelPostProcessorHelper helper = new CamelPostProcessorHelper(context);
+
+        MyPropertyFieldBean bean = new MyPropertyFieldBean();
+
+        Field field = bean.getClass().getField("timeout");
+        PropertyInject propertyInject = field.getAnnotation(PropertyInject.class);
+        Class<?> type = field.getType();
+        Object value = helper.getInjectionPropertyValue(type, propertyInject.value(), "timeout",
 bean, "foo");
+        assertEquals(Integer.valueOf("2000"), Integer.valueOf("" + value));
+
+        field = bean.getClass().getField("greeting");
+        propertyInject = field.getAnnotation(PropertyInject.class);
+        type = field.getType();
+        value = helper.getInjectionPropertyValue(type, propertyInject.value(), "greeting",
 bean, "foo");
+        assertEquals("Hello Camel", value);
+    }
+
+    public void testPropertyMethodInject() throws Exception {
+        myProp.put("myTimeout", "2000");
+        myProp.put("myApp", "Camel");
+
+        CamelPostProcessorHelper helper = new CamelPostProcessorHelper(context);
+
+        MyPropertyMethodBean bean = new MyPropertyMethodBean();
+
+        Method method = bean.getClass().getMethod("setTimeout", int.class);
+        PropertyInject propertyInject = method.getAnnotation(PropertyInject.class);
+        Class<?> type = method.getParameterTypes()[0];
+        Object value = helper.getInjectionPropertyValue(type, propertyInject.value(), "timeout",
 bean, "foo");
+        assertEquals(Integer.valueOf("2000"), Integer.valueOf("" + value));
+
+        method = bean.getClass().getMethod("setGreeting", String.class);
+        propertyInject = method.getAnnotation(PropertyInject.class);
+        type = method.getParameterTypes()[0];
+        value = helper.getInjectionPropertyValue(type, propertyInject.value(), "greeting",
 bean, "foo");
+        assertEquals("Hello Camel", value);
+    }
+
     public class MyConsumeBean {
 
         @Consume(uri = "seda:foo")
@@ -481,4 +545,45 @@ public class CamelPostProcessorHelperTest extends ContextTestSupport
{
         }
     }
 
+    public class MyPropertyFieldBean {
+
+        @PropertyInject("myTimeout")
+        public int timeout;
+
+        @PropertyInject("Hello {{myApp}}")
+        public String greeting;
+
+        public String doSomething(String body) {
+            return greeting + " " + body + " with timeout=" + timeout;
+        }
+    }
+
+    public class MyPropertyMethodBean {
+
+        private int timeout;
+        private String greeting;
+
+        public String doSomething(String body) {
+            return greeting + " " + body + " with timeout=" + timeout;
+        }
+
+        public int getTimeout() {
+            return timeout;
+        }
+
+        @PropertyInject("myTimeout")
+        public void setTimeout(int timeout) {
+            this.timeout = timeout;
+        }
+
+        public String getGreeting() {
+            return greeting;
+        }
+
+        @PropertyInject("Hello {{myApp}}")
+        public void setGreeting(String greeting) {
+            this.greeting = greeting;
+        }
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/70ca8f35/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/handler/CamelNamespaceHandler.java
----------------------------------------------------------------------
diff --git a/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/handler/CamelNamespaceHandler.java
b/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/handler/CamelNamespaceHandler.java
index 78e1501..38ea065 100644
--- a/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/handler/CamelNamespaceHandler.java
+++ b/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/handler/CamelNamespaceHandler.java
@@ -29,6 +29,8 @@ import javax.xml.bind.Binder;
 import javax.xml.bind.JAXBContext;
 import javax.xml.bind.JAXBException;
 
+import org.apache.camel.PropertyInject;
+import org.apache.camel.util.ReflectionHelper;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
@@ -661,6 +663,11 @@ public class CamelNamespaceHandler implements NamespaceHandler {
             do {
                 Field[] fields = clazz.getDeclaredFields();
                 for (Field field : fields) {
+                    PropertyInject propertyInject = field.getAnnotation(PropertyInject.class);
+                    if (propertyInject != null && matchContext(propertyInject.context()))
{
+                        injectFieldProperty(field, propertyInject.value(), bean, beanName);
+                    }
+
                     EndpointInject endpointInject = field.getAnnotation(EndpointInject.class);
                     if (endpointInject != null && matchContext(endpointInject.context()))
{
                         injectField(field, endpointInject.uri(), endpointInject.ref(), endpointInject.property(),
bean, beanName);
@@ -679,6 +686,10 @@ public class CamelNamespaceHandler implements NamespaceHandler {
             setField(field, bean, getInjectionValue(field.getType(), endpointUri, endpointRef,
endpointProperty, field.getName(), bean, beanName));
         }
 
+        protected void injectFieldProperty(Field field, String propertyName, Object bean,
String beanName) {
+            setField(field, bean, getInjectionPropertyValue(field.getType(), propertyName,
field.getName(), bean, beanName));
+        }
+
         protected static void setField(Field field, Object instance, Object value) {
             try {
                 boolean oldAccessible = field.isAccessible();
@@ -710,6 +721,11 @@ public class CamelNamespaceHandler implements NamespaceHandler {
         }
 
         protected void setterInjection(Method method, Object bean, String beanName) {
+            PropertyInject propertyInject = method.getAnnotation(PropertyInject.class);
+            if (propertyInject != null && matchContext(propertyInject.context()))
{
+                setterPropertyInjection(method, propertyInject.value(), bean, beanName);
+            }
+
             EndpointInject endpointInject = method.getAnnotation(EndpointInject.class);
             if (endpointInject != null && matchContext(endpointInject.context()))
{
                 setterInjection(method, bean, beanName, endpointInject.uri(), endpointInject.ref(),
endpointInject.property());
@@ -721,6 +737,19 @@ public class CamelNamespaceHandler implements NamespaceHandler {
             }
         }
 
+        protected void setterPropertyInjection(Method method, String name, Object bean, String
beanName) {
+            Class<?>[] parameterTypes = method.getParameterTypes();
+            if (parameterTypes != null) {
+                if (parameterTypes.length != 1) {
+                    LOG.warn("Ignoring badly annotated method for injection due to incorrect
number of parameters: " + method);
+                } else {
+                    String propertyName = ObjectHelper.getPropertyName(method);
+                    Object value = getInjectionPropertyValue(parameterTypes[0], name, propertyName,
bean, beanName);
+                    ObjectHelper.invokeMethod(method, bean, value);
+                }
+            }
+        }
+
         protected void setterInjection(Method method, Object bean, String beanName, String
endpointUri, String endpointRef, String endpointProperty) {
             Class<?>[] parameterTypes = method.getParameterTypes();
             if (parameterTypes != null) {

http://git-wip-us.apache.org/repos/asf/camel/blob/70ca8f35/components/camel-spring/src/test/java/org/apache/camel/component/properties/SpringBuilderRefPropertyInjectTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/java/org/apache/camel/component/properties/SpringBuilderRefPropertyInjectTest.java
b/components/camel-spring/src/test/java/org/apache/camel/component/properties/SpringBuilderRefPropertyInjectTest.java
new file mode 100644
index 0000000..25b4cac
--- /dev/null
+++ b/components/camel-spring/src/test/java/org/apache/camel/component/properties/SpringBuilderRefPropertyInjectTest.java
@@ -0,0 +1,41 @@
+/**
+ * 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.springframework.context.support.AbstractXmlApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+/**
+ * @version 
+ */
+public class SpringBuilderRefPropertyInjectTest extends SpringTestSupport {
+
+    @Override
+    protected AbstractXmlApplicationContext createApplicationContext() {
+        return new ClassPathXmlApplicationContext("org/apache/camel/component/properties/SpringBuilderRefPropertyInjectTest.xml");
+    }
+
+    public void testPropertyInject() throws Exception {
+        getMockEndpoint("{{result}}").expectedBodiesReceived("Hello Camel");
+
+        template.sendBody("direct:start", "Hello World");
+
+        assertMockEndpointsSatisfied();
+    }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/70ca8f35/components/camel-spring/src/test/java/org/apache/camel/component/properties/route2/SpringPropertyInjectRoute.java
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/java/org/apache/camel/component/properties/route2/SpringPropertyInjectRoute.java
b/components/camel-spring/src/test/java/org/apache/camel/component/properties/route2/SpringPropertyInjectRoute.java
new file mode 100644
index 0000000..7e828da
--- /dev/null
+++ b/components/camel-spring/src/test/java/org/apache/camel/component/properties/route2/SpringPropertyInjectRoute.java
@@ -0,0 +1,37 @@
+/**
+ * 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.route2;
+
+import org.apache.camel.PropertyInject;
+import org.apache.camel.spring.SpringRouteBuilder;
+
+/**
+ * @version 
+ */
+public class SpringPropertyInjectRoute extends SpringRouteBuilder {
+
+    @PropertyInject("hello")
+    private String greeting;
+
+    @Override
+    public void configure() throws Exception {
+        from("direct:start")
+            .transform().constant(greeting)
+            .to("{{result}}");
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/70ca8f35/components/camel-spring/src/test/resources/org/apache/camel/component/properties/SpringBuilderRefPropertyInjectTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/resources/org/apache/camel/component/properties/SpringBuilderRefPropertyInjectTest.xml
b/components/camel-spring/src/test/resources/org/apache/camel/component/properties/SpringBuilderRefPropertyInjectTest.xml
new file mode 100644
index 0000000..4a93d3a
--- /dev/null
+++ b/components/camel-spring/src/test/resources/org/apache/camel/component/properties/SpringBuilderRefPropertyInjectTest.xml
@@ -0,0 +1,32 @@
+<?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="simpleRoute" class="org.apache.camel.component.properties.route2.SpringPropertyInjectRoute"/>
+
+    <camelContext xmlns="http://camel.apache.org/schema/spring">
+        <propertyPlaceholder id="properties" location="org/apache/camel/component/properties/myprop.properties"/>
+        <routeBuilder ref="simpleRoute"/>
+    </camelContext>
+
+</beans>

http://git-wip-us.apache.org/repos/asf/camel/blob/70ca8f35/components/camel-spring/src/test/resources/org/apache/camel/component/properties/myprop.properties
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/resources/org/apache/camel/component/properties/myprop.properties
b/components/camel-spring/src/test/resources/org/apache/camel/component/properties/myprop.properties
index 2ebc3a1..965e050 100644
--- a/components/camel-spring/src/test/resources/org/apache/camel/component/properties/myprop.properties
+++ b/components/camel-spring/src/test/resources/org/apache/camel/component/properties/myprop.properties
@@ -24,4 +24,6 @@ mybuilder=simpleRoute
 
 mydsl=transacted
 
-stop=true
\ No newline at end of file
+stop=true
+
+hello=Hello Camel

http://git-wip-us.apache.org/repos/asf/camel/blob/70ca8f35/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/BlueprintPropertyInjectRoute.java
----------------------------------------------------------------------
diff --git a/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/BlueprintPropertyInjectRoute.java
b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/BlueprintPropertyInjectRoute.java
new file mode 100644
index 0000000..2f1959c
--- /dev/null
+++ b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/BlueprintPropertyInjectRoute.java
@@ -0,0 +1,34 @@
+/**
+ * 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.test.blueprint;
+
+import org.apache.camel.PropertyInject;
+import org.apache.camel.builder.RouteBuilder;
+
+public class BlueprintPropertyInjectRoute extends RouteBuilder {
+
+    @PropertyInject("greeting")
+    private String greeting;
+
+    @Override
+    public void configure() throws Exception {
+        from("direct:start")
+                .transform().constant(greeting)
+                .to("{{destination}}");
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/70ca8f35/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/MyProperties.java
----------------------------------------------------------------------
diff --git a/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/MyProperties.java
b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/MyProperties.java
index 092a51a..370fa5a 100644
--- a/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/MyProperties.java
+++ b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/MyProperties.java
@@ -24,6 +24,7 @@ public class MyProperties extends Properties {
 
     public MyProperties() {
         setProperty("greeting", "Hello");
+        setProperty("hello", "Hello Camel");
         setProperty("destination", "mock:result");
     }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/70ca8f35/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/PropertyInjectTest.java
----------------------------------------------------------------------
diff --git a/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/PropertyInjectTest.java
b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/PropertyInjectTest.java
new file mode 100644
index 0000000..6336f7c
--- /dev/null
+++ b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/PropertyInjectTest.java
@@ -0,0 +1,38 @@
+/**
+ * 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.test.blueprint;
+
+import org.junit.Test;
+
+public class PropertyInjectTest extends CamelBlueprintTestSupport {
+
+    @Override
+    protected String getBlueprintDescriptor() {
+        return "org/apache/camel/test/blueprint/propertyInjectTest.xml";
+    }
+
+    @Test
+    public void testPropertyInject() throws Exception {
+        getMockEndpoint("mock:result").expectedBodiesReceived("Hello");
+
+        template.sendBody("direct:start", "Camel");
+
+        assertMockEndpointsSatisfied();
+    }
+
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/70ca8f35/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/propertyInjectTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/propertyInjectTest.xml
b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/propertyInjectTest.xml
new file mode 100644
index 0000000..dc00c9f
--- /dev/null
+++ b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/propertyInjectTest.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.
+-->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+           xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0"
+           xsi:schemaLocation="
+             http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0 http://aries.apache.org/schemas/blueprint-cm/blueprint-cm-1.0.0.xsd
+             http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
+
+  
+  <bean id="vmProperties" class="org.apache.camel.test.blueprint.MyProperties" />
+  <bean id="myRoute" class="org.apache.camel.test.blueprint.BlueprintPropertyInjectRoute"
/>
+
+  <camelContext xmlns="http://camel.apache.org/schema/blueprint">
+    <propertyPlaceholder location="ref:vmProperties" />
+    <routeBuilder ref="myRoute"/>
+  </camelContext>
+
+</blueprint>


Mime
View raw message