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/03/14 08:15:56 UTC
[1/8] camel git commit: CAMEL-8484: File language - Should support
file extensions with multiple dots such as tar.gz
Repository: camel
Updated Branches:
refs/heads/camel-2.14.x 82d7c3a7c -> 8ac065074
refs/heads/camel-2.15.x 20ae65340 -> b668a89af
refs/heads/master 6a6e26217 -> b8590c834
CAMEL-8484: File language - Should support file extensions with multiple dots such as tar.gz
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/26450651
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/26450651
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/26450651
Branch: refs/heads/master
Commit: 26450651cc87b521a880ae8da74d90d4088e50d2
Parents: 6a6e262
Author: Claus Ibsen <da...@apache.org>
Authored: Sat Mar 14 07:41:16 2015 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Mar 14 07:41:16 2015 +0100
----------------------------------------------------------------------
.../apache/camel/builder/ExpressionBuilder.java | 6 +-----
.../java/org/apache/camel/util/FileUtil.java | 19 ++++++++++++++++++-
.../apache/camel/language/FileLanguageTest.java | 16 ++++++++++++++++
.../java/org/apache/camel/util/FileUtilTest.java | 9 +++++++++
4 files changed, 44 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/26450651/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 a5539e2..a31e895 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
@@ -1724,11 +1724,7 @@ public final class ExpressionBuilder {
return new ExpressionAdapter() {
public Object evaluate(Exchange exchange) {
String name = exchange.getIn().getHeader(Exchange.FILE_NAME, String.class);
- if (name != null) {
- return name.substring(name.lastIndexOf('.') + 1);
- } else {
- return null;
- }
+ return FileUtil.onlyExt(name);
}
@Override
http://git-wip-us.apache.org/repos/asf/camel/blob/26450651/camel-core/src/main/java/org/apache/camel/util/FileUtil.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/FileUtil.java b/camel-core/src/main/java/org/apache/camel/util/FileUtil.java
index e59b575..d3db672 100644
--- a/camel-core/src/main/java/org/apache/camel/util/FileUtil.java
+++ b/camel-core/src/main/java/org/apache/camel/util/FileUtil.java
@@ -194,13 +194,30 @@ public final class FileUtil {
if (name == null) {
return null;
}
- int pos = name.lastIndexOf('.');
+ name = stripPath(name);
+
+ // extension is the first dot, as a file may have double extension such as .tar.gz
+ int pos = name.indexOf('.');
if (pos != -1) {
return name.substring(0, pos);
}
return name;
}
+ public static String onlyExt(String name) {
+ if (name == null) {
+ return null;
+ }
+ name = stripPath(name);
+
+ // extension is the first dot, as a file may have double extension such as .tar.gz
+ int pos = name.indexOf('.');
+ if (pos != -1) {
+ return name.substring(pos + 1);
+ }
+ return null;
+ }
+
/**
* Returns only the leading path (returns <tt>null</tt> if no path)
*/
http://git-wip-us.apache.org/repos/asf/camel/blob/26450651/camel-core/src/test/java/org/apache/camel/language/FileLanguageTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/language/FileLanguageTest.java b/camel-core/src/test/java/org/apache/camel/language/FileLanguageTest.java
index 3208835..407b737 100644
--- a/camel-core/src/test/java/org/apache/camel/language/FileLanguageTest.java
+++ b/camel-core/src/test/java/org/apache/camel/language/FileLanguageTest.java
@@ -162,6 +162,22 @@ public class FileLanguageTest extends LanguageTestSupport {
assertExpression("target\\newdir\\onwindows\\${file:name}", "target\\newdir\\onwindows\\hello.txt");
}
+ public void testFileNameDoubleExtension() throws Exception {
+ file = new File("target/filelanguage/test/bigfile.tar.gz");
+
+ String uri = "file://target/filelanguage?fileExist=Override";
+ GenericFile<File> gf = FileConsumer.asGenericFile("target/filelanguage", file, null);
+
+ FileEndpoint endpoint = getMandatoryEndpoint(uri, FileEndpoint.class);
+
+ Exchange answer = endpoint.createExchange(gf);
+ endpoint.configureMessage(gf, answer.getIn());
+
+ assertEquals("bigfile.tar.gz", file.getName());
+ assertExpression(answer, "${file:onlyname}", "bigfile.tar.gz");
+ assertExpression(answer, "${file:ext}", "tar.gz");
+ }
+
public Exchange createExchange() {
// create the file
String uri = "file://target/filelanguage?fileExist=Override";
http://git-wip-us.apache.org/repos/asf/camel/blob/26450651/camel-core/src/test/java/org/apache/camel/util/FileUtilTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/util/FileUtilTest.java b/camel-core/src/test/java/org/apache/camel/util/FileUtilTest.java
index 1f84aad..d386bbc 100644
--- a/camel-core/src/test/java/org/apache/camel/util/FileUtilTest.java
+++ b/camel-core/src/test/java/org/apache/camel/util/FileUtilTest.java
@@ -110,6 +110,15 @@ public class FileUtilTest extends TestCase {
assertEquals("/foo/bar", FileUtil.stripExt("/foo/bar.xml"));
}
+ public void testOnlyExt() {
+ assertEquals(null, FileUtil.onlyExt(null));
+ assertEquals(null, FileUtil.onlyExt("foo"));
+ assertEquals("xml", FileUtil.onlyExt("foo.xml"));
+ assertEquals("xml", FileUtil.onlyExt("/foo/bar.xml"));
+ assertEquals("tar.gz", FileUtil.onlyExt("/foo/bigfile.tar.gz"));
+ assertEquals("tar.gz", FileUtil.onlyExt("/foo.bar/bigfile.tar.gz"));
+ }
+
public void testOnlyPath() {
assertEquals(null, FileUtil.onlyPath(null));
assertEquals(null, FileUtil.onlyPath("foo"));
[4/8] camel git commit: CAMEL-8484: File language - Should support
file extensions with multiple dots such as tar.gz
Posted by da...@apache.org.
CAMEL-8484: File language - Should support file extensions with multiple dots such as tar.gz
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/8ac06507
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/8ac06507
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/8ac06507
Branch: refs/heads/camel-2.14.x
Commit: 8ac0650748879329ef66bdacd5f2c05b9ffff048
Parents: bb3e510
Author: Claus Ibsen <da...@apache.org>
Authored: Sat Mar 14 08:16:17 2015 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Mar 14 08:17:13 2015 +0100
----------------------------------------------------------------------
.../java/org/apache/camel/util/FileUtil.java | 22 +++++++++++++++-----
1 file changed, 17 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/8ac06507/camel-core/src/main/java/org/apache/camel/util/FileUtil.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/FileUtil.java b/camel-core/src/main/java/org/apache/camel/util/FileUtil.java
index d3db672..8500d9a 100644
--- a/camel-core/src/main/java/org/apache/camel/util/FileUtil.java
+++ b/camel-core/src/main/java/org/apache/camel/util/FileUtil.java
@@ -194,13 +194,25 @@ public final class FileUtil {
if (name == null) {
return null;
}
- name = stripPath(name);
- // extension is the first dot, as a file may have double extension such as .tar.gz
- int pos = name.indexOf('.');
- if (pos != -1) {
- return name.substring(0, pos);
+ // the name may have a leading path
+ int posUnix = name.lastIndexOf('/');
+ int posWin = name.lastIndexOf('\\');
+ int pos = Math.max(posUnix, posWin);
+
+ if (pos > 0) {
+ String onlyName = name.substring(pos + 1);
+ int pos2 = onlyName.indexOf('.');
+ if (pos2 > 0) {
+ return name.substring(0, pos + pos2 + 1);
+ }
+ } else {
+ int pos2 = name.indexOf('.');
+ if (pos2 > 0) {
+ return name.substring(0, pos2);
+ }
}
+
return name;
}
[8/8] camel git commit: CAMEL-8484: File language - Should support
file extensions with multiple dots such as tar.gz
Posted by da...@apache.org.
CAMEL-8484: File language - Should support file extensions with multiple dots such as tar.gz
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/cfe8fb54
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/cfe8fb54
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/cfe8fb54
Branch: refs/heads/camel-2.15.x
Commit: cfe8fb54998d5be08e74c298f454e2e75f72deac
Parents: 20ae653
Author: Claus Ibsen <da...@apache.org>
Authored: Sat Mar 14 07:41:16 2015 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Mar 14 08:17:30 2015 +0100
----------------------------------------------------------------------
.../apache/camel/builder/ExpressionBuilder.java | 6 +-----
.../java/org/apache/camel/util/FileUtil.java | 19 ++++++++++++++++++-
.../apache/camel/language/FileLanguageTest.java | 16 ++++++++++++++++
.../java/org/apache/camel/util/FileUtilTest.java | 9 +++++++++
4 files changed, 44 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/cfe8fb54/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 a5539e2..a31e895 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
@@ -1724,11 +1724,7 @@ public final class ExpressionBuilder {
return new ExpressionAdapter() {
public Object evaluate(Exchange exchange) {
String name = exchange.getIn().getHeader(Exchange.FILE_NAME, String.class);
- if (name != null) {
- return name.substring(name.lastIndexOf('.') + 1);
- } else {
- return null;
- }
+ return FileUtil.onlyExt(name);
}
@Override
http://git-wip-us.apache.org/repos/asf/camel/blob/cfe8fb54/camel-core/src/main/java/org/apache/camel/util/FileUtil.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/FileUtil.java b/camel-core/src/main/java/org/apache/camel/util/FileUtil.java
index e59b575..d3db672 100644
--- a/camel-core/src/main/java/org/apache/camel/util/FileUtil.java
+++ b/camel-core/src/main/java/org/apache/camel/util/FileUtil.java
@@ -194,13 +194,30 @@ public final class FileUtil {
if (name == null) {
return null;
}
- int pos = name.lastIndexOf('.');
+ name = stripPath(name);
+
+ // extension is the first dot, as a file may have double extension such as .tar.gz
+ int pos = name.indexOf('.');
if (pos != -1) {
return name.substring(0, pos);
}
return name;
}
+ public static String onlyExt(String name) {
+ if (name == null) {
+ return null;
+ }
+ name = stripPath(name);
+
+ // extension is the first dot, as a file may have double extension such as .tar.gz
+ int pos = name.indexOf('.');
+ if (pos != -1) {
+ return name.substring(pos + 1);
+ }
+ return null;
+ }
+
/**
* Returns only the leading path (returns <tt>null</tt> if no path)
*/
http://git-wip-us.apache.org/repos/asf/camel/blob/cfe8fb54/camel-core/src/test/java/org/apache/camel/language/FileLanguageTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/language/FileLanguageTest.java b/camel-core/src/test/java/org/apache/camel/language/FileLanguageTest.java
index 3208835..407b737 100644
--- a/camel-core/src/test/java/org/apache/camel/language/FileLanguageTest.java
+++ b/camel-core/src/test/java/org/apache/camel/language/FileLanguageTest.java
@@ -162,6 +162,22 @@ public class FileLanguageTest extends LanguageTestSupport {
assertExpression("target\\newdir\\onwindows\\${file:name}", "target\\newdir\\onwindows\\hello.txt");
}
+ public void testFileNameDoubleExtension() throws Exception {
+ file = new File("target/filelanguage/test/bigfile.tar.gz");
+
+ String uri = "file://target/filelanguage?fileExist=Override";
+ GenericFile<File> gf = FileConsumer.asGenericFile("target/filelanguage", file, null);
+
+ FileEndpoint endpoint = getMandatoryEndpoint(uri, FileEndpoint.class);
+
+ Exchange answer = endpoint.createExchange(gf);
+ endpoint.configureMessage(gf, answer.getIn());
+
+ assertEquals("bigfile.tar.gz", file.getName());
+ assertExpression(answer, "${file:onlyname}", "bigfile.tar.gz");
+ assertExpression(answer, "${file:ext}", "tar.gz");
+ }
+
public Exchange createExchange() {
// create the file
String uri = "file://target/filelanguage?fileExist=Override";
http://git-wip-us.apache.org/repos/asf/camel/blob/cfe8fb54/camel-core/src/test/java/org/apache/camel/util/FileUtilTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/util/FileUtilTest.java b/camel-core/src/test/java/org/apache/camel/util/FileUtilTest.java
index 1f84aad..d386bbc 100644
--- a/camel-core/src/test/java/org/apache/camel/util/FileUtilTest.java
+++ b/camel-core/src/test/java/org/apache/camel/util/FileUtilTest.java
@@ -110,6 +110,15 @@ public class FileUtilTest extends TestCase {
assertEquals("/foo/bar", FileUtil.stripExt("/foo/bar.xml"));
}
+ public void testOnlyExt() {
+ assertEquals(null, FileUtil.onlyExt(null));
+ assertEquals(null, FileUtil.onlyExt("foo"));
+ assertEquals("xml", FileUtil.onlyExt("foo.xml"));
+ assertEquals("xml", FileUtil.onlyExt("/foo/bar.xml"));
+ assertEquals("tar.gz", FileUtil.onlyExt("/foo/bigfile.tar.gz"));
+ assertEquals("tar.gz", FileUtil.onlyExt("/foo.bar/bigfile.tar.gz"));
+ }
+
public void testOnlyPath() {
assertEquals(null, FileUtil.onlyPath(null));
assertEquals(null, FileUtil.onlyPath("foo"));
[7/8] camel git commit: Component documentation
Posted by da...@apache.org.
Component documentation
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/0aafc256
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/0aafc256
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/0aafc256
Branch: refs/heads/camel-2.15.x
Commit: 0aafc256b4344da9b4c833ebfff1b52d88dd6d5c
Parents: cfe8fb5
Author: Claus Ibsen <da...@apache.org>
Authored: Sat Mar 14 07:49:08 2015 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Mar 14 08:17:30 2015 +0100
----------------------------------------------------------------------
.../camel/component/mail/MailConfiguration.java | 111 ++++++++++++++++---
.../camel/component/mail/MailEndpoint.java | 6 +-
2 files changed, 102 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/0aafc256/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConfiguration.java
----------------------------------------------------------------------
diff --git a/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConfiguration.java b/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConfiguration.java
index d9cc01f..526e32c 100644
--- a/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConfiguration.java
+++ b/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConfiguration.java
@@ -41,9 +41,10 @@ import org.apache.camel.util.jsse.SSLContextParameters;
@UriParams
public class MailConfiguration implements Cloneable {
- private JavaMailSender javaMailSender;
+ private Session session;
private Properties javaMailProperties;
private Properties additionalJavaMailProperties;
+
// protocol is implied by component name so it should not be in UriPath
private String protocol;
@UriPath @Metadata(required = "true")
@@ -54,27 +55,28 @@ public class MailConfiguration implements Cloneable {
private String username;
@UriParam
private String password;
- @UriParam
+ @UriParam @Metadata(label = "producer")
private String subject;
- private Session session;
+ @UriParam @Metadata(label = "producer")
+ private JavaMailSender javaMailSender;
@UriParam(defaultValue = "true")
private boolean mapMailMessage = true;
- @UriParam(defaultValue = MailConstants.MAIL_DEFAULT_FROM)
+ @UriParam(defaultValue = MailConstants.MAIL_DEFAULT_FROM) @Metadata(label = "producer")
private String from = MailConstants.MAIL_DEFAULT_FROM;
- @UriParam(defaultValue = MailConstants.MAIL_DEFAULT_FOLDER)
+ @UriParam(defaultValue = MailConstants.MAIL_DEFAULT_FOLDER) @Metadata(label = "consumer")
private String folderName = MailConstants.MAIL_DEFAULT_FOLDER;
- @UriParam
+ @UriParam @Metadata(label = "consumer")
private boolean delete;
- @UriParam
+ @UriParam @Metadata(label = "consumer")
private String copyTo;
- @UriParam(defaultValue = "true")
+ @UriParam(defaultValue = "true") @Metadata(label = "consumer")
private boolean unseen = true;
@UriParam
private boolean ignoreUriScheme;
private Map<Message.RecipientType, String> recipients = new HashMap<Message.RecipientType, String>();
- @UriParam
+ @UriParam @Metadata(label = "producer")
private String replyTo;
- @UriParam(defaultValue = "-1")
+ @UriParam(defaultValue = "-1") @Metadata(label = "consumer")
private int fetchSize = -1;
@UriParam
private boolean debugMode;
@@ -90,11 +92,11 @@ public class MailConfiguration implements Cloneable {
private boolean useInlineAttachments;
@UriParam
private boolean ignoreUnsupportedCharset;
- @UriParam
+ @UriParam @Metadata(label = "consumer")
private boolean disconnect;
- @UriParam(defaultValue = "true")
+ @UriParam(defaultValue = "true") @Metadata(label = "consumer")
private boolean closeFolder = true;
- @UriParam(defaultValue = "true")
+ @UriParam(defaultValue = "true") @Metadata(label = "consumer")
private boolean peek = true;
@UriParam
private SSLContextParameters sslContextParameters;
@@ -267,6 +269,9 @@ public class MailConfiguration implements Cloneable {
return javaMailSender;
}
+ /**
+ * To use a custom {@link org.apache.camel.component.mail.JavaMailSender} for sending emails.
+ */
public void setJavaMailSender(JavaMailSender javaMailSender) {
this.javaMailSender = javaMailSender;
}
@@ -275,6 +280,9 @@ public class MailConfiguration implements Cloneable {
return host;
}
+ /**
+ * The mail server host name
+ */
public void setHost(String host) {
this.host = host;
}
@@ -311,6 +319,9 @@ public class MailConfiguration implements Cloneable {
return password;
}
+ /**
+ * The password for login
+ */
public void setPassword(String password) {
this.password = password;
}
@@ -319,6 +330,9 @@ public class MailConfiguration implements Cloneable {
return subject;
}
+ /**
+ * The Subject of the message being sent. Note: Setting the subject in the header takes precedence over this option.
+ */
public void setSubject(String subject) {
this.subject = subject;
}
@@ -327,6 +341,9 @@ public class MailConfiguration implements Cloneable {
return port;
}
+ /**
+ * The port number of the mail server
+ */
public void setPort(int port) {
this.port = port;
}
@@ -335,6 +352,9 @@ public class MailConfiguration implements Cloneable {
return protocol;
}
+ /**
+ * The protocol for communicating with the mail server
+ */
public void setProtocol(String protocol) {
this.protocol = protocol;
}
@@ -351,6 +371,9 @@ public class MailConfiguration implements Cloneable {
return username;
}
+ /**
+ * The username for login
+ */
public void setUsername(String username) {
this.username = username;
if (getRecipients().size() == 0) {
@@ -368,6 +391,9 @@ public class MailConfiguration implements Cloneable {
return from;
}
+ /**
+ * The from email address
+ */
public void setFrom(String from) {
this.from = from;
}
@@ -376,6 +402,11 @@ public class MailConfiguration implements Cloneable {
return delete;
}
+ /**
+ * Deletes the messages after they have been processed. This is done by setting the DELETED flag on the mail message.
+ * If false, the SEEN flag is set instead. As of Camel 2.10 you can override this configuration option by setting a
+ * header with the key delete to determine if the mail should be deleted or not.
+ */
public void setDelete(boolean delete) {
this.delete = delete;
}
@@ -392,6 +423,9 @@ public class MailConfiguration implements Cloneable {
return folderName;
}
+ /**
+ * The folder to poll.
+ */
public void setFolderName(String folderName) {
this.folderName = folderName;
}
@@ -400,6 +434,10 @@ public class MailConfiguration implements Cloneable {
return ignoreUriScheme;
}
+ /**
+ * Option to let Camel ignore unsupported charset in the local JVM when sending mails. If the charset is unsupported
+ * then charset=XXX (where XXX represents the unsupported charset) is removed from the content-type and it relies on the platform default instead.
+ */
public void setIgnoreUriScheme(boolean ignoreUriScheme) {
this.ignoreUriScheme = ignoreUriScheme;
}
@@ -408,6 +446,9 @@ public class MailConfiguration implements Cloneable {
return unseen;
}
+ /**
+ * Whether to limit by unseen mails only.
+ */
public void setUnseen(boolean unseen) {
this.unseen = unseen;
}
@@ -441,6 +482,9 @@ public class MailConfiguration implements Cloneable {
return replyTo;
}
+ /**
+ * The Reply-To recipients (the receivers of the response mail). Separate multiple email addresses with a comma.
+ */
public void setReplyTo(String replyTo) {
this.replyTo = replyTo;
}
@@ -449,6 +493,11 @@ public class MailConfiguration implements Cloneable {
return fetchSize;
}
+ /**
+ * Sets the maximum number of messages to consume during a poll. This can be used to avoid overloading a mail server,
+ * if a mailbox folder contains a lot of messages. Default value of -1 means no fetch size and all messages will be consumed.
+ * Setting the value to 0 is a special corner case, where Camel will not consume any messages at all.
+ */
public void setFetchSize(int fetchSize) {
this.fetchSize = fetchSize;
}
@@ -457,6 +506,9 @@ public class MailConfiguration implements Cloneable {
return debugMode;
}
+ /**
+ * Enable debug mode on the underlying mail framework. The SUN Mail framework logs the debug messages to System.out by default.
+ */
public void setDebugMode(boolean debugMode) {
this.debugMode = debugMode;
}
@@ -465,6 +517,9 @@ public class MailConfiguration implements Cloneable {
return connectionTimeout;
}
+ /**
+ * The connection timeout in milliseconds.
+ */
public void setConnectionTimeout(int connectionTimeout) {
this.connectionTimeout = connectionTimeout;
}
@@ -481,6 +536,9 @@ public class MailConfiguration implements Cloneable {
return contentType;
}
+ /**
+ * The mail message content type. Use text/html for HTML mails.
+ */
public void setContentType(String contentType) {
this.contentType = contentType;
}
@@ -489,6 +547,11 @@ public class MailConfiguration implements Cloneable {
return alternativeBodyHeader;
}
+ /**
+ * Specifies the key to an IN message header that contains an alternative email body.
+ * For example, if you send emails in text/html format and want to provide an alternative mail body for
+ * non-HTML email clients, set the alternative mail body with this key as a header.
+ */
public void setAlternativeBodyHeader(String alternativeBodyHeader) {
this.alternativeBodyHeader = alternativeBodyHeader;
}
@@ -505,6 +568,11 @@ public class MailConfiguration implements Cloneable {
return ignoreUnsupportedCharset;
}
+ /**
+ * Option to let Camel ignore unsupported charset in the local JVM when sending mails.
+ * If the charset is unsupported then charset=XXX (where XXX represents the unsupported charset)
+ * is removed from the content-type and it relies on the platform default instead.
+ */
public void setIgnoreUnsupportedCharset(boolean ignoreUnsupportedCharset) {
this.ignoreUnsupportedCharset = ignoreUnsupportedCharset;
}
@@ -513,6 +581,9 @@ public class MailConfiguration implements Cloneable {
return disconnect;
}
+ /**
+ * Whether the consumer should disconnect after polling. If enabled this forces Camel to connect on each poll.
+ */
public void setDisconnect(boolean disconnect) {
this.disconnect = disconnect;
}
@@ -521,6 +592,10 @@ public class MailConfiguration implements Cloneable {
return closeFolder;
}
+ /**
+ * Whether the consumer should close the folder after polling. Setting this option to false and having disconnect=false as well,
+ * then the consumer keep the folder open between polls.
+ */
public void setCloseFolder(boolean closeFolder) {
this.closeFolder = closeFolder;
}
@@ -537,6 +612,11 @@ public class MailConfiguration implements Cloneable {
return copyTo;
}
+ /**
+ * After processing a mail message, it can be copied to a mail folder with the given name.
+ * You can override this configuration value, with a header with the key copyTo, allowing you to copy messages
+ * to folder names configured at runtime.
+ */
public void setCopyTo(String copyTo) {
this.copyTo = copyTo;
}
@@ -545,6 +625,11 @@ public class MailConfiguration implements Cloneable {
return peek;
}
+ /**
+ * Will mark the javax.mail.Message as peeked before processing the mail message.
+ * This applies to IMAPMessage messages types only. By using peek the mail will not be eager marked as SEEN on
+ * the mail server, which allows us to rollback the mail message if there is an error processing in Camel.
+ */
public void setPeek(boolean peek) {
this.peek = peek;
}
http://git-wip-us.apache.org/repos/asf/camel/blob/0aafc256/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailEndpoint.java b/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailEndpoint.java
index f2e0080..a7a89cd 100644
--- a/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailEndpoint.java
+++ b/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailEndpoint.java
@@ -20,7 +20,6 @@ import javax.mail.Message;
import javax.mail.search.SearchTerm;
import com.sun.mail.imap.SortTerm;
-
import org.apache.camel.Consumer;
import org.apache.camel.Exchange;
import org.apache.camel.ExchangePattern;
@@ -37,10 +36,13 @@ import org.apache.camel.spi.UriParam;
*/
@UriEndpoint(scheme = "imap,imaps,pop3,pop3s,smtp,smtps", syntax = "imap:host:port", consumerClass = MailConsumer.class, label = "mail")
public class MailEndpoint extends ScheduledPollEndpoint {
- private MailBinding binding;
@UriParam
private MailConfiguration configuration;
+ @UriParam
+ private MailBinding binding;
+ @UriParam
private HeaderFilterStrategy headerFilterStrategy = new MailHeaderFilterStrategy();
+ @UriParam
private ContentTypeResolver contentTypeResolver;
@UriParam
private int maxMessagesPerPoll;
[6/8] camel git commit: CAMEL-8484: File language - Should support
file extensions with multiple dots such as tar.gz
Posted by da...@apache.org.
CAMEL-8484: File language - Should support file extensions with multiple dots such as tar.gz
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/b668a89a
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/b668a89a
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/b668a89a
Branch: refs/heads/camel-2.15.x
Commit: b668a89af613a464856d24b57aa860a320bba47d
Parents: 0aafc25
Author: Claus Ibsen <da...@apache.org>
Authored: Sat Mar 14 08:16:17 2015 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Mar 14 08:17:30 2015 +0100
----------------------------------------------------------------------
.../java/org/apache/camel/util/FileUtil.java | 22 +++++++++++++++-----
1 file changed, 17 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/b668a89a/camel-core/src/main/java/org/apache/camel/util/FileUtil.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/FileUtil.java b/camel-core/src/main/java/org/apache/camel/util/FileUtil.java
index d3db672..8500d9a 100644
--- a/camel-core/src/main/java/org/apache/camel/util/FileUtil.java
+++ b/camel-core/src/main/java/org/apache/camel/util/FileUtil.java
@@ -194,13 +194,25 @@ public final class FileUtil {
if (name == null) {
return null;
}
- name = stripPath(name);
- // extension is the first dot, as a file may have double extension such as .tar.gz
- int pos = name.indexOf('.');
- if (pos != -1) {
- return name.substring(0, pos);
+ // the name may have a leading path
+ int posUnix = name.lastIndexOf('/');
+ int posWin = name.lastIndexOf('\\');
+ int pos = Math.max(posUnix, posWin);
+
+ if (pos > 0) {
+ String onlyName = name.substring(pos + 1);
+ int pos2 = onlyName.indexOf('.');
+ if (pos2 > 0) {
+ return name.substring(0, pos + pos2 + 1);
+ }
+ } else {
+ int pos2 = name.indexOf('.');
+ if (pos2 > 0) {
+ return name.substring(0, pos2);
+ }
}
+
return name;
}
[2/8] camel git commit: Component documentation
Posted by da...@apache.org.
Component documentation
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/5174a1ca
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/5174a1ca
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/5174a1ca
Branch: refs/heads/master
Commit: 5174a1ca1a08c11815fd48fc0dfc4b1e92b34269
Parents: 2645065
Author: Claus Ibsen <da...@apache.org>
Authored: Sat Mar 14 07:49:08 2015 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Mar 14 08:03:21 2015 +0100
----------------------------------------------------------------------
.../camel/component/mail/MailConfiguration.java | 111 ++++++++++++++++---
.../camel/component/mail/MailEndpoint.java | 6 +-
2 files changed, 102 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/5174a1ca/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConfiguration.java
----------------------------------------------------------------------
diff --git a/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConfiguration.java b/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConfiguration.java
index d9cc01f..526e32c 100644
--- a/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConfiguration.java
+++ b/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConfiguration.java
@@ -41,9 +41,10 @@ import org.apache.camel.util.jsse.SSLContextParameters;
@UriParams
public class MailConfiguration implements Cloneable {
- private JavaMailSender javaMailSender;
+ private Session session;
private Properties javaMailProperties;
private Properties additionalJavaMailProperties;
+
// protocol is implied by component name so it should not be in UriPath
private String protocol;
@UriPath @Metadata(required = "true")
@@ -54,27 +55,28 @@ public class MailConfiguration implements Cloneable {
private String username;
@UriParam
private String password;
- @UriParam
+ @UriParam @Metadata(label = "producer")
private String subject;
- private Session session;
+ @UriParam @Metadata(label = "producer")
+ private JavaMailSender javaMailSender;
@UriParam(defaultValue = "true")
private boolean mapMailMessage = true;
- @UriParam(defaultValue = MailConstants.MAIL_DEFAULT_FROM)
+ @UriParam(defaultValue = MailConstants.MAIL_DEFAULT_FROM) @Metadata(label = "producer")
private String from = MailConstants.MAIL_DEFAULT_FROM;
- @UriParam(defaultValue = MailConstants.MAIL_DEFAULT_FOLDER)
+ @UriParam(defaultValue = MailConstants.MAIL_DEFAULT_FOLDER) @Metadata(label = "consumer")
private String folderName = MailConstants.MAIL_DEFAULT_FOLDER;
- @UriParam
+ @UriParam @Metadata(label = "consumer")
private boolean delete;
- @UriParam
+ @UriParam @Metadata(label = "consumer")
private String copyTo;
- @UriParam(defaultValue = "true")
+ @UriParam(defaultValue = "true") @Metadata(label = "consumer")
private boolean unseen = true;
@UriParam
private boolean ignoreUriScheme;
private Map<Message.RecipientType, String> recipients = new HashMap<Message.RecipientType, String>();
- @UriParam
+ @UriParam @Metadata(label = "producer")
private String replyTo;
- @UriParam(defaultValue = "-1")
+ @UriParam(defaultValue = "-1") @Metadata(label = "consumer")
private int fetchSize = -1;
@UriParam
private boolean debugMode;
@@ -90,11 +92,11 @@ public class MailConfiguration implements Cloneable {
private boolean useInlineAttachments;
@UriParam
private boolean ignoreUnsupportedCharset;
- @UriParam
+ @UriParam @Metadata(label = "consumer")
private boolean disconnect;
- @UriParam(defaultValue = "true")
+ @UriParam(defaultValue = "true") @Metadata(label = "consumer")
private boolean closeFolder = true;
- @UriParam(defaultValue = "true")
+ @UriParam(defaultValue = "true") @Metadata(label = "consumer")
private boolean peek = true;
@UriParam
private SSLContextParameters sslContextParameters;
@@ -267,6 +269,9 @@ public class MailConfiguration implements Cloneable {
return javaMailSender;
}
+ /**
+ * To use a custom {@link org.apache.camel.component.mail.JavaMailSender} for sending emails.
+ */
public void setJavaMailSender(JavaMailSender javaMailSender) {
this.javaMailSender = javaMailSender;
}
@@ -275,6 +280,9 @@ public class MailConfiguration implements Cloneable {
return host;
}
+ /**
+ * The mail server host name
+ */
public void setHost(String host) {
this.host = host;
}
@@ -311,6 +319,9 @@ public class MailConfiguration implements Cloneable {
return password;
}
+ /**
+ * The password for login
+ */
public void setPassword(String password) {
this.password = password;
}
@@ -319,6 +330,9 @@ public class MailConfiguration implements Cloneable {
return subject;
}
+ /**
+ * The Subject of the message being sent. Note: Setting the subject in the header takes precedence over this option.
+ */
public void setSubject(String subject) {
this.subject = subject;
}
@@ -327,6 +341,9 @@ public class MailConfiguration implements Cloneable {
return port;
}
+ /**
+ * The port number of the mail server
+ */
public void setPort(int port) {
this.port = port;
}
@@ -335,6 +352,9 @@ public class MailConfiguration implements Cloneable {
return protocol;
}
+ /**
+ * The protocol for communicating with the mail server
+ */
public void setProtocol(String protocol) {
this.protocol = protocol;
}
@@ -351,6 +371,9 @@ public class MailConfiguration implements Cloneable {
return username;
}
+ /**
+ * The username for login
+ */
public void setUsername(String username) {
this.username = username;
if (getRecipients().size() == 0) {
@@ -368,6 +391,9 @@ public class MailConfiguration implements Cloneable {
return from;
}
+ /**
+ * The from email address
+ */
public void setFrom(String from) {
this.from = from;
}
@@ -376,6 +402,11 @@ public class MailConfiguration implements Cloneable {
return delete;
}
+ /**
+ * Deletes the messages after they have been processed. This is done by setting the DELETED flag on the mail message.
+ * If false, the SEEN flag is set instead. As of Camel 2.10 you can override this configuration option by setting a
+ * header with the key delete to determine if the mail should be deleted or not.
+ */
public void setDelete(boolean delete) {
this.delete = delete;
}
@@ -392,6 +423,9 @@ public class MailConfiguration implements Cloneable {
return folderName;
}
+ /**
+ * The folder to poll.
+ */
public void setFolderName(String folderName) {
this.folderName = folderName;
}
@@ -400,6 +434,10 @@ public class MailConfiguration implements Cloneable {
return ignoreUriScheme;
}
+ /**
+ * Option to let Camel ignore unsupported charset in the local JVM when sending mails. If the charset is unsupported
+ * then charset=XXX (where XXX represents the unsupported charset) is removed from the content-type and it relies on the platform default instead.
+ */
public void setIgnoreUriScheme(boolean ignoreUriScheme) {
this.ignoreUriScheme = ignoreUriScheme;
}
@@ -408,6 +446,9 @@ public class MailConfiguration implements Cloneable {
return unseen;
}
+ /**
+ * Whether to limit by unseen mails only.
+ */
public void setUnseen(boolean unseen) {
this.unseen = unseen;
}
@@ -441,6 +482,9 @@ public class MailConfiguration implements Cloneable {
return replyTo;
}
+ /**
+ * The Reply-To recipients (the receivers of the response mail). Separate multiple email addresses with a comma.
+ */
public void setReplyTo(String replyTo) {
this.replyTo = replyTo;
}
@@ -449,6 +493,11 @@ public class MailConfiguration implements Cloneable {
return fetchSize;
}
+ /**
+ * Sets the maximum number of messages to consume during a poll. This can be used to avoid overloading a mail server,
+ * if a mailbox folder contains a lot of messages. Default value of -1 means no fetch size and all messages will be consumed.
+ * Setting the value to 0 is a special corner case, where Camel will not consume any messages at all.
+ */
public void setFetchSize(int fetchSize) {
this.fetchSize = fetchSize;
}
@@ -457,6 +506,9 @@ public class MailConfiguration implements Cloneable {
return debugMode;
}
+ /**
+ * Enable debug mode on the underlying mail framework. The SUN Mail framework logs the debug messages to System.out by default.
+ */
public void setDebugMode(boolean debugMode) {
this.debugMode = debugMode;
}
@@ -465,6 +517,9 @@ public class MailConfiguration implements Cloneable {
return connectionTimeout;
}
+ /**
+ * The connection timeout in milliseconds.
+ */
public void setConnectionTimeout(int connectionTimeout) {
this.connectionTimeout = connectionTimeout;
}
@@ -481,6 +536,9 @@ public class MailConfiguration implements Cloneable {
return contentType;
}
+ /**
+ * The mail message content type. Use text/html for HTML mails.
+ */
public void setContentType(String contentType) {
this.contentType = contentType;
}
@@ -489,6 +547,11 @@ public class MailConfiguration implements Cloneable {
return alternativeBodyHeader;
}
+ /**
+ * Specifies the key to an IN message header that contains an alternative email body.
+ * For example, if you send emails in text/html format and want to provide an alternative mail body for
+ * non-HTML email clients, set the alternative mail body with this key as a header.
+ */
public void setAlternativeBodyHeader(String alternativeBodyHeader) {
this.alternativeBodyHeader = alternativeBodyHeader;
}
@@ -505,6 +568,11 @@ public class MailConfiguration implements Cloneable {
return ignoreUnsupportedCharset;
}
+ /**
+ * Option to let Camel ignore unsupported charset in the local JVM when sending mails.
+ * If the charset is unsupported then charset=XXX (where XXX represents the unsupported charset)
+ * is removed from the content-type and it relies on the platform default instead.
+ */
public void setIgnoreUnsupportedCharset(boolean ignoreUnsupportedCharset) {
this.ignoreUnsupportedCharset = ignoreUnsupportedCharset;
}
@@ -513,6 +581,9 @@ public class MailConfiguration implements Cloneable {
return disconnect;
}
+ /**
+ * Whether the consumer should disconnect after polling. If enabled this forces Camel to connect on each poll.
+ */
public void setDisconnect(boolean disconnect) {
this.disconnect = disconnect;
}
@@ -521,6 +592,10 @@ public class MailConfiguration implements Cloneable {
return closeFolder;
}
+ /**
+ * Whether the consumer should close the folder after polling. Setting this option to false and having disconnect=false as well,
+ * then the consumer keep the folder open between polls.
+ */
public void setCloseFolder(boolean closeFolder) {
this.closeFolder = closeFolder;
}
@@ -537,6 +612,11 @@ public class MailConfiguration implements Cloneable {
return copyTo;
}
+ /**
+ * After processing a mail message, it can be copied to a mail folder with the given name.
+ * You can override this configuration value, with a header with the key copyTo, allowing you to copy messages
+ * to folder names configured at runtime.
+ */
public void setCopyTo(String copyTo) {
this.copyTo = copyTo;
}
@@ -545,6 +625,11 @@ public class MailConfiguration implements Cloneable {
return peek;
}
+ /**
+ * Will mark the javax.mail.Message as peeked before processing the mail message.
+ * This applies to IMAPMessage messages types only. By using peek the mail will not be eager marked as SEEN on
+ * the mail server, which allows us to rollback the mail message if there is an error processing in Camel.
+ */
public void setPeek(boolean peek) {
this.peek = peek;
}
http://git-wip-us.apache.org/repos/asf/camel/blob/5174a1ca/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailEndpoint.java b/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailEndpoint.java
index f2e0080..a7a89cd 100644
--- a/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailEndpoint.java
+++ b/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailEndpoint.java
@@ -20,7 +20,6 @@ import javax.mail.Message;
import javax.mail.search.SearchTerm;
import com.sun.mail.imap.SortTerm;
-
import org.apache.camel.Consumer;
import org.apache.camel.Exchange;
import org.apache.camel.ExchangePattern;
@@ -37,10 +36,13 @@ import org.apache.camel.spi.UriParam;
*/
@UriEndpoint(scheme = "imap,imaps,pop3,pop3s,smtp,smtps", syntax = "imap:host:port", consumerClass = MailConsumer.class, label = "mail")
public class MailEndpoint extends ScheduledPollEndpoint {
- private MailBinding binding;
@UriParam
private MailConfiguration configuration;
+ @UriParam
+ private MailBinding binding;
+ @UriParam
private HeaderFilterStrategy headerFilterStrategy = new MailHeaderFilterStrategy();
+ @UriParam
private ContentTypeResolver contentTypeResolver;
@UriParam
private int maxMessagesPerPoll;
[5/8] camel git commit: CAMEL-8484: File language - Should support
file extensions with multiple dots such as tar.gz
Posted by da...@apache.org.
CAMEL-8484: File language - Should support file extensions with multiple dots such as tar.gz
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/bb3e5107
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/bb3e5107
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/bb3e5107
Branch: refs/heads/camel-2.14.x
Commit: bb3e5107a69bb6e3882af9f4d7a2115edf2fa2f7
Parents: 82d7c3a
Author: Claus Ibsen <da...@apache.org>
Authored: Sat Mar 14 07:41:16 2015 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Mar 14 08:17:13 2015 +0100
----------------------------------------------------------------------
.../apache/camel/builder/ExpressionBuilder.java | 6 +-----
.../java/org/apache/camel/util/FileUtil.java | 19 ++++++++++++++++++-
.../apache/camel/language/FileLanguageTest.java | 16 ++++++++++++++++
.../java/org/apache/camel/util/FileUtilTest.java | 9 +++++++++
4 files changed, 44 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/bb3e5107/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 4473fe7..f0333ed 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
@@ -1698,11 +1698,7 @@ public final class ExpressionBuilder {
return new ExpressionAdapter() {
public Object evaluate(Exchange exchange) {
String name = exchange.getIn().getHeader(Exchange.FILE_NAME, String.class);
- if (name != null) {
- return name.substring(name.lastIndexOf('.') + 1);
- } else {
- return null;
- }
+ return FileUtil.onlyExt(name);
}
@Override
http://git-wip-us.apache.org/repos/asf/camel/blob/bb3e5107/camel-core/src/main/java/org/apache/camel/util/FileUtil.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/FileUtil.java b/camel-core/src/main/java/org/apache/camel/util/FileUtil.java
index e59b575..d3db672 100644
--- a/camel-core/src/main/java/org/apache/camel/util/FileUtil.java
+++ b/camel-core/src/main/java/org/apache/camel/util/FileUtil.java
@@ -194,13 +194,30 @@ public final class FileUtil {
if (name == null) {
return null;
}
- int pos = name.lastIndexOf('.');
+ name = stripPath(name);
+
+ // extension is the first dot, as a file may have double extension such as .tar.gz
+ int pos = name.indexOf('.');
if (pos != -1) {
return name.substring(0, pos);
}
return name;
}
+ public static String onlyExt(String name) {
+ if (name == null) {
+ return null;
+ }
+ name = stripPath(name);
+
+ // extension is the first dot, as a file may have double extension such as .tar.gz
+ int pos = name.indexOf('.');
+ if (pos != -1) {
+ return name.substring(pos + 1);
+ }
+ return null;
+ }
+
/**
* Returns only the leading path (returns <tt>null</tt> if no path)
*/
http://git-wip-us.apache.org/repos/asf/camel/blob/bb3e5107/camel-core/src/test/java/org/apache/camel/language/FileLanguageTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/language/FileLanguageTest.java b/camel-core/src/test/java/org/apache/camel/language/FileLanguageTest.java
index 3208835..407b737 100644
--- a/camel-core/src/test/java/org/apache/camel/language/FileLanguageTest.java
+++ b/camel-core/src/test/java/org/apache/camel/language/FileLanguageTest.java
@@ -162,6 +162,22 @@ public class FileLanguageTest extends LanguageTestSupport {
assertExpression("target\\newdir\\onwindows\\${file:name}", "target\\newdir\\onwindows\\hello.txt");
}
+ public void testFileNameDoubleExtension() throws Exception {
+ file = new File("target/filelanguage/test/bigfile.tar.gz");
+
+ String uri = "file://target/filelanguage?fileExist=Override";
+ GenericFile<File> gf = FileConsumer.asGenericFile("target/filelanguage", file, null);
+
+ FileEndpoint endpoint = getMandatoryEndpoint(uri, FileEndpoint.class);
+
+ Exchange answer = endpoint.createExchange(gf);
+ endpoint.configureMessage(gf, answer.getIn());
+
+ assertEquals("bigfile.tar.gz", file.getName());
+ assertExpression(answer, "${file:onlyname}", "bigfile.tar.gz");
+ assertExpression(answer, "${file:ext}", "tar.gz");
+ }
+
public Exchange createExchange() {
// create the file
String uri = "file://target/filelanguage?fileExist=Override";
http://git-wip-us.apache.org/repos/asf/camel/blob/bb3e5107/camel-core/src/test/java/org/apache/camel/util/FileUtilTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/util/FileUtilTest.java b/camel-core/src/test/java/org/apache/camel/util/FileUtilTest.java
index 89446e9..2160683 100644
--- a/camel-core/src/test/java/org/apache/camel/util/FileUtilTest.java
+++ b/camel-core/src/test/java/org/apache/camel/util/FileUtilTest.java
@@ -110,6 +110,15 @@ public class FileUtilTest extends TestCase {
assertEquals("/foo/bar", FileUtil.stripExt("/foo/bar.xml"));
}
+ public void testOnlyExt() {
+ assertEquals(null, FileUtil.onlyExt(null));
+ assertEquals(null, FileUtil.onlyExt("foo"));
+ assertEquals("xml", FileUtil.onlyExt("foo.xml"));
+ assertEquals("xml", FileUtil.onlyExt("/foo/bar.xml"));
+ assertEquals("tar.gz", FileUtil.onlyExt("/foo/bigfile.tar.gz"));
+ assertEquals("tar.gz", FileUtil.onlyExt("/foo.bar/bigfile.tar.gz"));
+ }
+
public void testOnlyPath() {
assertEquals(null, FileUtil.onlyPath(null));
assertEquals(null, FileUtil.onlyPath("foo"));
[3/8] camel git commit: CAMEL-8484: File language - Should support
file extensions with multiple dots such as tar.gz
Posted by da...@apache.org.
CAMEL-8484: File language - Should support file extensions with multiple dots such as tar.gz
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/b8590c83
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/b8590c83
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/b8590c83
Branch: refs/heads/master
Commit: b8590c834a0855c22870085fb132f21eccb3c474
Parents: 5174a1c
Author: Claus Ibsen <da...@apache.org>
Authored: Sat Mar 14 08:16:17 2015 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Mar 14 08:16:17 2015 +0100
----------------------------------------------------------------------
.../java/org/apache/camel/util/FileUtil.java | 22 +++++++++++++++-----
1 file changed, 17 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/b8590c83/camel-core/src/main/java/org/apache/camel/util/FileUtil.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/FileUtil.java b/camel-core/src/main/java/org/apache/camel/util/FileUtil.java
index d3db672..8500d9a 100644
--- a/camel-core/src/main/java/org/apache/camel/util/FileUtil.java
+++ b/camel-core/src/main/java/org/apache/camel/util/FileUtil.java
@@ -194,13 +194,25 @@ public final class FileUtil {
if (name == null) {
return null;
}
- name = stripPath(name);
- // extension is the first dot, as a file may have double extension such as .tar.gz
- int pos = name.indexOf('.');
- if (pos != -1) {
- return name.substring(0, pos);
+ // the name may have a leading path
+ int posUnix = name.lastIndexOf('/');
+ int posWin = name.lastIndexOf('\\');
+ int pos = Math.max(posUnix, posWin);
+
+ if (pos > 0) {
+ String onlyName = name.substring(pos + 1);
+ int pos2 = onlyName.indexOf('.');
+ if (pos2 > 0) {
+ return name.substring(0, pos + pos2 + 1);
+ }
+ } else {
+ int pos2 = name.indexOf('.');
+ if (pos2 > 0) {
+ return name.substring(0, pos2);
+ }
}
+
return name;
}