我已经开发了一个Java应用程序,使用Apache Camel来归档一堆先前根据子文件夹名称排序的文件。它在Eclipse中按预期运行,但当我尝试在Eclipse外部运行应用程序时,无法创建Route,每次都会产生以下错误消息:
2023-08-07 13:20:03,527 [main] ERROR MyClass - Exception occured: org.apache.camel.FailedToCreateRouteException: Failed to create route route1 at: >>> Aggregate[LotName -> [SetHeader[CamelFileName, simple{${in.header.LotName}.zip}], Log[Finished Zipping: ${file:name}], DynamicTo[file:${in.header.CreatedPath}?fileName=${file:name.noext}-2023-08-07T13-20-03-328.${file:ext}&fileExist=Move&moveExisting=${file:name.noext}-1.${file:ext}]]] <<< in route: Route(route1)[From[EndpointA... because of Error parsing [1000] as a java.time.Duration.
org.apache.camel.FailedToCreateRouteException: Failed to create route route1 at: >>> Aggregate[LotName -> [SetHeader[CamelFileName, simple{${in.header.LotName}.zip}], Log[Finished Zipping: ${file:name}], DynamicTo[file:${in.header.CreatedPath}?fileName=${file:name.noext}-2023-08-07T13-20-03-328.${file:ext}&fileExist=Move&moveExisting=${file:name.noext}-1.${file:ext}]]] <<< in route: Route(route1)[From[EndpointA because of Error parsing [1000] as a java.time.Duration.
at org.apache.camel.reifier.RouteReifier.doCreateRoute(RouteReifier.java:241)
at org.apache.camel.reifier.RouteReifier.createRoute(RouteReifier.java:75)
at org.apache.camel.impl.DefaultModelReifierFactory.createRoute(DefaultModelReifierFactory.java:49)
at org.apache.camel.impl.DefaultCamelContext.startRouteDefinitions(DefaultCamelContext.java:874)
at org.apache.camel.impl.DefaultCamelContext.startRouteDefinitions(DefaultCamelContext.java:764)
at org.apache.camel.impl.engine.AbstractCamelContext.doInit(AbstractCamelContext.java:2862)
at org.apache.camel.support.service.BaseService.init(BaseService.java:83)
at org.apache.camel.impl.engine.AbstractCamelContext.init(AbstractCamelContext.java:2568)
at org.apache.camel.support.service.BaseService.start(BaseService.java:111)
at org.apache.camel.impl.engine.AbstractCamelContext.start(AbstractCamelContext.java:2587)
at org.apache.camel.impl.DefaultCamelContext.start(DefaultCamelContext.java:253)
at org.apache.camel.main.Main.doStart(Main.java:116)
at org.apache.camel.support.service.BaseService.start(BaseService.java:119)
at org.apache.camel.main.MainSupport.run(MainSupport.java:69)
at MyClass.main(MyClass.java:80)
Caused by: java.lang.IllegalArgumentException: Error parsing [1000] as a java.time.Duration.
at org.apache.camel.support.CamelContextHelper.parse(CamelContextHelper.java:556)
at org.apache.camel.support.CamelContextHelper.parseDuration(CamelContextHelper.java:500)
at org.apache.camel.reifier.AbstractReifier.parseDuration(AbstractReifier.java:78)
at org.apache.camel.reifier.AggregateReifier.createAggregator(AggregateReifier.java:203)
at org.apache.camel.reifier.AggregateReifier.createProcessor(AggregateReifier.java:54)
at org.apache.camel.reifier.ProcessorReifier.makeProcessor(ProcessorReifier.java:838)
at org.apache.camel.reifier.ProcessorReifier.addRoutes(ProcessorReifier.java:579)
at org.apache.camel.reifier.RouteReifier.doCreateRoute(RouteReifier.java:237)
... 14 more
Caused by: org.apache.camel.NoTypeConversionAvailableException: No type converter available to convert from type: java.lang.String to the required type: java.time.Duration with value 1000
at org.apache.camel.impl.converter.CoreTypeConverterRegistry.mandatoryConvertTo(CoreTypeConverterRegistry.java:275)
at org.apache.camel.impl.converter.CoreTypeConverterRegistry.mandatoryConvertTo(CoreTypeConverterRegistry.java:207)
at org.apache.camel.support.CamelContextHelper.parse(CamelContextHelper.java:553)
... 21 more
我不知道持续时间对象来自哪里,它的目的是什么,为什么它的值是1000。
我的路线:
public void configure() throws Exception {
/* Takes files from origin folder, checks for valid file names and deletes files in their source folders */
from(FILECOMPONENT + sourceFolder + "?recursive=true&include=RAW("+ lotFileRegex +")&delete=true")
.log(LoggingLevel.INFO, "Starting to process file: ${file:name}")
// Extract our criteria to aggregate
.process(new SubfolderExtractor())
// Aggregate Files based on Header "LotName"
.log(LoggingLevel.INFO, "Currently aggregating: ${in.header.LotName}")
.aggregate(header("LotName"), new ZipAggregationStrategy())
.completionFromBatchConsumer().eagerCheckCompletion()
.completionOnNewCorrelationGroup() // finish our archive when the subfolder is empty
// Set Header FILE_NAME to LotName.zip
.setHeader(Exchange.FILE_NAME, simple("${in.header.LotName}.zip"))
.log(LoggingLevel.INFO, "Finished Zipping: ${file:name}")
/* Drop Zip-Archives in same location as their origin, add the current date to make it unique */
.toD(FILECOMPONENT + "${in.header.CreatedPath}?fileName=${file:name.noext}-"+LocalDateTime.now().toString().replace(':', '-').replace('.', '-')+".${file:ext}&fileExist=Move&moveExisting=${file:name.noext}-1.${file:ext}");
最后在.toD()中使用原始的java代码替换了Camel内置的“Simple”语言中的表达式,因为我认为这是导致问题的原因。然而,它并没有改变这个路由在Eclipse中工作而不在Eclipse之外工作的事实,事实上它会产生相同的错误消息。
Java 8和Camel 3.14.7这些路由使用Camel的主类运行。
1条答案
按热度按时间cngwdvgl1#
您可能会创建一个uber/fat-jar,然后确保相应地执行此操作:https://camel.apache.org/manual/camel-maven-plugin.html#_camelprepare_fatjar