You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2014/10/20 10:34:16 UTC
[1/3] git commit: CAMEL-7931 Supports multi-valued property in
camel-jcr with thanks to Charlee
Repository: camel
Updated Branches:
refs/heads/camel-2.13.x 11cb32156 -> b0a2bfdee
refs/heads/camel-2.14.x 49fe1fd08 -> ae61e340d
CAMEL-7931 Supports multi-valued property in camel-jcr with thanks to Charlee
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/a11013c2
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/a11013c2
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/a11013c2
Branch: refs/heads/camel-2.14.x
Commit: a11013c2ff5923a459a5b880dc3e05d57bba095e
Parents: 49fe1fd
Author: Willem Jiang <wi...@gmail.com>
Authored: Mon Oct 20 15:16:52 2014 +0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Mon Oct 20 16:31:01 2014 +0800
----------------------------------------------------------------------
.../apache/camel/component/jcr/JcrProducer.java | 17 ++++++--
.../camel/component/jcr/JcrGetNodeByIdTest.java | 8 ++++
.../component/jcr/JcrNodePathCreationTest.java | 46 ++++++++++++++++++--
3 files changed, 65 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/a11013c2/components/camel-jcr/src/main/java/org/apache/camel/component/jcr/JcrProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-jcr/src/main/java/org/apache/camel/component/jcr/JcrProducer.java b/components/camel-jcr/src/main/java/org/apache/camel/component/jcr/JcrProducer.java
index 7234f30..7c2f141 100644
--- a/components/camel-jcr/src/main/java/org/apache/camel/component/jcr/JcrProducer.java
+++ b/components/camel-jcr/src/main/java/org/apache/camel/component/jcr/JcrProducer.java
@@ -53,8 +53,14 @@ public class JcrProducer extends DefaultProducer {
Node node = findOrCreateNode(base, getNodeName(message));
Map<String, Object> headers = filterComponentHeaders(message.getHeaders());
for (String key : headers.keySet()) {
- Value value = converter.convertTo(Value.class, exchange, message.getHeader(key));
- node.setProperty(key, value);
+ Object header = message.getHeader(key);
+ if (header != null && Object[].class.isAssignableFrom(header.getClass())) {
+ Value[] value = converter.convertTo(Value[].class, exchange, header);
+ node.setProperty(key, value);
+ } else {
+ Value value = converter.convertTo(Value.class, exchange, header);
+ node.setProperty(key, value);
+ }
}
node.addMixin("mix:referenceable");
exchange.getOut().setBody(node.getIdentifier());
@@ -66,7 +72,12 @@ public class JcrProducer extends DefaultProducer {
while (properties.hasNext()) {
Property property = properties.nextProperty();
Class<?> aClass = classForJCRType(property);
- Object value = converter.convertTo(aClass, exchange, property.getValue());
+ Object value;
+ if (property.isMultiple()) {
+ value = converter.convertTo(aClass, exchange, property.getValues());
+ } else {
+ value = converter.convertTo(aClass, exchange, property.getValue());
+ }
message.setHeader(property.getName(), value);
}
} else {
http://git-wip-us.apache.org/repos/asf/camel/blob/a11013c2/components/camel-jcr/src/test/java/org/apache/camel/component/jcr/JcrGetNodeByIdTest.java
----------------------------------------------------------------------
diff --git a/components/camel-jcr/src/test/java/org/apache/camel/component/jcr/JcrGetNodeByIdTest.java b/components/camel-jcr/src/test/java/org/apache/camel/component/jcr/JcrGetNodeByIdTest.java
index 3f525d6..c23c980 100644
--- a/components/camel-jcr/src/test/java/org/apache/camel/component/jcr/JcrGetNodeByIdTest.java
+++ b/components/camel-jcr/src/test/java/org/apache/camel/component/jcr/JcrGetNodeByIdTest.java
@@ -18,6 +18,8 @@ package org.apache.camel.component.jcr;
import javax.jcr.Node;
import javax.jcr.Session;
+import javax.jcr.Value;
+import javax.jcr.ValueFactory;
import org.apache.camel.EndpointInject;
import org.apache.camel.Exchange;
@@ -43,6 +45,12 @@ public class JcrGetNodeByIdTest extends JcrRouteTestSupport {
Node node = session.getRootNode().addNode("home").addNode("test");
node.setProperty("content.approved", APPROVED);
node.setProperty("my.contents.property", CONTENT);
+
+
+ ValueFactory valFact = session.getValueFactory();
+ Value[] vals = new Value[] {valFact.createValue("value-1"), valFact.createValue("value-2")};
+ node.setProperty("my.multi.valued", vals);
+
identifier = node.getIdentifier();
session.save();
http://git-wip-us.apache.org/repos/asf/camel/blob/a11013c2/components/camel-jcr/src/test/java/org/apache/camel/component/jcr/JcrNodePathCreationTest.java
----------------------------------------------------------------------
diff --git a/components/camel-jcr/src/test/java/org/apache/camel/component/jcr/JcrNodePathCreationTest.java b/components/camel-jcr/src/test/java/org/apache/camel/component/jcr/JcrNodePathCreationTest.java
index ab91ff3..4ffa3c5 100644
--- a/components/camel-jcr/src/test/java/org/apache/camel/component/jcr/JcrNodePathCreationTest.java
+++ b/components/camel-jcr/src/test/java/org/apache/camel/component/jcr/JcrNodePathCreationTest.java
@@ -18,13 +18,32 @@ package org.apache.camel.component.jcr;
import javax.jcr.Node;
import javax.jcr.Session;
+import javax.jcr.Value;
+import javax.jcr.ValueFactory;
import org.apache.camel.Exchange;
import org.apache.camel.builder.RouteBuilder;
+import org.junit.Before;
import org.junit.Test;
public class JcrNodePathCreationTest extends JcrRouteTestSupport {
+ private Value[] multiValued;
+
+ @Override
+ @Before
+ public void setUp() throws Exception {
+ super.setUp();
+
+ Session session = openSession();
+
+ ValueFactory valFact = session.getValueFactory();
+ multiValued = new Value[]{valFact.createValue("value-1"),
+ valFact.createValue("value-2")};
+
+ session.logout();
+ }
+
@Test
public void testJcrNodePathCreation() throws Exception {
Exchange exchange = createExchangeWithBody("<body/>");
@@ -43,7 +62,28 @@ public class JcrNodePathCreationTest extends JcrRouteTestSupport {
}
}
}
-
+
+ @Test
+ public void testJcrNodePathCreationMultiValued() throws Exception {
+ Exchange exchange = createExchangeWithBody(multiValued);
+ Exchange out = template.send("direct:a", exchange);
+ assertNotNull(out);
+ String uuid = out.getOut().getBody(String.class);
+ assertNotNull("Out body was null; expected JCR node UUID", uuid);
+ Session session = openSession();
+ try {
+ Node node = session.getNodeByIdentifier(uuid);
+ assertNotNull(node);
+ assertEquals("/home/test/node/with/path", node.getPath());
+ assertTrue(node.getProperty("my.contents.property").isMultiple());
+ assertArrayEquals(multiValued, node.getProperty("my.contents.property").getValues());
+ } finally {
+ if (session != null && session.isLive()) {
+ session.logout();
+ }
+ }
+ }
+
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@@ -51,10 +91,10 @@ public class JcrNodePathCreationTest extends JcrRouteTestSupport {
public void configure() throws Exception {
// START SNIPPET: jcr
from("direct:a").setHeader(JcrConstants.JCR_NODE_NAME, constant("node/with/path"))
- .setHeader("my.contents.property", body()).to("jcr://user:pass@repository/home/test");
+ .setHeader("my.contents.property", body()).to("jcr://user:pass@repository/home/test");
// END SNIPPET: jcr
}
};
}
-
+
}
[3/3] git commit: CAMEL-7932 Added setter,
getter and test for initial properties in PropertiesComponent
Posted by ni...@apache.org.
CAMEL-7932 Added setter, getter and test for initial properties in PropertiesComponent
Removed unnecessary null check
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/b0a2bfde
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/b0a2bfde
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/b0a2bfde
Branch: refs/heads/camel-2.13.x
Commit: b0a2bfdee79dab0c04a6702464a1ac9bec07d9f8
Parents: 11cb321
Author: Jyrki Ruuskanen <yu...@kotikone.fi>
Authored: Sun Oct 5 19:38:43 2014 +0300
Committer: Willem Jiang <wi...@gmail.com>
Committed: Mon Oct 20 16:32:59 2014 +0800
----------------------------------------------------------------------
.../properties/PropertiesComponent.java | 34 +++++++--
...ropertiesComponentInitialPropertiesTest.java | 72 ++++++++++++++++++++
2 files changed, 100 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/b0a2bfde/camel-core/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java b/camel-core/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java
index 24b2eba..31162fc 100644
--- a/camel-core/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java
+++ b/camel-core/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java
@@ -82,6 +82,7 @@ public class PropertiesComponent extends DefaultComponent {
private boolean fallbackToUnaugmentedProperty = true;
private String prefixToken = DEFAULT_PREFIX_TOKEN;
private String suffixToken = DEFAULT_SUFFIX_TOKEN;
+ private Properties initialProperties;
private Properties overrideProperties;
public PropertiesComponent() {
@@ -120,7 +121,14 @@ public class PropertiesComponent extends DefaultComponent {
}
public String parseUri(String uri, String... paths) throws Exception {
- Properties prop = null;
+ Properties prop = new Properties();
+
+ // use initial properties
+ if (null != initialProperties) {
+ prop.putAll(initialProperties);
+ }
+
+ // use locations
if (paths != null) {
// location may contain JVM system property or OS environment variables
// so we need to parse those
@@ -128,17 +136,18 @@ public class PropertiesComponent extends DefaultComponent {
// check cache first
CacheKey key = new CacheKey(locations);
- prop = cache ? cacheMap.get(key) : null;
- if (prop == null) {
- prop = propertiesResolver.resolveProperties(getCamelContext(), ignoreMissingLocation, locations);
+ Properties locationsProp = cache ? cacheMap.get(key) : null;
+ if (locationsProp == null) {
+ locationsProp = propertiesResolver.resolveProperties(getCamelContext(), ignoreMissingLocation, locations);
if (cache) {
- cacheMap.put(key, prop);
+ cacheMap.put(key, locationsProp);
}
}
+ prop.putAll(locationsProp);
}
// use override properties
- if (prop != null && overrideProperties != null) {
+ if (overrideProperties != null) {
// make a copy to avoid affecting the original properties
Properties override = new Properties();
override.putAll(prop);
@@ -272,6 +281,19 @@ public class PropertiesComponent extends DefaultComponent {
}
}
+ public Properties getInitialProperties() {
+ return initialProperties;
+ }
+
+ /**
+ * Sets initial properties which will be used before any locations are resolved.
+ *
+ * @param initialProperties properties that are added first
+ */
+ public void setInitialProperties(Properties initialProperties) {
+ this.initialProperties = initialProperties;
+ }
+
public Properties getOverrideProperties() {
return overrideProperties;
}
http://git-wip-us.apache.org/repos/asf/camel/blob/b0a2bfde/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentInitialPropertiesTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentInitialPropertiesTest.java b/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentInitialPropertiesTest.java
new file mode 100644
index 0000000..7bd4e1e
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentInitialPropertiesTest.java
@@ -0,0 +1,72 @@
+/**
+ * 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 java.util.Properties;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ * @version
+ */
+public class PropertiesComponentInitialPropertiesTest extends ContextTestSupport {
+
+ @Override
+ public boolean isUseRouteBuilder() {
+ return false;
+ }
+
+ public void testPropertiesComponentEndpoint() throws Exception {
+ context.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start")
+ .to("{{first}}")
+ .to("mock:{{second}}")
+ .to("{{cool.end}}");
+ }
+ });
+ context.start();
+
+ getMockEndpoint("mock:first").expectedMessageCount(1);
+ getMockEndpoint("mock:second").expectedMessageCount(1);
+ getMockEndpoint("mock:result").expectedMessageCount(1);
+
+ template.sendBody("direct:start", "Hello World");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @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);
+
+ Properties initial = new Properties();
+ initial.put("first", "mock:first");
+ initial.put("second", "second");
+ pc.setInitialProperties(initial);
+
+ return context;
+ }
+
+}
\ No newline at end of file
[2/3] git commit: CAMEL-7932 Added setter,
getter and test for initial properties in PropertiesComponent
Posted by ni...@apache.org.
CAMEL-7932 Added setter, getter and test for initial properties in PropertiesComponent
Removed unnecessary null check
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/ae61e340
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/ae61e340
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/ae61e340
Branch: refs/heads/camel-2.14.x
Commit: ae61e340dce5436dca4e289a98cdb15ed789f7b2
Parents: a11013c
Author: Jyrki Ruuskanen <yu...@kotikone.fi>
Authored: Sun Oct 5 19:38:43 2014 +0300
Committer: Willem Jiang <wi...@gmail.com>
Committed: Mon Oct 20 16:31:12 2014 +0800
----------------------------------------------------------------------
.../properties/PropertiesComponent.java | 34 +++++++--
...ropertiesComponentInitialPropertiesTest.java | 72 ++++++++++++++++++++
2 files changed, 100 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/ae61e340/camel-core/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java b/camel-core/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java
index 24b2eba..31162fc 100644
--- a/camel-core/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java
+++ b/camel-core/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java
@@ -82,6 +82,7 @@ public class PropertiesComponent extends DefaultComponent {
private boolean fallbackToUnaugmentedProperty = true;
private String prefixToken = DEFAULT_PREFIX_TOKEN;
private String suffixToken = DEFAULT_SUFFIX_TOKEN;
+ private Properties initialProperties;
private Properties overrideProperties;
public PropertiesComponent() {
@@ -120,7 +121,14 @@ public class PropertiesComponent extends DefaultComponent {
}
public String parseUri(String uri, String... paths) throws Exception {
- Properties prop = null;
+ Properties prop = new Properties();
+
+ // use initial properties
+ if (null != initialProperties) {
+ prop.putAll(initialProperties);
+ }
+
+ // use locations
if (paths != null) {
// location may contain JVM system property or OS environment variables
// so we need to parse those
@@ -128,17 +136,18 @@ public class PropertiesComponent extends DefaultComponent {
// check cache first
CacheKey key = new CacheKey(locations);
- prop = cache ? cacheMap.get(key) : null;
- if (prop == null) {
- prop = propertiesResolver.resolveProperties(getCamelContext(), ignoreMissingLocation, locations);
+ Properties locationsProp = cache ? cacheMap.get(key) : null;
+ if (locationsProp == null) {
+ locationsProp = propertiesResolver.resolveProperties(getCamelContext(), ignoreMissingLocation, locations);
if (cache) {
- cacheMap.put(key, prop);
+ cacheMap.put(key, locationsProp);
}
}
+ prop.putAll(locationsProp);
}
// use override properties
- if (prop != null && overrideProperties != null) {
+ if (overrideProperties != null) {
// make a copy to avoid affecting the original properties
Properties override = new Properties();
override.putAll(prop);
@@ -272,6 +281,19 @@ public class PropertiesComponent extends DefaultComponent {
}
}
+ public Properties getInitialProperties() {
+ return initialProperties;
+ }
+
+ /**
+ * Sets initial properties which will be used before any locations are resolved.
+ *
+ * @param initialProperties properties that are added first
+ */
+ public void setInitialProperties(Properties initialProperties) {
+ this.initialProperties = initialProperties;
+ }
+
public Properties getOverrideProperties() {
return overrideProperties;
}
http://git-wip-us.apache.org/repos/asf/camel/blob/ae61e340/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentInitialPropertiesTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentInitialPropertiesTest.java b/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentInitialPropertiesTest.java
new file mode 100644
index 0000000..7bd4e1e
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentInitialPropertiesTest.java
@@ -0,0 +1,72 @@
+/**
+ * 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 java.util.Properties;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ * @version
+ */
+public class PropertiesComponentInitialPropertiesTest extends ContextTestSupport {
+
+ @Override
+ public boolean isUseRouteBuilder() {
+ return false;
+ }
+
+ public void testPropertiesComponentEndpoint() throws Exception {
+ context.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start")
+ .to("{{first}}")
+ .to("mock:{{second}}")
+ .to("{{cool.end}}");
+ }
+ });
+ context.start();
+
+ getMockEndpoint("mock:first").expectedMessageCount(1);
+ getMockEndpoint("mock:second").expectedMessageCount(1);
+ getMockEndpoint("mock:result").expectedMessageCount(1);
+
+ template.sendBody("direct:start", "Hello World");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @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);
+
+ Properties initial = new Properties();
+ initial.put("first", "mock:first");
+ initial.put("second", "second");
+ pc.setInitialProperties(initial);
+
+ return context;
+ }
+
+}
\ No newline at end of file