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 2011/02/04 10:56:43 UTC
svn commit: r1067124 - in /camel/trunk/camel-core/src:
main/java/org/apache/camel/builder/xml/
main/java/org/apache/camel/component/file/
test/java/org/apache/camel/component/file/ test/resources/
Author: davsclaus
Date: Fri Feb 4 09:56:43 2011
New Revision: 1067124
URL: http://svn.apache.org/viewvc?rev=1067124&view=rev
Log:
CAMEL-3617: Fixed issue with file consumer using absolute starting directory.
Added:
camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileAbsolutePathIssueTest.java
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/DefaultTransformErrorHandler.java
camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileConsumer.java
camel/trunk/camel-core/src/test/resources/log4j.properties
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/DefaultTransformErrorHandler.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/DefaultTransformErrorHandler.java?rev=1067124&r1=1067123&r2=1067124&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/DefaultTransformErrorHandler.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/DefaultTransformErrorHandler.java Fri Feb 4 09:56:43 2011
@@ -19,12 +19,13 @@ package org.apache.camel.builder.xml;
import javax.xml.transform.ErrorListener;
import javax.xml.transform.TransformerException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.xml.sax.ErrorHandler;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
/**
* {@link ErrorHandler} and {@link ErrorListener} which will log warnings,
* and throws error and fatal as exception, which ensures those can be caught by Camel and dealt-with.
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileConsumer.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileConsumer.java?rev=1067124&r1=1067123&r2=1067124&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileConsumer.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileConsumer.java Fri Feb 4 09:56:43 2011
@@ -137,24 +137,21 @@ public class FileConsumer extends Generi
answer.setAbsolute(FileUtil.isAbsolute(file));
answer.setAbsoluteFilePath(file.getAbsolutePath());
answer.setLastModified(file.lastModified());
- if (answer.isAbsolute()) {
- // use absolute path as relative
- answer.setRelativeFilePath(file.getAbsolutePath());
+
+ // compute the file path as relative to the starting directory
+ File path;
+ String endpointNormalized = FileUtil.normalizePath(endpointPath);
+ if (file.getPath().startsWith(endpointNormalized)) {
+ // skip duplicate endpoint path
+ path = new File(ObjectHelper.after(file.getPath(), endpointNormalized + File.separator));
} else {
- File path;
- String endpointNormalized = FileUtil.normalizePath(endpointPath);
- if (file.getPath().startsWith(endpointNormalized)) {
- // skip duplicate endpoint path
- path = new File(ObjectHelper.after(file.getPath(), endpointNormalized + File.separator));
- } else {
- path = new File(file.getPath());
- }
+ path = new File(file.getPath());
+ }
- if (path.getParent() != null) {
- answer.setRelativeFilePath(path.getParent() + File.separator + file.getName());
- } else {
- answer.setRelativeFilePath(path.getName());
- }
+ if (path.getParent() != null) {
+ answer.setRelativeFilePath(path.getParent() + File.separator + file.getName());
+ } else {
+ answer.setRelativeFilePath(path.getName());
}
// the file name should be the relative path
Added: camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileAbsolutePathIssueTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileAbsolutePathIssueTest.java?rev=1067124&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileAbsolutePathIssueTest.java (added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileAbsolutePathIssueTest.java Fri Feb 4 09:56:43 2011
@@ -0,0 +1,66 @@
+/**
+ * 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;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+
+/**
+ * @version $Revision$
+ */
+public class FileAbsolutePathIssueTest extends ContextTestSupport {
+
+ private String uri;
+ private String start;
+ private String done;
+
+ @Override
+ protected void setUp() throws Exception {
+ deleteDirectory("target/issue");
+ deleteDirectory("target/done");
+
+ start = new File("target/issue").getAbsoluteFile().getAbsolutePath();
+ done = new File("target/done").getAbsoluteFile().getAbsolutePath();
+ uri = "file:" + start + "?move=" + done + "/${file:name}";
+
+ super.setUp();
+ }
+
+ public void testMoveAbsolute() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedMessageCount(1);
+ mock.expectedFileExists(done + "/hello.txt");
+
+ template.sendBodyAndHeader("file:" + start, "Hello World", Exchange.FILE_NAME, "hello.txt");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from(uri).to("mock:result");
+ }
+ };
+ }
+}
Modified: camel/trunk/camel-core/src/test/resources/log4j.properties
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/resources/log4j.properties?rev=1067124&r1=1067123&r2=1067124&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/resources/log4j.properties (original)
+++ camel/trunk/camel-core/src/test/resources/log4j.properties Fri Feb 4 09:56:43 2011
@@ -30,6 +30,7 @@ log4j.logger.org.apache.camel.impl.Defau
#log4j.logger.org.apache.camel.language.simple=TRACE
#log4j.logger.org.apache.camel.component=TRACE
#log4j.logger.org.apache.camel.component.seda=TRACE
+#log4j.logger.org.apache.camel.component.file=TRACE
#log4j.logger.org.apache.camel.impl.DefaultUnitOfWork=TRACE
#log4j.logger.org.apache.camel.component.mock=DEBUG
#log4j.logger.org.apache.camel.component.file=TRACE