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 2010/05/21 08:16:24 UTC
svn commit: r946891 - in /camel/trunk/camel-core/src:
main/java/org/apache/camel/component/file/
main/java/org/apache/camel/component/file/strategy/
main/java/org/apache/camel/converter/ main/java/org/apache/camel/impl/
main/java/org/apache/camel/impl/...
Author: davsclaus
Date: Fri May 21 06:16:23 2010
New Revision: 946891
URL: http://svn.apache.org/viewvc?rev=946891&view=rev
Log:
CAMEL-2741: Closing streams for zip/gzip data formats. Added closeable on IOHelper where it belongs.
Added:
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/GzipDataFormatFileDeleteTest.java (with props)
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/GzipDataFormatFileUnmarshalDeleteTest.java (with props)
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/ZipDataFormatFileDeleteTest.java (with props)
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/ZipDataFormatFileUnmarshalDeleteTest.java (with props)
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileOperations.java
camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileProducer.java
camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileLockExclusiveReadLockStrategy.java
camel/trunk/camel-core/src/main/java/org/apache/camel/converter/IOConverter.java
camel/trunk/camel-core/src/main/java/org/apache/camel/converter/NIOConverter.java
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultFactoryFinder.java
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultPackageScanClassResolver.java
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/GzipDataFormat.java
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ZipDataFormat.java
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/AnnotationTypeConverterLoader.java
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/idempotent/FileIdempotentRepository.java
camel/trunk/camel-core/src/main/java/org/apache/camel/util/IOHelper.java
camel/trunk/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileOperations.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileOperations.java?rev=946891&r1=946890&r2=946891&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileOperations.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileOperations.java Fri May 21 06:16:23 2010
@@ -31,6 +31,7 @@ import org.apache.camel.Exchange;
import org.apache.camel.InvalidPayloadException;
import org.apache.camel.util.ExchangeHelper;
import org.apache.camel.util.FileUtil;
+import org.apache.camel.util.IOHelper;
import org.apache.camel.util.ObjectHelper;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -255,8 +256,8 @@ public class FileOperations implements G
position += in.transferTo(position, endpoint.getBufferSize(), out);
}
} finally {
- ObjectHelper.close(in, source.getName(), LOG);
- ObjectHelper.close(out, source.getName(), LOG);
+ IOHelper.close(in, source.getName(), LOG);
+ IOHelper.close(out, source.getName(), LOG);
}
}
@@ -280,8 +281,8 @@ public class FileOperations implements G
byteBuffer.clear();
}
} finally {
- ObjectHelper.close(in, target.getName(), LOG);
- ObjectHelper.close(out, target.getName(), LOG);
+ IOHelper.close(in, target.getName(), LOG);
+ IOHelper.close(out, target.getName(), LOG);
}
}
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=946891&r1=946890&r2=946891&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 May 21 06:16:23 2010
@@ -25,6 +25,7 @@ import org.apache.camel.impl.DefaultProd
import org.apache.camel.spi.Language;
import org.apache.camel.util.ExchangeHelper;
import org.apache.camel.util.FileUtil;
+import org.apache.camel.util.IOHelper;
import org.apache.camel.util.ObjectHelper;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -214,7 +215,7 @@ public class GenericFileProducer<T> exte
}
} finally {
- ObjectHelper.close(payload, "Closing payload", log);
+ IOHelper.close(payload, "Closing payload", log);
}
}
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileLockExclusiveReadLockStrategy.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileLockExclusiveReadLockStrategy.java?rev=946891&r1=946890&r2=946891&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileLockExclusiveReadLockStrategy.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileLockExclusiveReadLockStrategy.java Fri May 21 06:16:23 2010
@@ -29,7 +29,7 @@ import org.apache.camel.component.file.G
import org.apache.camel.component.file.GenericFileExclusiveReadLockStrategy;
import org.apache.camel.component.file.GenericFileOperations;
import org.apache.camel.util.ExchangeHelper;
-import org.apache.camel.util.ObjectHelper;
+import org.apache.camel.util.IOHelper;
import org.apache.camel.util.StopWatch;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -126,7 +126,7 @@ public class FileLockExclusiveReadLockSt
lock.release();
} finally {
// must close channel first
- ObjectHelper.close(channel, "while acquiring exclusive read lock for file: " + lockFileName, LOG);
+ IOHelper.close(channel, "while acquiring exclusive read lock for file: " + lockFileName, LOG);
}
}
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/converter/IOConverter.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/IOConverter.java?rev=946891&r1=946890&r2=946891&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/converter/IOConverter.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/converter/IOConverter.java Fri May 21 06:16:23 2010
@@ -40,7 +40,6 @@ import java.io.StringReader;
import java.io.UnsupportedEncodingException;
import java.io.Writer;
import java.net.URL;
-import java.nio.charset.Charset;
import org.apache.camel.Converter;
import org.apache.camel.Exchange;
@@ -177,7 +176,7 @@ public final class IOConverter {
try {
return toBytes(is);
} finally {
- ObjectHelper.close(is, "file", LOG);
+ IOHelper.close(is, "file", LOG);
}
}
@@ -206,7 +205,7 @@ public final class IOConverter {
try {
return toString(is, exchange);
} finally {
- ObjectHelper.close(is, "url", LOG);
+ IOHelper.close(is, "url", LOG);
}
}
@@ -237,7 +236,7 @@ public final class IOConverter {
}
}
} finally {
- ObjectHelper.close(reader, "reader", LOG);
+ IOHelper.close(reader, "reader", LOG);
}
return sb.toString();
@@ -303,7 +302,7 @@ public final class IOConverter {
IOHelper.copy(stream, bos);
return bos.toByteArray();
} finally {
- ObjectHelper.close(bos, "stream", LOG);
+ IOHelper.close(bos, "stream", LOG);
}
}
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/converter/NIOConverter.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/NIOConverter.java?rev=946891&r1=946890&r2=946891&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/converter/NIOConverter.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/converter/NIOConverter.java Fri May 21 06:16:23 2010
@@ -26,7 +26,7 @@ import java.nio.ByteBuffer;
import org.apache.camel.Converter;
import org.apache.camel.Exchange;
-import org.apache.camel.util.ObjectHelper;
+import org.apache.camel.util.IOHelper;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -76,7 +76,7 @@ public final class NIOConverter {
}
return ByteBuffer.wrap(buf);
} finally {
- ObjectHelper.close(in, "Failed to close file stream: " + file.getPath(), LOG);
+ IOHelper.close(in, "Failed to close file stream: " + file.getPath(), LOG);
}
}
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultFactoryFinder.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultFactoryFinder.java?rev=946891&r1=946890&r2=946891&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultFactoryFinder.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultFactoryFinder.java Fri May 21 06:16:23 2010
@@ -30,7 +30,7 @@ import org.apache.camel.spi.ClassResolve
import org.apache.camel.spi.FactoryFinder;
import org.apache.camel.spi.Injector;
import org.apache.camel.util.CastUtils;
-import org.apache.camel.util.ObjectHelper;
+import org.apache.camel.util.IOHelper;
/**
* Default factory finder.
@@ -143,8 +143,8 @@ public class DefaultFactoryFinder implem
properties.load(reader);
return properties;
} finally {
- ObjectHelper.close(reader, key, null);
- ObjectHelper.close(in, key, null);
+ IOHelper.close(reader, key, null);
+ IOHelper.close(in, key, null);
}
}
}
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultPackageScanClassResolver.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultPackageScanClassResolver.java?rev=946891&r1=946890&r2=946891&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultPackageScanClassResolver.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultPackageScanClassResolver.java Fri May 21 06:16:23 2010
@@ -41,7 +41,7 @@ import org.apache.camel.impl.scan.Assign
import org.apache.camel.impl.scan.CompositePackageScanFilter;
import org.apache.camel.spi.PackageScanClassResolver;
import org.apache.camel.spi.PackageScanFilter;
-import org.apache.camel.util.ObjectHelper;
+import org.apache.camel.util.IOHelper;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -386,7 +386,7 @@ public class DefaultPackageScanClassReso
log.warn("Cannot search jar file '" + urlPath + "' for classes matching criteria: " + test
+ " due to an IOException: " + ioe.getMessage(), ioe);
} finally {
- ObjectHelper.close(jarStream, urlPath, log);
+ IOHelper.close(jarStream, urlPath, log);
}
}
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/GzipDataFormat.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/GzipDataFormat.java?rev=946891&r1=946890&r2=946891&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/GzipDataFormat.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/GzipDataFormat.java Fri May 21 06:16:23 2010
@@ -36,9 +36,9 @@ public class GzipDataFormat implements D
try {
IOHelper.copy(is, zipOutput);
} finally {
- zipOutput.close();
+ IOHelper.close(is);
+ IOHelper.close(zipOutput);
}
-
}
public Object unmarshal(Exchange exchange, InputStream stream) throws Exception {
@@ -47,8 +47,12 @@ public class GzipDataFormat implements D
// Create an expandable byte array to hold the inflated data
ByteArrayOutputStream bos = new ByteArrayOutputStream();
- IOHelper.copy(unzipInput, bos);
- return bos.toByteArray();
+ try {
+ IOHelper.copy(unzipInput, bos);
+ return bos.toByteArray();
+ } finally {
+ IOHelper.close(unzipInput);
+ }
}
}
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ZipDataFormat.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ZipDataFormat.java?rev=946891&r1=946890&r2=946891&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ZipDataFormat.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ZipDataFormat.java Fri May 21 06:16:23 2010
@@ -47,7 +47,8 @@ public class ZipDataFormat implements Da
try {
IOHelper.copy(is, zipOutput);
} finally {
- zipOutput.close();
+ IOHelper.close(is);
+ IOHelper.close(zipOutput);
}
}
@@ -61,8 +62,7 @@ public class ZipDataFormat implements Da
IOHelper.copy(unzipInput, bos);
return bos.toByteArray();
} finally {
- unzipInput.close();
- bos.close();
+ IOHelper.close(unzipInput);
}
}
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/AnnotationTypeConverterLoader.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/AnnotationTypeConverterLoader.java?rev=946891&r1=946890&r2=946891&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/AnnotationTypeConverterLoader.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/AnnotationTypeConverterLoader.java Fri May 21 06:16:23 2010
@@ -37,6 +37,7 @@ import org.apache.camel.TypeConverter;
import org.apache.camel.spi.PackageScanClassResolver;
import org.apache.camel.spi.TypeConverterRegistry;
import org.apache.camel.util.CastUtils;
+import org.apache.camel.util.IOHelper;
import org.apache.camel.util.ObjectHelper;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -117,7 +118,7 @@ public class AnnotationTypeConverterLoad
tokenize(packages, line);
}
} finally {
- ObjectHelper.close(reader, null, LOG);
+ IOHelper.close(reader, null, LOG);
}
}
}
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/processor/idempotent/FileIdempotentRepository.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/idempotent/FileIdempotentRepository.java?rev=946891&r1=946890&r2=946891&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/processor/idempotent/FileIdempotentRepository.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/processor/idempotent/FileIdempotentRepository.java Fri May 21 06:16:23 2010
@@ -24,6 +24,7 @@ import java.util.Scanner;
import java.util.concurrent.atomic.AtomicBoolean;
import org.apache.camel.spi.IdempotentRepository;
+import org.apache.camel.util.IOHelper;
import org.apache.camel.util.LRUCache;
import org.apache.camel.util.ObjectHelper;
import org.apache.commons.logging.Log;
@@ -218,7 +219,7 @@ public class FileIdempotentRepository im
} catch (IOException e) {
throw ObjectHelper.wrapRuntimeCamelException(e);
} finally {
- ObjectHelper.close(fos, "Appending to file idempotent repository", LOG);
+ IOHelper.close(fos, "Appending to file idempotent repository", LOG);
}
}
@@ -240,7 +241,7 @@ public class FileIdempotentRepository im
} catch (IOException e) {
throw ObjectHelper.wrapRuntimeCamelException(e);
} finally {
- ObjectHelper.close(fos, "Trunking file idempotent repository", LOG);
+ IOHelper.close(fos, "Trunking file idempotent repository", LOG);
}
}
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/util/IOHelper.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/util/IOHelper.java?rev=946891&r1=946890&r2=946891&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/util/IOHelper.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/util/IOHelper.java Fri May 21 06:16:23 2010
@@ -16,12 +16,16 @@
*/
package org.apache.camel.util;
+import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
/**
* IO helper class.
*
@@ -29,6 +33,7 @@ import java.nio.charset.Charset;
*/
public final class IOHelper {
+ private static final transient Log LOG = LogFactory.getLog(IOHelper.class);
private static final int DEFAULT_BUFFER_SIZE = 1024 * 4;
private static final Charset UTF8_CHARSET = Charset.forName("UTF-8");
@@ -104,11 +109,55 @@ public final class IOHelper {
public static void copyAndCloseInput(InputStream input, OutputStream output) throws IOException {
copy(input, output);
- input.close();
+ close(input, null, LOG);
}
public static void copyAndCloseInput(InputStream input, OutputStream output, int bufferSize) throws IOException {
copy(input, output, bufferSize);
- input.close();
+ close(input, null, LOG);
+ }
+
+ /**
+ * Closes the given resource if it is available, logging any closing
+ * exceptions to the given log
+ *
+ * @param closeable the object to close
+ * @param name the name of the resource
+ * @param log the log to use when reporting closure warnings
+ */
+ public static void close(Closeable closeable, String name, Log log) {
+ if (closeable != null) {
+ try {
+ closeable.close();
+ } catch (IOException e) {
+ if (log != null) {
+ if (name != null) {
+ log.warn("Cannot close: " + name + ". Reason: " + e.getMessage(), e);
+ } else {
+ log.warn("Cannot close. Reason: " + e.getMessage(), e);
+ }
+ }
+ }
+ }
}
+
+ /**
+ * Closes the given resource if it is available.
+ *
+ * @param closeable the object to close
+ * @param name the name of the resource
+ */
+ public static void close(Closeable closeable, String name) {
+ close(closeable, name, LOG);
+ }
+
+ /**
+ * Closes the given resource if it is available.
+ *
+ * @param closeable the object to close
+ */
+ public static void close(Closeable closeable) {
+ close(closeable, null, LOG);
+ }
+
}
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java?rev=946891&r1=946890&r2=946891&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java Fri May 21 06:16:23 2010
@@ -581,9 +581,8 @@ public final class ObjectHelper {
/**
* A helper method to access a camel context properties with a prefix
*
- * @param name the name of the system property required
- * @param defaultValue the default value to use if the property is not
- * available or a security exception prevents access
+ * @param prefix the prefix
+ * @param camelContext the camel context
* @return the properties which holds the camel context properties with the prefix,
* and the key omit the prefix part
*/
@@ -993,19 +992,14 @@ public final class ObjectHelper {
* @param closeable the object to close
* @param name the name of the resource
* @param log the log to use when reporting closure warnings
+ * @deprecated use {@link org.apache.camel.util.IOHelper#close(java.io.Closeable, String, org.apache.commons.logging.Log)}
*/
+ @Deprecated
public static void close(Closeable closeable, String name, Log log) {
- if (closeable != null) {
- try {
- closeable.close();
- } catch (IOException e) {
- if (log != null) {
- log.warn("Cannot close: " + name + ". Reason: " + e, e);
- }
- }
- }
+ IOHelper.close(closeable, name, log);
}
+
/**
* Converts the given value to the required type or throw a meaningful exception
*/
Added: camel/trunk/camel-core/src/test/java/org/apache/camel/impl/GzipDataFormatFileDeleteTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/impl/GzipDataFormatFileDeleteTest.java?rev=946891&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/impl/GzipDataFormatFileDeleteTest.java (added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/impl/GzipDataFormatFileDeleteTest.java Fri May 21 06:16:23 2010
@@ -0,0 +1,65 @@
+/**
+ * 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.impl;
+
+import java.io.File;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ * @version $Revision$
+ */
+public class GzipDataFormatFileDeleteTest extends ContextTestSupport {
+
+ @Override
+ protected void setUp() throws Exception {
+ deleteDirectory("target/gzip");
+ super.setUp();
+ }
+
+ public void testGzipFileDelete() throws Exception {
+ getMockEndpoint("mock:result").expectedMessageCount(1);
+
+ template.sendBodyAndHeader("file:target/gzip", "Hello World", Exchange.FILE_NAME, "hello.txt");
+
+ assertMockEndpointsSatisfied();
+
+ //give a bit time
+ Thread.sleep(1000);
+
+ File in = new File("target/gzip/hello.txt").getAbsoluteFile();
+ assertFalse("Should have been deleted " + in, in.exists());
+
+ File out = new File("target/gzip/out/hello.txt.gz").getAbsoluteFile();
+ assertTrue("Should have been created " + out, out.exists());
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("file:target/gzip?delete=true")
+ .marshal().gzip()
+ .to("file:target/gzip/out?fileName=${file:name}.gz")
+ .to("mock:result");
+ }
+ };
+ }
+}
Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/impl/GzipDataFormatFileDeleteTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/impl/GzipDataFormatFileDeleteTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/camel-core/src/test/java/org/apache/camel/impl/GzipDataFormatFileUnmarshalDeleteTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/impl/GzipDataFormatFileUnmarshalDeleteTest.java?rev=946891&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/impl/GzipDataFormatFileUnmarshalDeleteTest.java (added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/impl/GzipDataFormatFileUnmarshalDeleteTest.java Fri May 21 06:16:23 2010
@@ -0,0 +1,68 @@
+/**
+ * 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.impl;
+
+import java.io.File;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ * @version $Revision$
+ */
+public class GzipDataFormatFileUnmarshalDeleteTest extends ContextTestSupport {
+
+ @Override
+ protected void setUp() throws Exception {
+ deleteDirectory("target/gzip");
+ super.setUp();
+ }
+
+ public void testGzipFileUnmarshalDelete() throws Exception {
+ getMockEndpoint("mock:result").expectedBodiesReceived("Hello World");
+
+ template.sendBodyAndHeader("file:target/gzip", "Hello World", Exchange.FILE_NAME, "hello.txt");
+
+ assertMockEndpointsSatisfied();
+
+ //give a bit time
+ Thread.sleep(1000);
+
+ File in = new File("target/gzip/hello.txt").getAbsoluteFile();
+ assertFalse("Should have been deleted " + in, in.exists());
+
+ File out = new File("target/gzip/out/hello.txt.gz").getAbsoluteFile();
+ assertFalse("Should have been deleted " + out, out.exists());
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("file:target/gzip?delete=true")
+ .marshal().gzip()
+ .to("file:target/gzip/out?fileName=${file:name}.gz");
+
+ from("file:target/gzip/out?delete=true")
+ .unmarshal().gzip()
+ .to("mock:result");
+ }
+ };
+ }
+}
\ No newline at end of file
Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/impl/GzipDataFormatFileUnmarshalDeleteTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/impl/GzipDataFormatFileUnmarshalDeleteTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/camel-core/src/test/java/org/apache/camel/impl/ZipDataFormatFileDeleteTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/impl/ZipDataFormatFileDeleteTest.java?rev=946891&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/impl/ZipDataFormatFileDeleteTest.java (added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/impl/ZipDataFormatFileDeleteTest.java Fri May 21 06:16:23 2010
@@ -0,0 +1,65 @@
+/**
+ * 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.impl;
+
+import java.io.File;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ * @version $Revision$
+ */
+public class ZipDataFormatFileDeleteTest extends ContextTestSupport {
+
+ @Override
+ protected void setUp() throws Exception {
+ deleteDirectory("target/zip");
+ super.setUp();
+ }
+
+ public void testZipFileDelete() throws Exception {
+ getMockEndpoint("mock:result").expectedMessageCount(1);
+
+ template.sendBodyAndHeader("file:target/zip", "Hello World", Exchange.FILE_NAME, "hello.txt");
+
+ assertMockEndpointsSatisfied();
+
+ //give a bit time
+ Thread.sleep(1000);
+
+ File in = new File("target/zip/hello.txt").getAbsoluteFile();
+ assertFalse("Should have been deleted " + in, in.exists());
+
+ File out = new File("target/zip/out/hello.txt.zip").getAbsoluteFile();
+ assertTrue("Should have been created " + out, out.exists());
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("file:target/zip?delete=true")
+ .marshal().zip()
+ .to("file:target/zip/out?fileName=${file:name}.zip")
+ .to("mock:result");
+ }
+ };
+ }
+}
\ No newline at end of file
Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/impl/ZipDataFormatFileDeleteTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/impl/ZipDataFormatFileDeleteTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/camel-core/src/test/java/org/apache/camel/impl/ZipDataFormatFileUnmarshalDeleteTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/impl/ZipDataFormatFileUnmarshalDeleteTest.java?rev=946891&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/impl/ZipDataFormatFileUnmarshalDeleteTest.java (added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/impl/ZipDataFormatFileUnmarshalDeleteTest.java Fri May 21 06:16:23 2010
@@ -0,0 +1,68 @@
+/**
+ * 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.impl;
+
+import java.io.File;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ * @version $Revision$
+ */
+public class ZipDataFormatFileUnmarshalDeleteTest extends ContextTestSupport {
+
+ @Override
+ protected void setUp() throws Exception {
+ deleteDirectory("target/zip");
+ super.setUp();
+ }
+
+ public void testZipFileUnmarshalDelete() throws Exception {
+ getMockEndpoint("mock:result").expectedBodiesReceived("Hello World");
+
+ template.sendBodyAndHeader("file:target/zip", "Hello World", Exchange.FILE_NAME, "hello.txt");
+
+ assertMockEndpointsSatisfied();
+
+ //give a bit time
+ Thread.sleep(1000);
+
+ File in = new File("target/zip/hello.txt").getAbsoluteFile();
+ assertFalse("Should have been deleted " + in, in.exists());
+
+ File out = new File("target/zip/out/hello.txt.zip").getAbsoluteFile();
+ assertFalse("Should have been deleted " + out, out.exists());
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("file:target/zip?delete=true")
+ .marshal().zip()
+ .to("file:target/zip/out?fileName=${file:name}.zip");
+
+ from("file:target/zip/out?delete=true")
+ .unmarshal().zip()
+ .to("mock:result");
+ }
+ };
+ }
+}
\ No newline at end of file
Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/impl/ZipDataFormatFileUnmarshalDeleteTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/impl/ZipDataFormatFileUnmarshalDeleteTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date