嵌入 Jetty 时检测处理程序何时无法启动
我以与 此处。当 RequestLogHandler
无法打开指定的日志文件时,它会抛出一个异常,不幸的是,该异常被 org.eclipse.jetty.server.Server
捕获并吞噬(但首先记录,至少)。这意味着我没有明显的方法来判断日志处理程序是否已正确启动。
我是否缺少一种方法来检测处理程序何时无法启动?
I'm embedding Jetty in a similar manner as described here. When the RequestLogHandler
can't open the specified logfile, it throws an exception which is unfortunately caught by org.eclipse.jetty.server.Server
and swallowed (but logged first, at least). This means that there's no obvious way for me to tell if the log handler was started correctly.
Is there a way that I'm missing to detect when a handler couldn't start?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这个想法基于 的实现WebAppContext 您可以在其中使用 WebAppContext.getUnavailableException() 判断上下文是否初始化成功。
只需将 Server 和 Context 的默认实现替换为您自己的:
在 beans.xml 中,只需替换
org.mortbay.jetty.Server
(并删除init-method="start") 和 org.mortbay.jetty.servlet.Context
以及您自己的实现。这段代码适用于 Jetty 6(正如您链接到的示例),因为这就是我所拥有的。虽然我没有测试它,但它与我们成功地与 WebAppContext 结合使用几乎相同。为了将其扩展到 RequestLogHandler,您可以对您正在使用的任何处理程序执行相同的操作,或者创建一个装饰器来包装任何处理程序。为此,您可能需要查看 org.mortbay.jetty.handler.HandlerWrapper 。
This idea is based on the implementation of WebAppContext where you can use WebAppContext.getUnavailableException() to determine whether the context was initialized successfully.
Simply replace the default implementation of Server and Context with your own:
In your beans.xml, simply replace
org.mortbay.jetty.Server
(and removeinit-method="start"
) andorg.mortbay.jetty.servlet.Context
with your own implementations.This code is for Jetty 6 though (as is the example you linked to), as that's what I have around. I didn't test it though, but it's pretty much the same as we are successfully using in conjunction with WebAppContext. In order to extend this to RequestLogHandler, you could either do the same for just any handler you are using or create a decorator to wrap any handler. You may want to look at
org.mortbay.jetty.handler.HandlerWrapper
for this purpose.修改jetty代码怎么样?您可以在 RequestLogHandler 的重要位置添加一些简单的 println 语句,这将指示您处理程序是否已启动。
How about modifying the jetty code? You could add some simple println statements in strategic places in the RequestLogHandler which would indicate to you whether or not the handler was started.