Standalone Apache Camel JAR is not able to read file content

396 views Asked by At

I have written a small Camel application (https://github.com/bhushantimilsina/camel-simple-app) that reads file from inbox directory, calls a processor to change its case and write output to a file in outbox directory. When I run the main class (using IDE or using run.cmd script), everything works as expected but when I run the application using executable JAR, only message content is null.

To do this test, I copied \inbox\inputFile.txt in \target so that input file is there. Then I run the JAR using 'java -jar camel-simple-app-1.0-jar-with-dependencies.jar' from target directory.

Output log when running as executable JAR:

2021-03-04 20:04:46.581| INFO | AbstractCamelContext.java 2980 | Routes startup summary (total:4 started:4)
2021-03-04 20:04:46.581| INFO | AbstractCamelContext.java 2985 |        Started inputFileRoute (file://inbox)
2021-03-04 20:04:46.581| INFO | AbstractCamelContext.java 2985 |        Started multicastRoute (direct://inputChannel)
2021-03-04 20:04:46.581| INFO | AbstractCamelContext.java 2985 |        Started upperCaseTransformRoute (direct://upperCaseTransformInputChannel)
2021-03-04 20:04:46.581| INFO | AbstractCamelContext.java 2985 |        Started lowerCaseTransformRoute (direct://lowerCaseTransformInputChannel)
2021-03-04 20:04:46.581| INFO | AbstractCamelContext.java 2997 | Apache Camel 3.8.0 (camelContext) started in 234ms (build:31ms init:172ms start:31ms)
2021-03-04 20:04:46.612| INFO | AbstractCamelContext.java 2980 | Routes startup summary (total:0 started:0)
2021-03-04 20:04:46.612| INFO | AbstractCamelContext.java 2997 | Apache Camel 3.8.0 (camel-1) started in 15ms (build:0ms init:15ms start:0ms)
2021-03-04 20:04:47.581| INFO | CamelLogger.java 166 | *** Input message read from file: C:\SpringPractice\camel-simple-app\target\inbox\inputFile.txt**
2021-03-04 20:04:47.581| INFO | CamelLogger.java 166 | *** Message:

2021-03-04 20:04:47.581| INFO | CamelLogger.java 166 | *** Multicasting the file content to different processors ...
2021-03-04 20:04:47.628| INFO | CamelLogger.java 166 | *** Transforming the message to upper case
2021-03-04 20:04:47.628| INFO | CamelLogger.java 166 | *** Transforming the message to lower case
2021-03-04 20:04:47.628| ERROR | CamelLogger.java 205 | Failed delivery for (MessageId: F89B7EA52A14215-0000000000000001 on ExchangeId: F89B7EA52A14215-0000000000000001). Exhausted after delivery attempt: 1 caught: java.lang.NullPointerException

Here in the log the Message: is empty.

When running from IDE or using run.cmd script I can see the Message: print message in the file.

2021-03-04 20:12:44.320| INFO | AbstractCamelContext.java 2980 | Routes startup summary (total:4 started:4)
2021-03-04 20:12:44.336| INFO | AbstractCamelContext.java 2985 |        Started inputFileRoute (file://inbox)
2021-03-04 20:12:44.336| INFO | AbstractCamelContext.java 2985 |        Started multicastRoute (direct://inputChannel)
2021-03-04 20:12:44.336| INFO | AbstractCamelContext.java 2985 |        Started upperCaseTransformRoute (direct://upperCaseTransformInputChannel)
2021-03-04 20:12:44.336| INFO | AbstractCamelContext.java 2985 |        Started lowerCaseTransformRoute (direct://lowerCaseTransformInputChannel)
2021-03-04 20:12:44.336| INFO | AbstractCamelContext.java 2997 | Apache Camel 3.8.0 (camelContext) started in 422ms (build:78ms init:312ms start:32ms)
2021-03-04 20:12:44.383| INFO | AbstractCamelContext.java 2980 | Routes startup summary (total:0 started:0)
2021-03-04 20:12:44.383| INFO | AbstractCamelContext.java 2997 | Apache Camel 3.8.0 (camel-1) started in 16ms (build:0ms init:16ms start:0ms)
2021-03-04 20:12:45.351| INFO | CamelLogger.java 166 | *** Input message read from file: C:\SpringPractice\camel-simple-app\inbox\inputFile.txt
2021-03-04 20:12:45.351| INFO | CamelLogger.java 166 | *** Message: SoMe meESSage GOes HERe

2021-03-04 20:12:45.351| INFO | CamelLogger.java 166 | *** Multicasting the file content to different processors ...
2021-03-04 20:12:45.398| INFO | CamelLogger.java 166 | *** Transforming the message to lower case
2021-03-04 20:12:45.398| INFO | CamelLogger.java 166 | *** Transforming the message to upper case
2021-03-04 20:12:46.383| INFO | AbstractCamelContext.java 3174 | Apache Camel 3.8.0 (camel-1) shutting down (timeout:45s)
2021-03-04 20:12:46.383| INFO | AbstractCamelContext.java 3368 | Routes shutdown summary (total:0 stopped:0)
2021-03-04 20:12:46.383| INFO | AbstractCamelContext.java 3313 | Apache Camel 3.8.0 (camel-1) shutdown in 0ms (uptime:2s) 
0

There are 0 answers