Anirban
Anirban

Reputation: 949

Print exception stacktrace in Apache Camel

I am developing a program using Spring Boot and Apache Camel that reads a file from a file server using FTP and writes it to another file server using FTP. I am deploying the Spring Boot application in JBoss EAP server. when I used Apache commons-net library to connect to the FTP server, it failed with an exception, it was unable to connect to the FTP server. I printed the stacktrace. The exception is as below:

    <<Some FTP logs before connecting>>
    500 - I won't open a connection to IP.
    java.lang.NullPointerException
    ...
    ...

But when I am doing the same thing using Apache Camel, It is not printing any exception message or stacktrace or the FTP logs. Below is my program:

public void configure() throws Exception {
        errorHandler(defaultErrorHandler()
                .maximumRedeliveries(3)
                .redeliveryDelay(1000)
                .retryAttemptedLogLevel(LoggingLevel.WARN));

        from("direct:transferFile")
            .log("Transferring file")
            .process(requestProcessor)
            .pollEnrich()
                .simple("${exchangeProperty.inputEndpoint}").timeout(0).aggregationStrategy(requestAggregator)
            .choice()
                .when(body().isNotNull())
                    .toD("${exchangeProperty.outputEndpoint}", true)
                    .log("File transferred")
                .otherwise()
                    .log("Empty body, exiting");
    }

Can anyone please suggest me how will I print the stack trace and FTP logs in Apache Camel?

Upvotes: 0

Views: 2099

Answers (1)

Hassam Abdelillah
Hassam Abdelillah

Reputation: 2304

Why not use onException clause with your specific options :

onException(NullPointerException.class)
    .maximumRedeliveries(3)
    .redeliveryDelay(1000)
    .retryAttemptedLogLevel(LoggingLevel.WARN);

For logging use log() with more parameters to display those messages.

.log(LoggingLevel.WARN,"Transferring file ${body}")

Maybe your logs doesn't display because of your log level.

Upvotes: 1

Related Questions