當我向嵌入式Jetty服務器添加兩個連接器時,我既不能使用HTTP也不能使用HTTPS - 瀏覽器/ curl被卡住了。該代碼我用它來創建嵌入式碼頭約以下(它是基於這個例子 - http://self-learning-java-tutorial.blogspot.de/2015/10/jetty-configuring-many-connectors.html):在Jetty v.9.4.3中不能使用兩個連接器(http和https)
HttpConfiguration httpConfiguration = new HttpConfiguration();
httpConfiguration.setRequestHeaderSize(requestHeaderSize);
ServerConnector httpConnector= new ServerConnector(server, 1, -1, new
HttpConnectionFactory(httpConfiguration));
httpConnector.setPort(getPort());
httpConnector.setReuseAddress(true);
httpConnector.setIdleTimeout(maxTimeout);
server.addConnector(httpConnector);
HttpConfiguration httpsConfiguration = new HttpConfiguration();
httpsConfiguration.setSecureScheme("https");
httpsConfiguration.setSecurePort(securePort);
httpsConfiguration.addCustomizer(new SecureRequestCustomizer());
ServerConnector sslConnector = new ServerConnector(server,
new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()),
new HttpConnectionFactory(httpsConfiguration));
sslConnector.setPort(securePort);
sslConnector.setIdleTimeout(maxTimeout);
sslConnector.setReuseAddress(true);
server.addConnector(sslConnector);
ServletContextHandler servContext = new
ServletContextHandler(ServletContextHandler.NO_SESSIONS);
servContext.setContextPath("/");
server.setHandler(servContext);
server.start();
我打開調試日誌裏面org.eclipse.jetty和任何要求,我得到以下幾點:
Selector loop woken up from select, 0/1 selected [] [io.ManagedSelector][jetty-default-3]
Running action [email protected] [][io.ManagedSelector] [jetty-default-3]
Queued change [email protected] on [email protected] id=3 keys=2 selected=0 [] [io.ManagedSelector] [jetty-default-3]
[email protected]/[email protected]/PRODUCING/0/1->PRODUCING/0/1 PEC [email protected] [] [strategy.EatWhatYouKill] [jetty-default-3]
Selector loop waiting on select [] [io.ManagedSelector] [jetty-default-3]
當只添加一個連接器時,所有功能都按預期工作。
P.S. SO問題"Selector loop waiting on select" when running multiple test cases which use wiremock stubs和Jetty+Jersey infinite loop with curl post query除了它是在9.3(我使用9.4.3)中修復的碼頭bug之外沒有給出任何答案
你在做什麼,你共享的鏈接在做什麼是不同的。該鏈接正確使用2個嵌套的HttpConfiguration對象,而不是。 –
我更改了代碼並使用了嵌套對象,但結果相同 –
事實上,我最終啓動了兩個Jetty服務器 - 一個使用HTTP,一個使用HTTPS。 HTTP工作正常,而後者沒有工作進入無限循環的ManagedSelector,我相信。 –