对不起的头衔很抱歉,我不太确定这里发生了什么。我正在尝试使用以前使用http的Jetty服务器现在可以通过https工作。我跟着一些文章,过去几天一直在玩它,但我不知道我做错了什么。
这是我设置和启动服务器的代码:
toDataURL()
运行正常,线程在server.join()成功连接。我得到以下输出:
// Create jetty server
this.server = new Server();
HttpConfiguration http_config = new HttpConfiguration();
http_config.setSecureScheme("https");
http_config.setSecurePort(3972);
// Configure Connector for http
ServerConnector http = new ServerConnector(server, new HttpConnectionFactory(http_config));
http.setPort(3971);
http.setIdleTimeout(300000);
// HTTPS Configuration
HttpConfiguration https_config = new HttpConfiguration(http_config);
https_config.addCustomizer(new SecureRequestCustomizer());
SslContextFactory sslContextFactory = new SslContextFactory();
sslContextFactory.setKeyStorePath("data/derkle.jks");
sslContextFactory.setKeyStorePassword("XXXXXXXXXX");
ServerConnector sslConnector = new ServerConnector(server, new SslConnectionFactory(sslContextFactory, "http/1.1"), new HttpConnectionFactory(https_config));
sslConnector.setPort(portSecureNo);
server.setConnectors(new Connector[] { http, sslConnector });
this.server.setHandler(vaultServer);
this.server.start();
this.server.join();
所有看起来都不错,但是当我尝试向它发送请求时,我似乎没有将任何内容传递给我的AbstractHandler实现。哪个具有这样的句柄功能:
2016-01-22 10:52:30.587:INFO::main: Logging initialized @269ms
2016-01-22 10:52:42.124:INFO:oejs.Server:main: jetty-9.2.14.v20151106
2016-01-22 10:52:42.227:INFO:oejs.ServerConnector:main: Started ServerConnector@5674fb70{HTTP/1.1}{0.0.0.0:3971}
2016-01-22 10:52:43.044:INFO:oejs.ServerConnector:main: Started ServerConnector@d9f8120{SSL-http/1.1}{0.0.0.0:3972}
2016-01-22 10:52:43.045:INFO:oejs.Server:main: Started @12729ms
我正在从'高级REST客户端'发送请求到服务器,这是一个chrome扩展。我也尝试过使用Curl,但我似乎无法让SSL使用它。
我试过调用以下地址:
@Override
public void handle(
String target,
Request baseRequest,
HttpServletRequest request,
HttpServletResponse response) throws IOException, ServletException {
Validate.isTrue(this.endPointManager != null, "This has not been initialised.");
target = target.replace('\\', '/');
if (target.startsWith("/"))
target = target.substring(1);
if (target.endsWith("/"))
target = target.substring(0, target.length() - 1);
String[] targets = stelar.extx.StringUtil.stringSplit(target, '/');
if ((targets.length == 1) && (targets[0].trim().equalsIgnoreCase(STATUS_URI))) {
response.setStatus(HttpServletResponse.SC_OK);
baseRequest.setHandled(true);
return;
}
else {
// Display help is the help uri is passed, or not uri is passed
if ((target.isEmpty()) || (targets[0].equalsIgnoreCase(IURLHandler.HELP_URI))) {
displayHelp(this.rootHandler, baseRequest, response);
return;
}
}
parseURI(targets, 0, baseRequest, request, response, this.rootHandler);
}
编辑:
所以我决定恢复使用http作为健全性检查,我注意到它也停止了工作。我之后唯一改变的是我正在使用的码头版本。最初我使用了一个名为jetty-all的库,但它似乎不包含对SSL的支持,所以我切换到了jetty-distribuition-9.2.14.v20151106,它被分成多个jar文件。我想知道我是否需要包含一些额外的库(虽然我没有得到任何编译问题,所以看起来似乎并非如此)。