[
https://issues.apache.org/jira/browse/CAMEL-5582?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Claus Ibsen resolved CAMEL-5582.
--------------------------------
Resolution: Fixed
Fix Version/s: 2.10.2
2.11.0
2.9.4
Thanks for reporting.
The workaround is to convert the payload to a String before the marshal
from -> convertTo(String) -> marshal
> PGP data format doesn't close file input streams
> ------------------------------------------------
>
> Key: CAMEL-5582
> URL: https://issues.apache.org/jira/browse/CAMEL-5582
> Project: Camel
> Issue Type: Bug
> Components: camel-crypto
> Affects Versions: 2.10.1
> Environment: Windows XP
> Reporter: Daniel Gredler
> Assignee: Claus Ibsen
> Fix For: 2.9.4, 2.11.0, 2.10.2
>
>
> The following route doesn't work on Windows:
> {code}from("file:foo").marshal().pgp(...).to("ftp:blah"){code}
> The reason is that PGPDataFormat.marshal() and PGPDataFormat.unmarshal() both
> use IOUtils.toByteArray() to read the incoming stream into a byte array, but
> neither of these two methods closes the streams after they have been read
> from. My understanding is that not closing these streams prevents Camel from
> subsequently renaming the file once the route has completed. I've attached a
> sample stack trace at the bottom.
> The following seems to fix the issue for me:
> Replacing the following code in
> {{org.apache.camel.converter.crypto.PGPDataFormat.marshal(...)}}:
> {code}InputStream plaintextStream =
> ExchangeHelper.convertToMandatoryType(exchange, InputStream.class, graph);
> byte[] compressedData =
> PGPDataFormatUtil.compress(IOUtils.toByteArray(plaintextStream),
> PGPLiteralData.CONSOLE, CompressionAlgorithmTags.ZIP);{code}
> With this code:
> {code}byte[] plaintextData;
> InputStream plaintextStream = null;
> try {
> plaintextStream = ExchangeHelper.convertToMandatoryType(exchange,
> InputStream.class, graph);
> plaintextData = IOUtils.toByteArray(plaintextStream);
> } finally {
> IOUtils.closeQuietly(plaintextStream);
> }
> byte[] compressedData = PGPDataFormatUtil.compress(plaintextData,
> PGPLiteralData.CONSOLE, CompressionAlgorithmTags.ZIP);{code}
> And replacing the following code in
> {{org.apache.camel.converter.crypto.PGPDataFormat.unmarshal(...)}}:
> {code}InputStream in = new
> ByteArrayInputStream(IOUtils.toByteArray(encryptedStream));
> in = PGPUtil.getDecoderStream(in);{code}
> With this code:
> {code}InputStream in;
> try {
> byte[] encryptedData = IOUtils.toByteArray(encryptedStream);
> InputStream byteStream = new ByteArrayInputStream(encryptedData);
> in = PGPUtil.getDecoderStream(byteStream);
> } finally {
> IOUtils.closeQuietly(encryptedStream);
> }{code}
> And here's the stack trace mentioned above:
> {code}org.apache.camel.component.file.GenericFileOperationFailedException:
> Error renaming file from C:\opt\connect\just\a\test\lax\blah.txt to
> C:\opt\connect\just\a\test\lax\.sent\blah.txt
> at
> org.apache.camel.component.file.FileOperations.renameFile(FileOperations.java:72)
> at
> org.apache.camel.component.file.strategy.GenericFileProcessStrategySupport.renameFile(GenericFileProcessStrategySupport.java:107)
> at
> org.apache.camel.component.file.strategy.GenericFileRenameProcessStrategy.commit(GenericFileRenameProcessStrategy.java:86)
> at
> org.apache.camel.component.file.GenericFileOnCompletion.processStrategyCommit(GenericFileOnCompletion.java:132)
> at
> org.apache.camel.component.file.GenericFileOnCompletion.onCompletion(GenericFileOnCompletion.java:82)
> at
> org.apache.camel.component.file.GenericFileOnCompletion.onComplete(GenericFileOnCompletion.java:53)
> at
> org.apache.camel.util.UnitOfWorkHelper.doneSynchronizations(UnitOfWorkHelper.java:55)
> at
> org.apache.camel.impl.DefaultUnitOfWork.done(DefaultUnitOfWork.java:226)
> at
> org.apache.camel.processor.UnitOfWorkProcessor.doneUow(UnitOfWorkProcessor.java:199)
> at
> org.apache.camel.processor.UnitOfWorkProcessor.access$000(UnitOfWorkProcessor.java:37)
> at
> org.apache.camel.processor.UnitOfWorkProcessor$1.done(UnitOfWorkProcessor.java:157)
> at
> org.apache.camel.processor.RouteContextProcessor$1.done(RouteContextProcessor.java:56)
> at org.apache.camel.processor.Pipeline.process(Pipeline.java:106)
> at
> org.apache.camel.processor.RouteContextProcessor.processNext(RouteContextProcessor.java:45)
> at
> org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
> at
> org.apache.camel.processor.UnitOfWorkProcessor.processAsync(UnitOfWorkProcessor.java:150)
> at
> org.apache.camel.processor.UnitOfWorkProcessor.process(UnitOfWorkProcessor.java:117)
> at
> org.apache.camel.processor.RouteInflightRepositoryProcessor.processNext(RouteInflightRepositoryProcessor.java:48)
> at
> org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
> at
> org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
> at
> org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:99)
> at
> org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
> at
> org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:73)
> at
> org.apache.camel.component.file.GenericFileConsumer.processExchange(GenericFileConsumer.java:336)
> at
> org.apache.camel.component.file.GenericFileConsumer.processBatch(GenericFileConsumer.java:189)
> at
> org.apache.camel.component.file.GenericFileConsumer.poll(GenericFileConsumer.java:155)
> at
> org.apache.camel.impl.ScheduledPollConsumer.doRun(ScheduledPollConsumer.java:139)
> at
> org.apache.camel.impl.ScheduledPollConsumer.run(ScheduledPollConsumer.java:91)
> at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
> at
> java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:317)
> at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:150)
> at
> java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(ScheduledThreadPoolExecutor.java:98)
> at
> java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(ScheduledThreadPoolExecutor.java:181)
> at
> java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:205)
> at
> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
> at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
> at java.lang.Thread.run(Thread.java:619)
> Caused by: java.io.IOException: Renaming file from:
> C:\opt\connect\just\a\test\lax\blah.txt to:
> C:\opt\connect\just\a\test\lax\.sent\blah.txt failed due cannot delete from
> file: C:\opt\connect\just\a\test\lax\blah.txt after copy succeeded
> at org.apache.camel.util.FileUtil.renameFile(FileUtil.java:362)
> at
> org.apache.camel.component.file.FileOperations.renameFile(FileOperations.java:70)
> ... 36 more{code}
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira