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 2015/02/10 09:47:42 UTC
[10/10] camel git commit: CAMEL-8329: camel-sql - May not propagate
headers for operations with no resultset
CAMEL-8329: camel-sql - May not propagate headers for operations with no resultset
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/1de6f2bf
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/1de6f2bf
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/1de6f2bf
Branch: refs/heads/camel-2.13.x
Commit: 1de6f2bf7fd2d065e6a3d9bd6298c58abe629d07
Parents: ecf42a1
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Feb 10 09:46:47 2015 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Feb 10 09:47:50 2015 +0100
----------------------------------------------------------------------
.../java/org/apache/camel/component/sql/SqlProducer.java | 5 +++++
.../org/apache/camel/component/sql/SqlGeneratedKeysTest.java | 8 ++++++++
2 files changed, 13 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/1de6f2bf/components/camel-sql/src/main/java/org/apache/camel/component/sql/SqlProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-sql/src/main/java/org/apache/camel/component/sql/SqlProducer.java b/components/camel-sql/src/main/java/org/apache/camel/component/sql/SqlProducer.java
index 75ff08b..2dcfbc2 100644
--- a/components/camel-sql/src/main/java/org/apache/camel/component/sql/SqlProducer.java
+++ b/components/camel-sql/src/main/java/org/apache/camel/component/sql/SqlProducer.java
@@ -156,6 +156,11 @@ public class SqlProducer extends DefaultProducer {
}
if (shouldRetrieveGeneratedKeys) {
+ // if no OUT message yet then create one and propagate headers
+ if (!exchange.hasOut()) {
+ exchange.getOut().getHeaders().putAll(exchange.getIn().getHeaders());
+ }
+
if (isResultSet) {
// we won't return generated keys for SELECT statements
exchange.getOut().setHeader(SqlConstants.SQL_GENERATED_KEYS_DATA, Collections.EMPTY_LIST);
http://git-wip-us.apache.org/repos/asf/camel/blob/1de6f2bf/components/camel-sql/src/test/java/org/apache/camel/component/sql/SqlGeneratedKeysTest.java
----------------------------------------------------------------------
diff --git a/components/camel-sql/src/test/java/org/apache/camel/component/sql/SqlGeneratedKeysTest.java b/components/camel-sql/src/test/java/org/apache/camel/component/sql/SqlGeneratedKeysTest.java
index 8b6fa7f..54c19b7 100644
--- a/components/camel-sql/src/test/java/org/apache/camel/component/sql/SqlGeneratedKeysTest.java
+++ b/components/camel-sql/src/test/java/org/apache/camel/component/sql/SqlGeneratedKeysTest.java
@@ -106,6 +106,7 @@ public class SqlGeneratedKeysTest extends CamelTestSupport {
exchange.getIn().setBody(new Object[] {"Star Swirl", "Wizard"});
exchange.getIn().setHeader(SqlConstants.SQL_RETRIEVE_GENERATED_KEYS, true);
exchange.getIn().setHeader(SqlConstants.SQL_GENERATED_COLUMNS, new String[]{"ID1", "ID2"});
+ exchange.getIn().setHeader("foo", "123");
// now we send the exchange to the endpoint, and receives the response from Camel
Exchange out = template.send(endpoint, exchange);
@@ -114,6 +115,7 @@ public class SqlGeneratedKeysTest extends CamelTestSupport {
assertNotNull(out);
assertNotNull(out.getOut());
assertNotNull(out.getOut().getHeader(SqlConstants.SQL_GENERATED_KEYS_DATA));
+ assertEquals("123", out.getOut().getHeader("foo"));
List<Map<String, Object>> generatedKeys = out.getOut().getHeader(SqlConstants.SQL_GENERATED_KEYS_DATA, List.class);
assertNotNull("out body could not be converted to a List - was: "
@@ -141,6 +143,7 @@ public class SqlGeneratedKeysTest extends CamelTestSupport {
payload.add(new Object[] {"project q", "ASF", "new project q"});
exchange.getIn().setBody(payload);
exchange.getIn().setHeader(SqlConstants.SQL_RETRIEVE_GENERATED_KEYS, true);
+ exchange.getIn().setHeader("foo", "123");
// now we send the exchange to the endpoint, and receives the response from Camel
Exchange out = template.send(endpoint, exchange);
@@ -149,6 +152,7 @@ public class SqlGeneratedKeysTest extends CamelTestSupport {
assertNotNull(out);
assertNotNull(out.getOut());
assertNotNull(out.getOut().getHeader(SqlConstants.SQL_GENERATED_KEYS_DATA));
+ assertEquals("123", out.getOut().getHeader("foo"));
List<Map<String, Object>> generatedKeys = out.getOut().getHeader(SqlConstants.SQL_GENERATED_KEYS_DATA, List.class);
assertNotNull("out body could not be converted to a List - was: "
@@ -175,6 +179,7 @@ public class SqlGeneratedKeysTest extends CamelTestSupport {
exchange.getIn().setBody(new Object[] {"project x", "ASF", "new project"});
exchange.getIn().setHeader(SqlConstants.SQL_RETRIEVE_GENERATED_KEYS, true);
exchange.getIn().setHeader(SqlConstants.SQL_GENERATED_COLUMNS, new String[]{"ID"});
+ exchange.getIn().setHeader("foo", "123");
// now we send the exchange to the endpoint, and receives the response from Camel
Exchange out = template.send(endpoint, exchange);
@@ -183,6 +188,7 @@ public class SqlGeneratedKeysTest extends CamelTestSupport {
assertNotNull(out);
assertNotNull(out.getOut());
assertNotNull(out.getOut().getHeader(SqlConstants.SQL_GENERATED_KEYS_DATA));
+ assertEquals("123", out.getOut().getHeader("foo"));
List<Map<String, Object>> generatedKeys = out.getOut().getHeader(SqlConstants.SQL_GENERATED_KEYS_DATA, List.class);
assertNotNull("out body could not be converted to a List - was: "
@@ -205,6 +211,7 @@ public class SqlGeneratedKeysTest extends CamelTestSupport {
exchange.getIn().setBody(new Object[] {"project x", "ASF", "new project"});
exchange.getIn().setHeader(SqlConstants.SQL_RETRIEVE_GENERATED_KEYS, true);
exchange.getIn().setHeader(SqlConstants.SQL_GENERATED_COLUMNS, new int[]{1});
+ exchange.getIn().setHeader("foo", "123");
// now we send the exchange to the endpoint, and receives the response from Camel
Exchange out = template.send(endpoint, exchange);
@@ -212,6 +219,7 @@ public class SqlGeneratedKeysTest extends CamelTestSupport {
// assertions of the response
assertNotNull(out);
assertNotNull(out.getOut().getHeader(SqlConstants.SQL_GENERATED_KEYS_DATA));
+ assertEquals("123", out.getOut().getHeader("foo"));
List<Map<String, Object>> generatedKeys = out.getOut().getHeader(SqlConstants.SQL_GENERATED_KEYS_DATA, List.class);
assertNotNull("out body could not be converted to a List - was: "