【问题标题】:Print exception stacktrace in Apache Camel在 Apache Camel 中打印异常堆栈跟踪
【发布时间】:2020-02-17 13:18:10
【问题描述】:

我正在使用 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 日志?

【问题讨论】:

    标签: java spring-boot apache-camel apache-commons-net jboss-eap-7


    【解决方案1】:

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

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

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

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

    可能由于您的日志级别,您的日志没有显示。

    【讨论】:

    • 我进行了编辑,它将是 NullPointerException 而不是 IOException
    • 对不起是NullPointerException,errorHandler()和onException()不会做同样的事情吗?
    • 问题是 Camel 没有打印 FTP 日志,我需要打印这些日志,那么有什么方法可以打印这些日志吗?我修改了我的问题
    • 这只会在 WARN 级别记录“传输文件”消息,而不是其他任何内容。我想要的是在尝试连接到 FTP 服务器时打印 FTP 日志,例如使用哪个用户名、密码等。
    猜你喜欢
    • 1970-01-01
    • 2012-09-04
    • 2011-01-18
    • 2014-08-06
    • 1970-01-01
    • 2010-09-18
    • 2011-05-15
    • 1970-01-01
    • 2011-01-05
    相关资源
    最近更新 更多