Can't use two connectors (http and https) in Jetty v.9.4.3

别来无恙 提交于 2019-12-12 19:06:49

问题


When I'm adding two connectors to embedded Jetty server I can't use neither HTTP nor HTTPS - browser/curl is simply stuck. The code I use to create embedded Jetty is approximately the following (it is based on this example - http://self-learning-java-tutorial.blogspot.de/2015/10/jetty-configuring-many-connectors.html):

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();

I turned on debug logs inside org.eclipse.jetty and on any request I get the following:

 Selector loop woken up from select, 0/1 selected [] [io.ManagedSelector][jetty-default-3]
 Running action org.eclipse.jetty.io.ManagedSelector$Accept@4278b8a5 [][io.ManagedSelector] [jetty-default-3]
 Queued change org.eclipse.jetty.io.ManagedSelector$CreateEndPoint@535fb063 on org.eclipse.jetty.io.ManagedSelector@3959754c id=3 keys=2 selected=0 [] [io.ManagedSelector] [jetty-default-3]
 EatWhatYouKill@1289003f/org.eclipse.jetty.io.ManagedSelector$SelectorProducer@7ff1b622/PRODUCING/0/1->PRODUCING/0/1 PEC org.eclipse.jetty.io.ManagedSelector$CreateEndPoint@535fb063 [] [strategy.EatWhatYouKill] [jetty-default-3]
 Selector loop waiting on select [] [io.ManagedSelector] [jetty-default-3]

When only one connector is added everything works as expected.

P.S. SO questions "Selector loop waiting on select" when running multiple test cases which use wiremock stubs and Jetty+Jersey infinite loop with curl post query don't give any answer other than it's a jetty bug fixed in 9.3 (I use 9.4.3)


回答1:


Embedded Jetty supports as many connectors on 1 server as you can dream up. There is no technical limitation in Jetty (the only limitations that exist are in the OS and Networking stacks on your environment)

Its important to note that you have to have a sane HttpConfiguration setup. As they can refer to each other's connectors. (this is for "is secure" behavior, security constraints, etc)

While it is possible to have multiple connectors that simple are not aware of each other, this is not the general use case.

When using HTTPS (aka HTTP over TLS/SSL) the choice of Certificates (sizes, types, alogorithms, etc), and Cipher suite selections will impact your ability to connect to that HTTPS connector.

Note that HTTPS is TLS (not SSL), and Jetty can use the ALPN extensions to TLS which allow the client to negotiate the next protocol to actually use (be it HTTP/1.x or HTTP/2 or whatever your configured next protocol list is)

Here's a few examples of multiple connectors in embedded Jetty.

eclipse/jetty.project - embedded/ManyConnectors.java

eclipse/jetty.project - embedded/LikeJettyXml.java

jetty-project/embedded-jetty-cookbook - ConnectorSpecificContexts.java

jetty-project/embedded-jetty-cookbook - ConnectorSpecificWebapps.java

jetty-project/embedded-jetty-cookbook - SecuredRedirectHandlerExample.java

jetty-project/embedded-jetty-cookbook - ServletTransportGuaranteeExample.java



来源:https://stackoverflow.com/questions/45160624/cant-use-two-connectors-http-and-https-in-jetty-v-9-4-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!