Return-Path: X-Original-To: apmail-camel-commits-archive@www.apache.org Delivered-To: apmail-camel-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id AAE0BD1A5 for ; Fri, 10 Aug 2012 04:46:45 +0000 (UTC) Received: (qmail 24568 invoked by uid 500); 10 Aug 2012 04:46:45 -0000 Delivered-To: apmail-camel-commits-archive@camel.apache.org Received: (qmail 24430 invoked by uid 500); 10 Aug 2012 04:46:42 -0000 Mailing-List: contact commits-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list commits@camel.apache.org Received: (qmail 24402 invoked by uid 99); 10 Aug 2012 04:46:41 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 10 Aug 2012 04:46:41 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 10 Aug 2012 04:46:40 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id ACEEE2388860; Fri, 10 Aug 2012 04:45:56 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1371570 - in /camel/trunk/camel-core/src: main/java/org/apache/camel/component/file/FileComponent.java main/java/org/apache/camel/component/file/FileEndpoint.java test/java/org/apache/camel/component/file/FileRouteOnDosWithNoVolTest.java Date: Fri, 10 Aug 2012 04:45:56 -0000 To: commits@camel.apache.org From: ningjiang@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120810044556.ACEEE2388860@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: ningjiang Date: Fri Aug 10 04:45:56 2012 New Revision: 1371570 URL: http://svn.apache.org/viewvc?rev=1371570&view=rev Log: CAMEL-5495 fix the file endpoint issue on Windows Added: camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileRouteOnDosWithNoVolTest.java Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileComponent.java camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileEndpoint.java Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileComponent.java URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileComponent.java?rev=1371570&r1=1371569&r2=1371570&view=diff ============================================================================== --- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileComponent.java (original) +++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileComponent.java Fri Aug 10 04:45:56 2012 @@ -19,6 +19,7 @@ package org.apache.camel.component.file; import java.io.File; import java.util.Map; +import org.apache.camel.util.FileUtil; import org.apache.camel.util.StringHelper; /** @@ -50,7 +51,7 @@ public class FileComponent extends Gener result.setFile(file); GenericFileConfiguration config = new GenericFileConfiguration(); - config.setDirectory(file.getPath()); + config.setDirectory(FileUtil.isAbsolute(file) ? file.getAbsolutePath() : file.getPath()); result.setConfiguration(config); return result; Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileEndpoint.java URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileEndpoint.java?rev=1371570&r1=1371569&r2=1371570&view=diff ============================================================================== --- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileEndpoint.java (original) +++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileEndpoint.java Fri Aug 10 04:45:56 2012 @@ -127,7 +127,7 @@ public class FileEndpoint extends Generi public void setFile(File file) { this.file = file; // update configuration as well - getConfiguration().setDirectory(file.getPath()); + getConfiguration().setDirectory(FileUtil.isAbsolute(file) ? file.getAbsolutePath() : file.getPath()); } @Override Added: camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileRouteOnDosWithNoVolTest.java URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileRouteOnDosWithNoVolTest.java?rev=1371570&view=auto ============================================================================== --- camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileRouteOnDosWithNoVolTest.java (added) +++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileRouteOnDosWithNoVolTest.java Fri Aug 10 04:45:56 2012 @@ -0,0 +1,93 @@ +/** + * 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; +import org.apache.camel.util.FileUtil; +import org.junit.Test; + +/** + * Verify the standard file url paths on windows that are interpreted as the window's + * url paths without the volume name will work on windows system. + */ +public class FileRouteOnDosWithNoVolTest extends ContextTestSupport { + private String path; + + @Override + public void setUp() throws Exception { + File dir = new File("target/reports/dosnovol"); + deleteDirectory(dir); + path = dir.getAbsolutePath(); + if (FileUtil.isWindows()) { + int dp = path.indexOf(":\\"); + if (dp > 0) { + path = path.substring(dp + 1).replace('\\', '/'); + } + } + + super.setUp(); + } + + @Test + public void testRouteFileToFile() throws Exception { + MockEndpoint mock = getMockEndpoint("mock:result"); + mock.expectedMessageCount(1); + mock.expectedFileExists(path + "/route/out/hello.txt"); + + template.sendBodyAndHeader("file://" + path + "/route/poller", "Hello World", Exchange.FILE_NAME, "hello.txt"); + + assertMockEndpointsSatisfied(); + } + + @Test + public void testRouteFromFileOnly() throws Exception { + MockEndpoint mock = getMockEndpoint("mock:result"); + mock.expectedMessageCount(1); + + template.sendBodyAndHeader("file://" + path + "/from/poller", "Hello World", Exchange.FILE_NAME, "hello.txt"); + + assertMockEndpointsSatisfied(); + } + + @Test + public void testRouteToFileOnly() throws Exception { + MockEndpoint mock = getMockEndpoint("mock:result"); + mock.expectedMessageCount(1); + mock.expectedFileExists(path + "/to/out/hello.txt"); + + template.sendBodyAndHeader("direct:report", "Hello World", Exchange.FILE_NAME, "hello.txt"); + + assertMockEndpointsSatisfied(); + } + + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + public void configure() throws Exception { + from("file://" + path + "/route/poller").to("file://" + path + "/route/out", "mock:result"); + from("file://" + path + "/from/poller").to("mock:result"); + from("direct:report").to("file://" + path + "/to/out", "mock:result"); + } + }; + } + +}