camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [1/2] camel git commit: CAMEL-9450: rest-dsl - Configuration allow to use # to refer to beans to be looked up
Date Fri, 25 Dec 2015 13:00:25 GMT
Repository: camel
Updated Branches:
  refs/heads/master e4b2eb8b5 -> 3d47d04b9


CAMEL-9450: rest-dsl - Configuration allow to use # to refer to beans to be looked up


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

Branch: refs/heads/master
Commit: 2c5264c5db1169c5dcf7d463c1fd084e772bb2db
Parents: e4b2eb8
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Fri Dec 25 12:28:30 2015 +0100
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Fri Dec 25 12:40:14 2015 +0100

----------------------------------------------------------------------
 .../camel/model/rest/RestBindingDefinition.java |  7 +++++--
 .../model/rest/RestConfigurationDefinition.java |  8 ++++++++
 .../rest/DummyRestConsumerFactory.java          | 20 ++++++++++++++++++++
 .../rest/FromRestConfigurationTest.java         | 19 +++++++++++++++++--
 4 files changed, 50 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/2c5264c5/camel-core/src/main/java/org/apache/camel/model/rest/RestBindingDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/rest/RestBindingDefinition.java
b/camel-core/src/main/java/org/apache/camel/model/rest/RestBindingDefinition.java
index d2936de..dec6006 100644
--- a/camel-core/src/main/java/org/apache/camel/model/rest/RestBindingDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/rest/RestBindingDefinition.java
@@ -18,7 +18,6 @@ package org.apache.camel.model.rest;
 
 import java.util.HashMap;
 import java.util.Map;
-
 import javax.xml.bind.JAXBContext;
 import javax.xml.bind.annotation.XmlAccessType;
 import javax.xml.bind.annotation.XmlAccessorType;
@@ -33,6 +32,7 @@ import org.apache.camel.spi.DataFormat;
 import org.apache.camel.spi.Metadata;
 import org.apache.camel.spi.RestConfiguration;
 import org.apache.camel.spi.RouteContext;
