Author: davsclaus
Date: Sun Jan 24 16:23:10 2010
New Revision: 902594
URL: http://svn.apache.org/viewvc?rev=902594&view=rev
Log:
CAMEL-2395: fileName should only detect constant file name and use constant
expression to avoid rare clash with simple langauge tokens.
Added:
camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileProducerFilenameConstantTest.java
(with props)
camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FromFileMulticastToFilesTest.java
(with props)
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileEndpoint.java
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileEndpoint.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileEndpoint.java?rev=902594&r1=902593&r2=902594&view=diff
==============================================================================
---
camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileEndpoint.java
(original)
+++
camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileEndpoint.java
Sun Jan 24 16:23:10 2010
@@ -215,7 +215,7 @@
*/
public void setMoveFailed(String fileLanguageExpression) {
String expression =
configureMoveOrPreMoveExpression(fileLanguageExpression);
- this.moveFailed = createFileLangugeExpression(expression);
+ this.moveFailed = createFileLanguageExpression(expression);
}
public Expression getMoveFailed() {
@@ -232,7 +232,7 @@
*/
public void setMove(String fileLanguageExpression) {
String expression =
configureMoveOrPreMoveExpression(fileLanguageExpression);
- this.move = createFileLangugeExpression(expression);
+ this.move = createFileLanguageExpression(expression);
}
public Expression getPreMove() {
@@ -249,7 +249,7 @@
*/
public void setPreMove(String fileLanguageExpression) {
String expression =
configureMoveOrPreMoveExpression(fileLanguageExpression);
- this.preMove = createFileLangugeExpression(expression);
+ this.preMove = createFileLanguageExpression(expression);
}
public Expression getFileName() {
@@ -265,7 +265,7 @@
* {...@link org.apache.camel.language.simple.FileLanguage}
*/
public void setFileName(String fileLanguageExpression) {
- this.fileName = createFileLangugeExpression(fileLanguageExpression);
+ this.fileName = createFileLanguageExpression(fileLanguageExpression);
}
public Boolean isIdempotent() {
@@ -343,7 +343,7 @@
}
public void setTempFileName(String tempFileNameExpression) {
- this.tempFileName =
createFileLangugeExpression(tempFileNameExpression);
+ this.tempFileName =
createFileLanguageExpression(tempFileNameExpression);
}
public GenericFileConfiguration getConfiguration() {
@@ -535,8 +535,14 @@
return params;
}
- private Expression createFileLangugeExpression(String expression) {
- Language language = getCamelContext().resolveLanguage("file");
+ private Expression createFileLanguageExpression(String expression) {
+ Language language;
+ // only use file language if the name is complex (eg. using $)
+ if (expression.contains("$")) {
+ language = getCamelContext().resolveLanguage("file");
+ } else {
+ language = getCamelContext().resolveLanguage("constant");
+ }
return language.createExpression(expression);
}
}
Added:
camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileProducerFilenameConstantTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileProducerFilenameConstantTest.java?rev=902594&view=auto
==============================================================================
---
camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileProducerFilenameConstantTest.java
(added)
+++
camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileProducerFilenameConstantTest.java
Sun Jan 24 16:23:10 2010
@@ -0,0 +1,36 @@
+/**
+ * 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.file;
+
+import java.io.File;
+
+import org.apache.camel.ContextTestSupport;
+
+/**
+ * @version $Revision$
+ */
+public class FileProducerFilenameConstantTest extends ContextTestSupport {
+
+ public void testFileProducerFilenameConstant() throws Exception {
+ deleteDirectory("target/constant");
+
+ template.sendBody("file://target/constant?fileName=header.txt", "Hello
World");
+
+ File file = new File("./target/constant/header.txt").getAbsoluteFile();
+ assertTrue("File should exists " + file, file.exists());
+ }
+}
Propchange:
camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileProducerFilenameConstantTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileProducerFilenameConstantTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added:
camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FromFileMulticastToFilesTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FromFileMulticastToFilesTest.java?rev=902594&view=auto
==============================================================================
---
camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FromFileMulticastToFilesTest.java
(added)
+++
camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FromFileMulticastToFilesTest.java
Sun Jan 24 16:23:10 2010
@@ -0,0 +1,75 @@
+/**
+ * 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.file;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+
+/**
+ * @version $Revision$
+ */
+public class FromFileMulticastToFilesTest extends ContextTestSupport {
+
+ @Override
+ protected void setUp() throws Exception {
+ deleteDirectory("./target/multicast");
+ super.setUp();
+ }
+
+ public void testFromFileMulticastToFiles() throws Exception {
+ MockEndpoint header = getMockEndpoint("mock:header");
+ header.expectedBodiesReceived("HEADER:foo");
+ header.expectedFileExists("./target/multicast/out/header.txt");
+
+ MockEndpoint footer = getMockEndpoint("mock:footer");
+ footer.expectedBodiesReceived("FOOTER:foo");
+ footer.expectedFileExists("./target/multicast/out/footer.txt");
+
+ MockEndpoint end = getMockEndpoint("mock:end");
+ end.expectedMessageCount(1);
+ end.expectedFileExists("./target/multicast/.camel/foo.txt");
+
+ template.sendBodyAndHeader("file://target/multicast", "foo",
Exchange.FILE_NAME, "foo.txt");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("file://target/multicast")
+ .multicast()
+ .pipeline()
+ .transform(body().prepend("HEADER:"))
+
.to("file://target/multicast/out/?fileName=header.txt")
+ .to("mock:header")
+ .end()
+ .pipeline()
+ .transform(body().prepend("FOOTER:"))
+
.to("file://target/multicast/out/?fileName=footer.txt")
+ .to("mock:footer")
+ .end()
+ .end()
+ .to("mock:end");
+ }
+ };
+ }
+}
Propchange:
camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FromFileMulticastToFilesTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FromFileMulticastToFilesTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date