使用ShutdownHandler关闭码头 [英] Shutting down jetty using ShutdownHandler

查看:132
本文介绍了使用ShutdownHandler关闭码头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 http://www.eclipse.org/jetty /documentation/current/shutdown-handler.html 作为尝试关闭我的jetty服务器的指南,但我得到 java.net.SocketException:来自服务器的文件意外结束 connection.getResponseCode(); 被调用时,我不知道为什么。我正在使用xml配置的服务器,因此将ShutdownHandler添加到Handler链的方式略有不同,但应该没问题。我知道ShutdownHandler已正确连接到处理程序链,因为我使用dumpAfterStartup检查它是否已启动。

I am using http://www.eclipse.org/jetty/documentation/current/shutdown-handler.html as a guide to try to shut down my jetty server, but I'm getting java.net.SocketException: Unexpected end of file from server when connection.getResponseCode(); is called and I don't know why. I'm using an xml configured server, so the way that the ShutdownHandler is added to the Handler chain is a little different, but it should be fine. I know that the ShutdownHandler is properly wired up to the handler chain because I used dumpAfterStartup to check if it was started.

我最不确定的是该行: URL url = new URL(http:// localhost:+ port +/ shutdown?token =+ shutdownCookie); 。我不知道我应该把什么放在shutdownCookie字段中; ShutdownHandler中指定的密码,或STOP键,或者是什么。我已经尝试了密码和STOP键,没有运气。我正在使用POST作为我的请求方法,但我也尝试了PUT,它也不起作用。

The thing that I am most unsure of is the line: URL url = new URL("http://localhost:" + port + "/shutdown?token=" + shutdownCookie);. I don't know what I'm supposed to put in the shutdownCookie field; the password specified in the ShutdownHandler, or the STOP key, or what. I've tried both the password and the STOP key with no luck. I'm using POST as my request method, but I tried PUT as well and it does not work either.

请根据需要提供更多信息。

Please ask for more information as required.

推荐答案

不幸的是,ShutdownHandler方法对我来说不起作用,但我查看了源代码,发现了这个代码片段。

Unfortunately, the ShutdownHandler method did not work for me, but I looked into the source code and found this snippet which did.

Socket s = new Socket(InetAddress.getByName("localhost"), STOP_PORT);
try {
    OutputStream out = s.getOutputStream();
    out.write((STOP_KEY + "\r\nstop\r\n").getBytes());
    out.flush();
} finally {
    s.close();
}

这篇关于使用ShutdownHandler关闭码头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