java - 在 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 日志?
解决方案
为什么不将onException子句与您的特定选项一起使用:
onException(NullPointerException.class)
.maximumRedeliveries(3)
.redeliveryDelay(1000)
.retryAttemptedLogLevel(LoggingLevel.WARN);
对于日志记录,使用带有更多参数的 log() 来显示这些消息。
.log(LoggingLevel.WARN,"Transferring file ${body}")
由于您的日志级别,您的日志可能不会显示。
推荐阅读
- swift - 使用 Snapkit 查看动画
- javascript - 延迟的对 JavaScript 对象的重复迭代
- java - 如何在 java 中使用 Hibernate 为 CRUD 操作创建泛型方法
- java - 从 testNG.xml 文件中检索参数值
- r - R:用新数据预测 VAR
- android - 图片在recycleview点击监听器中捕捉焦点
- c# - Xmlserializer 到 C# 对象,存储原始 XML 元素
- laravel - Laravel 雄辩删除
- amazon-web-services - 设置向导菜单时无法连接詹金斯
- python - Tensorflow分配内存:分配38535168超过系统内存的10%