首页 > 解决方案 > 在 Apache Camel 中打印异常堆栈跟踪

问题描述

我正在使用 Spring Boot 和 Apache Camel 开发一个程序,该程序使用 FTP 从文件服务器读取文件并使用 FTP 将其写入另一个文件服务器。我正在 JBoss EAP 服务器中部署 Spring Boot 应用程序。当我使用 Apache commons-net 库连接到 FTP 服务器时,它失败并出现异常,无法连接到 FTP 服务器。我打印了堆栈跟踪。例外情况如下:

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

但是当我使用 Apache Camel 做同样的事情时,它不会打印任何异常消息或堆栈跟踪或 FTP 日志。下面是我的程序:

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

谁能建议我如何在 Apache Camel 中打印堆栈跟踪和 FTP 日志?

标签: javaspring-bootapache-camelapache-commons-netjboss-eap-7

解决方案


为什么不将onException子句与您的特定选项一起使用:

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

对于日志记录,使用带有更多参数的 log() 来显示这些消息。

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

由于您的日志级别,您的日志可能不会显示。


推荐阅读