Apache Camel fails to create Route and produces bizarre Error message

322 Views Asked by At

I have developed a Java-Application using Apache Camel to archive a bunch of previously sorted files based upon the name of the subfolder they have been placed in. It works as expected running in Eclipse but fails to create the Route when I attempt to run the app outside of Eclipse, producing the following Error Message every time:

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

I have no idea where the Duration-Object comes from, what its purpose is or why its value is 1000.

My Route:

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}");

The use of raw java code in the .toD() at the end replaced an expression in Camel's built-in "Simple" language, as i assumed it was causing the problem. However, it did not change the fact that this route works in Eclipse but not outside of it, in fact it produces the same Error message.

I am using Java 8 and Camel 3.14.7. The routes are run using Camel's Main Class.

1

There are 1 best solutions below

0
On BEST ANSWER

You are likely creating an uber/fat-jar, and then make sure to do this accordingly to: https://camel.apache.org/manual/camel-maven-plugin.html#_camelprepare_fatjar