0

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) 
Olaf Kock
  • 46,930
  • 8
  • 59
  • 90
  • the inbox will have to be on a path relative to the jar. Check where the jar exists and your inbox should be created automatically there. – Sneharghya Pathak Mar 05 '21 at 09:25
  • The inbox directory is where the inputFile.txt is located which contains the message I want to process. In these two cases the only difference is that , when I run it from IDE, the inbox directory is inside project directory and when running it as JAR, i copied the inbox directory to \target directory. If the filepath was not resolved it would not have even resolved the file and the flow will stop right there. – Bhushan Timilsina Mar 05 '21 at 09:40
  • After closely investigating DEBUG logs from Camel, it turns out that when Camel loads TypeConverters there is some difference between executable JAR and running directly main() method from IDE. The issue was resolved using Maven Shade plugin to create the executable JAR (https://camel.apache.org/manual/latest/faq/how-to-create-executable-jar-camel-main.html). – Bhushan Timilsina Mar 05 '21 at 11:05

0 Answers0