You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2010/09/10 11:32:29 UTC
svn commit: r995718 - in /camel/trunk/camel-core/src:
main/java/org/apache/camel/component/file/
test/java/org/apache/camel/component/file/
Author: ningjiang
Date: Fri Sep 10 09:32:29 2010
New Revision: 995718
URL: http://svn.apache.org/viewvc?rev=995718&view=rev
Log:
CAMEL-3112 added the charset option into the GenericFileEndpoint
Added:
camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumeCharsetTest.java (with props)
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java
camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileEndpoint.java
camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileProducer.java
camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConfigureTest.java
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java?rev=995718&r1=995717&r2=995718&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java Fri Sep 10 09:32:29 2010
@@ -102,6 +102,7 @@ public abstract class GenericFileConsume
LinkedList<Exchange> exchanges = new LinkedList<Exchange>();
for (GenericFile<T> file : files) {
Exchange exchange = endpoint.createExchange(file);
+ endpoint.configureExchange(exchange);
endpoint.configureMessage(file, exchange.getIn());
exchanges.add(exchange);
}
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=995718&r1=995717&r2=995718&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 Fri Sep 10 09:32:29 2010
@@ -70,6 +70,7 @@ public abstract class GenericFileEndpoin
protected boolean eagerDeleteTargetFile = true;
protected String include;
protected String exclude;
+ protected String charset;
protected Expression fileName;
protected Expression move;
protected Expression moveFailed;
@@ -278,6 +279,14 @@ public abstract class GenericFileEndpoin
public Boolean isIdempotent() {
return idempotent != null ? idempotent : false;
}
+
+ public String getCharset() {
+ return charset;
+ }
+
+ public void setCharset(String charset) {
+ this.charset = charset;
+ }
boolean isIdempotentSet() {
return idempotent != null;
@@ -503,6 +512,17 @@ public abstract class GenericFileEndpoin
message.setHeader(Exchange.FILE_NAME, name);
}
}
+
+ /**
+ * Set up the exchange properties with the options of the file endpoint
+ * @param exchange
+ */
+ public void configureExchange(Exchange exchange) {
+ // Now we just set the charset property here
+ if (getCharset() != null) {
+ exchange.setProperty(Exchange.CHARSET_NAME, getCharset());
+ }
+ }
/**
* Strategy to configure the move or premove option based on a String input.
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileProducer.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileProducer.java?rev=995718&r1=995717&r2=995718&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileProducer.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileProducer.java Fri Sep 10 09:32:29 2010
@@ -54,6 +54,7 @@ public class GenericFileProducer<T> exte
public void process(Exchange exchange) throws Exception {
Exchange fileExchange = endpoint.createExchange(exchange);
+ endpoint.configureExchange(fileExchange);
processExchange(fileExchange);
ExchangeHelper.copyResults(exchange, fileExchange);
}
Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConfigureTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConfigureTest.java?rev=995718&r1=995717&r2=995718&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConfigureTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConfigureTest.java Fri Sep 10 09:32:29 2010
@@ -50,6 +50,12 @@ public class FileConfigureTest extends C
assertFileEndpoint("file:/", File.separator, true);
assertFileEndpoint("file:///", File.separator, true);
}
+
+ public void testUriWithCharset() throws Exception {
+ FileEndpoint endpoint = resolveMandatoryEndpoint("file://target/foo/bar?charset=UTF-8", FileEndpoint.class);
+ assertNotNull("Could not find endpoint: file://target/foo/bar?charset=UTF-8", endpoint);
+ assertEquals("Get a wrong charset", "UTF-8", endpoint.getCharset());
+ }
public void testConsumerConfigurations() throws Exception {
FileConsumer consumer = createFileConsumer("file://target/foo/bar?recursive=true");
Added: camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumeCharsetTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumeCharsetTest.java?rev=995718&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumeCharsetTest.java (added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumeCharsetTest.java Fri Sep 10 09:32:29 2010
@@ -0,0 +1,59 @@
+/**
+ * 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;
+
+/**
+ * Unit test for consuming the same filename only.
+ */
+public class FileConsumeCharsetTest extends ContextTestSupport {
+
+ @Override
+ protected void setUp() throws Exception {
+ deleteDirectory("target/files");
+ super.setUp();
+ template.sendBodyAndHeader("file://target/files?charset=UTF-8", "Hello World \u4f60\u597d", Exchange.FILE_NAME, "report.txt");
+ }
+
+ public void testConsumeAndDelete() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedBodiesReceived("Hello World \u4f60\u597d");
+
+ assertMockEndpointsSatisfied();
+
+ // give time to delete files
+ Thread.sleep(200);
+
+ // file should not exists
+ assertFalse("File should been deleted", new File("target/files/report.txt").getAbsoluteFile().exists());
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ public void configure() throws Exception {
+ from("file://target/files/?fileName=report.txt&delete=true&charset=UTF-8").convertBodyTo(String.class).to("mock:result");
+ }
+ };
+ }
+}
Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumeCharsetTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumeCharsetTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date