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 2017/08/21 05:26:25 UTC
[1/2] camel git commit: CAMEL-11621: extend simple date formatter for
properties
Repository: camel
Updated Branches:
refs/heads/master 3c6a82935 -> dc4f20b30
CAMEL-11621: extend simple date formatter for properties
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/cc1037e6
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/cc1037e6
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/cc1037e6
Branch: refs/heads/master
Commit: cc1037e6a30bc1af35a8bc8fe682a54b20064e5b
Parents: 3c6a829
Author: sdirbach <sa...@endless-webservices.de>
Authored: Mon Aug 14 20:35:53 2017 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Mon Aug 21 07:22:10 2017 +0200
----------------------------------------------------------------------
.../apache/camel/builder/ExpressionBuilder.java | 6 ++++
.../camel/language/simple/SimpleLanguage.java | 1 +
.../camel/language/simple/SimpleTest.java | 30 ++++++++++++++++----
3 files changed, 32 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/cc1037e6/camel-core/src/main/java/org/apache/camel/builder/ExpressionBuilder.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/builder/ExpressionBuilder.java b/camel-core/src/main/java/org/apache/camel/builder/ExpressionBuilder.java
index d8ace9b..db91f21 100644
--- a/camel-core/src/main/java/org/apache/camel/builder/ExpressionBuilder.java
+++ b/camel-core/src/main/java/org/apache/camel/builder/ExpressionBuilder.java
@@ -1949,6 +1949,12 @@ public final class ExpressionBuilder {
if (date == null) {
throw new IllegalArgumentException("Cannot find java.util.Date object at command: " + command);
}
+ } else if (command.startsWith("property.")) {
+ String key = command.substring(command.lastIndexOf('.') + 1);
+ date = exchange.getProperty(key, Date.class);
+ if (date == null) {
+ throw new IllegalArgumentException("Cannot find java.util.Date object at command: " + command);
+ }
} else if ("file".equals(command)) {
Long num = exchange.getIn().getHeader(Exchange.FILE_LAST_MODIFIED, Long.class);
if (num != null && num > 0) {
http://git-wip-us.apache.org/repos/asf/camel/blob/cc1037e6/camel-core/src/main/java/org/apache/camel/language/simple/SimpleLanguage.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/language/simple/SimpleLanguage.java b/camel-core/src/main/java/org/apache/camel/language/simple/SimpleLanguage.java
index de4fc92..4685503 100644
--- a/camel-core/src/main/java/org/apache/camel/language/simple/SimpleLanguage.java
+++ b/camel-core/src/main/java/org/apache/camel/language/simple/SimpleLanguage.java
@@ -56,6 +56,7 @@ import org.slf4j.LoggerFactory;
* Supported commands are: <tt>now</tt> for current timestamp,
* <tt>in.header.xxx</tt> or <tt>header.xxx</tt> to use the Date object in the in header.
* <tt>out.header.xxx</tt> to use the Date object in the out header.
+ * <tt>property.xxx</tt> to use the Date object in the out header.
* <tt>file</tt> for the last modified timestamp of the file (available with a File consumer).
* Command accepts offsets such as: <tt>now-24h</tt> or <tt>in.header.xxx+1h</tt> or even <tt>now+1h30m-100</tt>.
* </li>
http://git-wip-us.apache.org/repos/asf/camel/blob/cc1037e6/camel-core/src/test/java/org/apache/camel/language/simple/SimpleTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/language/simple/SimpleTest.java b/camel-core/src/test/java/org/apache/camel/language/simple/SimpleTest.java
index 83a9945..5713265 100644
--- a/camel-core/src/test/java/org/apache/camel/language/simple/SimpleTest.java
+++ b/camel-core/src/test/java/org/apache/camel/language/simple/SimpleTest.java
@@ -479,13 +479,33 @@ public class SimpleTest extends LanguageTestSupport {
}
public void testDateExpressions() throws Exception {
- Calendar cal = Calendar.getInstance();
- cal.set(1974, Calendar.APRIL, 20);
- exchange.getIn().setHeader("birthday", cal.getTime());
-
- assertExpression("date:header.birthday", cal.getTime());
+ Calendar inHeaderCalendar = Calendar.getInstance();
+ inHeaderCalendar.set(1974, Calendar.APRIL, 20);
+ exchange.getIn().setHeader("birthday", inHeaderCalendar.getTime());
+
+ Calendar outHeaderCalendar = Calendar.getInstance();
+ outHeaderCalendar.set(1975, Calendar.MAY, 21);
+ exchange.getOut().setHeader("birthday", outHeaderCalendar.getTime());
+
+ Calendar propertyCalendar = Calendar.getInstance();
+ propertyCalendar.set(1976, Calendar.JUNE, 22);
+ exchange.setProperty("birthday", propertyCalendar.getTime());
+
+ assertExpression("date:header.birthday", inHeaderCalendar.getTime());
assertExpression("date:header.birthday:yyyyMMdd", "19740420");
assertExpression("date:header.birthday+24h:yyyyMMdd", "19740421");
+
+ assertExpression("date:in.header.birthday", inHeaderCalendar.getTime());
+ assertExpression("date:in.header.birthday:yyyyMMdd", "19740420");
+ assertExpression("date:in.header.birthday+24h:yyyyMMdd", "19740421");
+
+ assertExpression("date:out.header.birthday", outHeaderCalendar.getTime());
+ assertExpression("date:out.header.birthday:yyyyMMdd", "19750521");
+ assertExpression("date:out.header.birthday+24h:yyyyMMdd", "19750522");
+
+ assertExpression("date:property.birthday", propertyCalendar.getTime());
+ assertExpression("date:property.birthday:yyyyMMdd", "19760622");
+ assertExpression("date:property.birthday+24h:yyyyMMdd", "19760623");
try {
assertExpression("date:yyyyMMdd", "19740420");
[2/2] camel git commit: Polished. This fixes #1890
Posted by da...@apache.org.
Polished. This fixes #1890
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/dc4f20b3
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/dc4f20b3
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/dc4f20b3
Branch: refs/heads/master
Commit: dc4f20b30ac77cafe89242fbfc983ec860677608
Parents: cc1037e
Author: Claus Ibsen <da...@apache.org>
Authored: Mon Aug 21 07:24:23 2017 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Mon Aug 21 07:24:23 2017 +0200
----------------------------------------------------------------------
camel-core/src/main/docs/simple-language.adoc | 1 +
.../main/java/org/apache/camel/language/simple/SimpleLanguage.java | 2 +-
2 files changed, 2 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/dc4f20b3/camel-core/src/main/docs/simple-language.adoc
----------------------------------------------------------------------
diff --git a/camel-core/src/main/docs/simple-language.adoc b/camel-core/src/main/docs/simple-language.adoc
index c8e428c..0667746 100644
--- a/camel-core/src/main/docs/simple-language.adoc
+++ b/camel-core/src/main/docs/simple-language.adoc
@@ -221,6 +221,7 @@ exceptions (`Exchange.EXCEPTION_CAUGHT`) if the Exchange has any.
Supported commands are: *now* for current timestamp, *in.header.xxx* or
*header.xxx* to use the Date object in the IN header with the key xxx.
*out.header.xxx* to use the Date object in the OUT header with the key xxx.
+*property.xxx* to use the Date object in the exchange property with the key xxx.
*file* for the last modified timestamp of the file (available with a File consumer).
Command accepts offsets such as: *now-24h* or *in.header.xxx+1h* or even *now+1h30m-100*.
http://git-wip-us.apache.org/repos/asf/camel/blob/dc4f20b3/camel-core/src/main/java/org/apache/camel/language/simple/SimpleLanguage.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/language/simple/SimpleLanguage.java b/camel-core/src/main/java/org/apache/camel/language/simple/SimpleLanguage.java
index 4685503..94f952e 100644
--- a/camel-core/src/main/java/org/apache/camel/language/simple/SimpleLanguage.java
+++ b/camel-core/src/main/java/org/apache/camel/language/simple/SimpleLanguage.java
@@ -56,7 +56,7 @@ import org.slf4j.LoggerFactory;
* Supported commands are: <tt>now</tt> for current timestamp,
* <tt>in.header.xxx</tt> or <tt>header.xxx</tt> to use the Date object in the in header.
* <tt>out.header.xxx</tt> to use the Date object in the out header.
- * <tt>property.xxx</tt> to use the Date object in the out header.
+ * <tt>property.xxx</tt> to use the Date object in the exchange property.
* <tt>file</tt> for the last modified timestamp of the file (available with a File consumer).
* Command accepts offsets such as: <tt>now-24h</tt> or <tt>in.header.xxx+1h</tt> or even <tt>now+1h30m-100</tt>.
* </li>