+import org.apache.camel.util.EndpointHelper;
 import org.apache.camel.util.IntrospectionSupport;
 
 /**
@@ -223,7 +223,9 @@ public class RestBindingDefinition extends NoOutputDefinition<RestBindingDefinit
                 }
             }
 
-            IntrospectionSupport.setProperties(context.getTypeConverter(), dataFormat, copy);
+            // set reference properties first as they use # syntax that fools the regular
properties setter
+            EndpointHelper.setReferenceProperties(context, dataFormat, copy);
+            EndpointHelper.setProperties(context, dataFormat, copy);
         }
     }
 
@@ -241,6 +243,7 @@ public class RestBindingDefinition extends NoOutputDefinition<RestBindingDefinit
     public void setComponent(String component) {
         this.component = component;
     }
+
     public String getComponent() {
         return component;
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/2c5264c5/camel-core/src/main/java/org/apache/camel/model/rest/RestConfigurationDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/rest/RestConfigurationDefinition.java
b/camel-core/src/main/java/org/apache/camel/model/rest/RestConfigurationDefinition.java
index 5dc4804..fb03ef5 100644
--- a/camel-core/src/main/java/org/apache/camel/model/rest/RestConfigurationDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/rest/RestConfigurationDefinition.java
@@ -557,6 +557,8 @@ public class RestConfigurationDefinition {
 
     /**
      * For additional configuration options on component level
+     * <p/>
+     * The value can use <tt>#</tt> to refer to a bean to lookup in the registry.
      */
     public RestConfigurationDefinition componentProperty(String key, String value) {
         RestPropertyDefinition prop = new RestPropertyDefinition();
@@ -568,6 +570,8 @@ public class RestConfigurationDefinition {
 
     /**
      * For additional configuration options on endpoint level
+     * <p/>
+     * The value can use <tt>#</tt> to refer to a bean to lookup in the registry.
      */
     public RestConfigurationDefinition endpointProperty(String key, String value) {
         RestPropertyDefinition prop = new RestPropertyDefinition();
@@ -579,6 +583,8 @@ public class RestConfigurationDefinition {
 
     /**
      * For additional configuration options on consumer level
+     * <p/>
+     * The value can use <tt>#</tt> to refer to a bean to lookup in the registry.
      */
     public RestConfigurationDefinition consumerProperty(String key, String value) {
         RestPropertyDefinition prop = new RestPropertyDefinition();
@@ -590,6 +596,8 @@ public class RestConfigurationDefinition {
 
     /**
      * For additional configuration options on data format level
+     * <p/>
+     * The value can use <tt>#</tt> to refer to a bean to lookup in the registry.
      */
     public RestConfigurationDefinition dataFormatProperty(String key, String value) {
         RestPropertyDefinition prop = new RestPropertyDefinition();

http://git-wip-us.apache.org/repos/asf/camel/blob/2c5264c5/camel-core/src/test/java/org/apache/camel/component/rest/DummyRestConsumerFactory.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/rest/DummyRestConsumerFactory.java
b/camel-core/src/test/java/org/apache/camel/component/rest/DummyRestConsumerFactory.java
index 46572c8..c0d8496 100644
--- a/camel-core/src/test/java/org/apache/camel/component/rest/DummyRestConsumerFactory.java
+++ b/camel-core/src/test/java/org/apache/camel/component/rest/DummyRestConsumerFactory.java
@@ -26,9 +26,21 @@ import org.apache.camel.impl.ActiveMQUuidGenerator;
 import org.apache.camel.spi.RestApiConsumerFactory;
 import org.apache.camel.spi.RestConfiguration;
 import org.apache.camel.spi.RestConsumerFactory;
+import org.apache.camel.util.CamelContextHelper;
+import org.apache.camel.util.EndpointHelper;
 
 public class DummyRestConsumerFactory implements RestConsumerFactory, RestApiConsumerFactory
{
 
+    private Object dummy;
+
+    public Object getDummy() {
+        return dummy;
+    }
+
+    public void setDummy(Object dummy) {
+        this.dummy = dummy;
+    }
+
     @Override
     public Consumer createConsumer(CamelContext camelContext, Processor processor, String
verb, String basePath, String uriTemplate,
                                    String consumes, String produces, RestConfiguration configuration,
Map<String, Object> parameters) throws Exception {
@@ -43,6 +55,14 @@ public class DummyRestConsumerFactory implements RestConsumerFactory, RestApiCon
         if (id.startsWith("-")) {
             id = id.substring(1);
         }
+
+        if (configuration.getConsumerProperties() != null) {
+            String ref = (String) configuration.getConsumerProperties().get("dummy");
+            if (ref != null) {
+                dummy = CamelContextHelper.mandatoryLookup(camelContext, ref.substring(1));
+            }
+        }
+
         SedaEndpoint seda = camelContext.getEndpoint("seda:" + verb + "-" + id, SedaEndpoint.class);
         return seda.createConsumer(processor);
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/2c5264c5/camel-core/src/test/java/org/apache/camel/component/rest/FromRestConfigurationTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/rest/FromRestConfigurationTest.java
b/camel-core/src/test/java/org/apache/camel/component/rest/FromRestConfigurationTest.java
index 59e5e93..4930f16 100644
--- a/camel-core/src/test/java/org/apache/camel/component/rest/FromRestConfigurationTest.java
+++ b/camel-core/src/test/java/org/apache/camel/component/rest/FromRestConfigurationTest.java
@@ -17,9 +17,20 @@
 package org.apache.camel.component.rest;
 
 import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.impl.FooBar;
+import org.apache.camel.impl.JndiRegistry;
 
 public class FromRestConfigurationTest extends FromRestGetTest {
 
+    private Object myDummy = new FooBar();
+
+    @Override
+    protected JndiRegistry createRegistry() throws Exception {
+        JndiRegistry jndi = super.createRegistry();
+        jndi.bind("myDummy", myDummy);
+        return jndi;
+    }
+
     @Override
     public void testFromRestModel() throws Exception {
         super.testFromRestModel();
@@ -31,6 +42,10 @@ public class FromRestConfigurationTest extends FromRestGetTest {
         assertEquals("stuff", context.getRestConfiguration().getComponentProperties().get("other"));
         assertEquals("200", context.getRestConfiguration().getEndpointProperties().get("size"));
         assertEquals("1000", context.getRestConfiguration().getConsumerProperties().get("pollTimeout"));
+        assertEquals("#myDummy", context.getRestConfiguration().getConsumerProperties().get("dummy"));
+
+        DummyRestConsumerFactory factory = (DummyRestConsumerFactory) context.getRegistry().lookupByName("dummy-rest");
+        assertSame(myDummy, factory.getDummy());
     }
 
     @Override
@@ -43,10 +58,10 @@ public class FromRestConfigurationTest extends FromRestGetTest {
                     .componentProperty("foo", "bar")
                     .componentProperty("other", "stuff")
                     .endpointProperty("size", "200")
-                    .consumerProperty("pollTimeout", "1000");
+                    .consumerProperty("pollTimeout", "1000")
+                    .consumerProperty("dummy", "#myDummy");
 
                 includeRoutes(lowerR);
-
             }
         };
     }


Mime
View raw message