ShutdownHandler将提供400欧元的嵌入式码头 [英] ShutdownHandler is giving 400 in Embedded Jetty
本文介绍了ShutdownHandler将提供400欧元的嵌入式码头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用了这些版本的库
<java.version>1.8</java.version>
<javax.websockets.version>1.1</javax.websockets.version>
<jetty.version>9.3.8.v20160314</jetty.version>
<jersey.version>2.22.2</jersey.version>
<jgit.version>4.3.0.201604071810-r</jgit.version>
<json.version>20160212</json.version>
<junit.version>4.12</junit.version>
<slf4j.version>1.7.12</slf4j.version>
<maven.shade.version>2.4.1</maven.shade.version>
嵌入式码头就是这样使用的
embedded Jetty is used like that
Server server = new Server(Settings.PORT);
ResourceHandler resourceHandler = new ResourceHandler();
resourceHandler.setDirectoriesListed(true);
resourceHandler.setWelcomeFiles(new String[] { "./html/index.html" });
resourceHandler.setResourceBase("./ressources/webcontent");
ShutdownHandler shutdownHandler = new ShutdownHandler("switchoff", true, true);
HandlerList handlers = new HandlerList();
handlers.setHandlers(new Handler[] { resourceHandler, shutdownHandler, new DefaultHandler() });
server.setHandler(handlers);
这显示了index.html
This shows the index.html
但这失败了400
http://localhost:22279/shutdown?token = 关闭"
知道为什么吗?
推荐答案
基本上是通过复制/粘贴文档中的片段来解决该问题的....不确定这是否是一种不错的方法,因为它具有丢失的挂起的回调"功能抱怨但行得通
solved it by basically copy/pastings the snipped from the documentation...not sure if that is a nice approach as it has a "losed with pending callback" complain but it works
因此在Jersey上下文持有人中
so in a Jersey Context Holder
@GET
@Path("shutdown")
@Produces(MediaType.TEXT_PLAIN)
public String shutdown(){
new Thread(new ShutDown()).start();
return "Down";
}
关闭类看起来像这样
public class ShutDown implements Runnable{
private static final org.slf4j.Logger log = LoggerFactory.getLogger(ShutDown.class);
private static final String SHUTDOWNCOOKIE = "switchoff";
public void run() {
try {
URL url = new URL("http://localhost:8080/shutdown?token=" + SHUTDOWNCOOKIE);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.getResponseCode();
String attempt = "Shutting down " + url + ": " + connection.getResponseMessage();
log.info(attempt);
} catch (Exception e) {
String error = "Error " + e.getMessage();
log.debug(error);
}
}
}
非常感谢任何剪裁评论!
any tailoring comment is greatly appreciated !
这篇关于ShutdownHandler将提供400欧元的嵌入式码头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文