It's hardly possible to use all expression of the Simple language to create 
file names in the file component
------------------------------------------------------------------------------------------------------------

                 Key: CAMEL-4370
                 URL: https://issues.apache.org/jira/browse/CAMEL-4370
             Project: Camel
          Issue Type: Bug
          Components: camel-core
    Affects Versions: 2.7.1
            Reporter: Sergey Zhemzhitsky


Sometimes it can be necessary to use custom headers to create a file name.

For example, I declare my file endpoint in the following manner:

{code}
<route id="fileReader">
    <from 
uri="file://rootFolder?move=.backup&amp;moveFailed=.error/${header.CustomHeader}"
 />
    <to uri="file://out"/>
</route>
{code}

The header "CustomHeader" cannot be read because of the following snippets of 
code in the org.apache.camel.component.file.GenericFile

{code}
/**
 * Bind this GenericFile to an Exchange
 */
public void bindToExchange(Exchange exchange) {
    exchange.setProperty(FileComponent.FILE_EXCHANGE_FILE, this);
    GenericFileMessage<T> in = new GenericFileMessage<T>(this);
    exchange.setIn(in);
    populateHeaders(in);
}

/**
 * Populates the {@link GenericFileMessage} relevant headers
 *
 * @param message the message to populate with headers
 */
public void populateHeaders(GenericFileMessage<T> message) {
    if (message != null) {
        message.setHeader(Exchange.FILE_NAME_ONLY, getFileNameOnly());
        message.setHeader(Exchange.FILE_NAME, getFileName());
        message.setHeader("CamelFileAbsolute", isAbsolute());
        message.setHeader("CamelFileAbsolutePath", getAbsoluteFilePath());

        if (isAbsolute()) {
            message.setHeader(Exchange.FILE_PATH, getAbsoluteFilePath());
        } else {
            // we must normalize path according to protocol if we build our own 
paths
            String path = normalizePathToProtocol(getEndpointPath() + 
File.separator + getRelativeFilePath());
            message.setHeader(Exchange.FILE_PATH, path);
        }

        message.setHeader("CamelFileRelativePath", getRelativeFilePath());
        message.setHeader(Exchange.FILE_PARENT, getParent());

        if (getFileLength() >= 0) {
            message.setHeader("CamelFileLength", getFileLength());
        }
        if (getLastModified() > 0) {
            message.setHeader(Exchange.FILE_LAST_MODIFIED, new 
Date(getLastModified()));
        }
    }
}
{code}

As you can see a new "in" message is created and not all the headers from the 
original message are copied to it.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to