处理

时间:2017-03-02 16:04:56

标签: apache-camel

有没有办法移动名为' yyyy-x.zip'的文件?在处理完文件夹之后' yyyy / yyyy-x.zip'由文件组件?我想到了以下几点:

from("file://directory?preMove=working&move=${${file:onlyname}.substring(0,3)}/${file:onlyname}&moveFailed=error")
.doStuff(...);

但我总是得到以下例外。

    org.apache.camel.language.simple.types.SimpleIllegalSyntaxException: Unknown function: ${file:onlyname}.toString().subString(0,3) at location 0 ${${file:onlyname}.toString().subString(0,3)}/${file:onlyname}
    at org.apache.camel.language.simple.ast.SimpleFunctionStart$1.evaluate(SimpleFunctionStart.java:107)
    at org.apache.camel.builder.ExpressionBuilder$75.evaluate(ExpressionBuilder.java:1795)
    at org.apache.camel.support.ExpressionAdapter.evaluate(ExpressionAdapter.java:36)
    at org.apache.camel.component.file.strategy.GenericFileExpressionRenamer.renameFile(GenericFileExpressionRenamer.java:37)
    at org.apache.camel.component.file.strategy.GenericFileRenameProcessStrategy.commit(GenericFileRenameProcessStrategy.java:87)
    at org.apache.camel.component.file.GenericFileOnCompletion.processStrategyCommit(GenericFileOnCompletion.java:127)
    at org.apache.camel.component.file.GenericFileOnCompletion.onCompletion(GenericFileOnCompletion.java:83)
    at org.apache.camel.component.file.GenericFileOnCompletion.onComplete(GenericFileOnCompletion.java:57)
    at org.apache.camel.util.UnitOfWorkHelper.doneSynchronizations(UnitOfWorkHelper.java:104)
    at org.apache.camel.impl.DefaultUnitOfWork.done(DefaultUnitOfWork.java:230)
    at org.apache.camel.util.UnitOfWorkHelper.doneUow(UnitOfWorkHelper.java:65)
    at org.apache.camel.processor.CamelInternalProcessor$UnitOfWorkProcessorAdvice.after(CamelInternalProcessor.java:674)
    at org.apache.camel.processor.CamelInternalProcessor$UnitOfWorkProcessorAdvice.after(CamelInternalProcessor.java:629)
    at org.apache.camel.processor.CamelInternalProcessor$InternalCallback.done(CamelInternalProcessor.java:246)
    at org.apache.camel.processor.Pipeline.process(Pipeline.java:109)
    at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:197)
    at org.apache.camel.component.file.GenericFileConsumer.processExchange(GenericFileConsumer.java:460)
    at org.apache.camel.component.file.GenericFileConsumer.processBatch(GenericFileConsumer.java:227)
    at org.apache.camel.component.file.GenericFileConsumer.poll(GenericFileConsumer.java:191)
    at org.apache.camel.impl.ScheduledPollConsumer.doRun(ScheduledPollConsumer.java:175)
    at org.apache.camel.impl.ScheduledPollConsumer.run(ScheduledPollConsumer.java:102)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: org.apache.camel.language.simple.types.SimpleParserException: Unknown function: ${file:onlyname}.toString().subString(0,3)
    at org.apache.camel.language.simple.ast.SimpleFunctionExpression.createSimpleExpression(SimpleFunctionExpression.java:230)
    at org.apache.camel.language.simple.ast.SimpleFunctionExpression.createExpression(SimpleFunctionExpression.java:45)
    at org.apache.camel.language.simple.ast.SimpleFunctionStart$1.evaluate(SimpleFunctionStart.java:104)
    ... 27 common frames omitted

修改

感谢Claus Ibsen的提示,我设法得到了以下解决方案:

from("file://directory?preMove=working&move=${bean:myBean.myMethod(${file:onlyname})}&moveFailed=error")
.doStuff(...);

使用以下Bean:

 import org.springframework.stereotype.Service;

@Service("myBean")
public class MyBeanImpl() implements MyBean{

        @Override
        public String myMethod(String fileName){
            return ...create the filename...; 
        }
    }

1 个答案:

答案 0 :(得分:2)

你不能直接在uri中使用substring et all的复杂函数。

您可以使用bean来计算名称,并使用move=${bean:myBean.myMethod}然后在注册表中注册一个ID为myBean的bean,然后计算名称。