I will try this hack (org/apache/camel/component/file/GenericFileProducer.java line 277):
  if (expression != null) {
    log.trace("Filename evaluated as expression: {}", expression);
exchange.getIn().setHeader("CamelFileConfiguredDirectory", endpoint.getConfiguration().getDirectory()); // <- hack
name = expression.evaluate(exchange, String.class);
  }


looks like the evaluation of the fileName option is done at a pretty early stage of the process, where output information is not yet available.

headers:
    CamelFileAbsolute=true
    CamelFileAbsolutePath=e:\temp\file-io\file-in\DESADV96A.EDI
    CamelFileLastModified=Thu Jun 09 23:41:04 CEST 2011
    CamelFileLength=1547
    CamelFileName=DESADV96A.EDI
    CamelFileNameOnly=DESADV96A.EDI
    CamelFileParent=e:\temp\file-io\file-in
    CamelFilePath=e:\temp\file-io\file-in\DESADV96A.EDI
    CamelFileRelativePath=DESADV96A.EDI
    breadcrumbId=ID-XXXXXXXXX-56639-1317208126721-0-2

call stack [camel 2.8.1]:
Daemon Thread [Camel (75-camel-3) thread #0 - file://e:/temp/file-io/file-in] (Suspended)
    FileNameGenerator.generateFileName(File, Exchange) line: 37
NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not available [native method]
    NativeMethodAccessorImpl.invoke(Object, Object[]) line: not available
DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: not available
    Method.invoke(Object, Object...) line: not available
    MethodInfo.invoke(Method, Object, Object[], Exchange) line: 329
    MethodInfo$1.proceed(AsyncCallback, AtomicBoolean) line: 231
    BeanProcessor.process(Exchange, AsyncCallback) line: 169
    AsyncProcessorHelper.process(AsyncProcessor, Exchange) line: 104
    BeanProcessor.process(Exchange) line: 74
    BeanExpression$InvokeProcessor.process(Exchange) line: 136
    BeanExpression.evaluate(Exchange) line: 92
    BeanExpression.evaluate(Exchange, Class<T>) line: 101
    ExpressionBuilder$56.evaluate(Exchange) line: 1287
ExpressionBuilder$56(ExpressionAdapter).evaluate(Exchange, Class<T>) line: 36
    GenericFileProducer<T>.createFileName(Exchange) line: 279
    GenericFileProducer<T>.process(Exchange) line: 65


The file producer appends a header with the actual name of the file produced.

The header has the key
Exchange.FILE_NAME_PRODUCED

On Tue, Sep 27, 2011 at 7:14 PM, Stefan Eder<[email protected]> wrote:
  Hi,

I have a similar problem with the generated output files.
Tried the bean way:
public String generateFileName(final File file)
and
public String generateFileName(final File file, final Exchange exchange)
and
public String generateFileName(final GenericFile<File> genericFile, final
Exchange exchange)

The Problem is that, either way, at the point where my bean is called, only
the in message of the exchange is initialized.
So my bean is called with the input file and I don't see how to obtain the
output file to check if the file already exists.

Of course I could make my bean aware about the output path with an
additional bean property, but this would not be a reliable solution.

Ideas?


Hi

Camel does not have any existing option for this.

You can use a java bean to compute the number yourself
http://camel.apache.org/file-language.html

You can just use the JDK File API to check if the file exists, if it
does, then increment the number, and try again.
Until you find a "free number".




On Mon, Sep 26, 2011 at 11:41 AM, nilsoni<[email protected]>    wrote:

Hi,
In File component URI, I have specified "moveFailed=..." option. Now
whenever there is any error, file is moved to error folder. I have a
requirement where files with same name are provided to input endpoint of
file component and if all of them are failing one by one due to any
reason,
they should not be overridden in /error folder. Instead, it should be
written in /error folder with some index appended to it. So for example,

I have provided abc.txt to File input endpoint 5 times, on error, there
should be 5 files in error folder with following name.
abc1.txt
abc2.txt
abc3.txt
abc4.txt
abc5.txt

Again, this should be done by camel and not by me by writing some index
number in header as i may not be knowing what was the last index used
(application may be shutdown in between multiple runs of flow mentioned above). Is there any uri option in camel which does this automatically?




--
View this message in context:
http://camel.465427.n5.nabble.com/Appending-index-number-in-file-name-written-in-error-folder-by-File-component-tp4840768p4840768.html
Sent from the Camel - Users mailing list archive at Nabble.com.




Reply via email to